Skip to content

Commit 2f848a4

Browse files
committed
I've rethought py2.6; giving it one last try.
1 parent 4cca67d commit 2f848a4

7 files changed

Lines changed: 46 additions & 11 deletions

File tree

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ env:
33
- REQUIREMENTS=true
44
- REQUIREMENTS=false
55
python:
6+
- "2.6"
67
- "2.7"
78
- "3.2"
89
- "3.3"

README.textile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,4 @@ h2. Usage
4343

4444
h3. Notes:
4545

46-
* Active development supports Python 2.7 or later (including Python 3.2+).
46+
* Active development supports Python 2.6 or later (including Python 3.2+).

setup.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def get_version():
2626
'Topic :: Software Development :: Libraries :: Python Modules',
2727
'Programming Language :: Python',
2828
'Programming Language :: Python :: 2',
29+
'Programming Language :: Python :: 2.6',
2930
'Programming Language :: Python :: 2.7',
3031
'Programming Language :: Python :: 3',
3132
'Programming Language :: Python :: 3.2',
@@ -36,6 +37,7 @@ def get_version():
3637
keywords='textile,text,html markup',
3738
install_requires=['six',],
3839
extras_require={
40+
':python_version=="2.6"': ['ordereddict>=1.1'],
3941
'develop': ['regex', 'pytest', 'pytest-cov'],
4042
},
4143
setup_requires=['pytest-runner'],

textile/__init__.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
11
from __future__ import unicode_literals
22

3+
import sys
4+
import warnings
5+
36
from .core import textile, textile_restricted, Textile
47
from .version import VERSION
58

69
__all__ = ['textile', 'textile_restricted']
710

811
__version__ = VERSION
12+
13+
14+
if sys.version_info[:2] == (2, 6):
15+
warnings.warn(
16+
"Python 2.6 is no longer supported by the Python core team, please "
17+
"upgrade your Python. A future version of cryptography will drop "
18+
"support for Python 2.6",
19+
DeprecationWarning
20+
)

textile/core.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@
3131
from textile.objects import Block, Table
3232

3333

34-
from collections import OrderedDict
34+
try:
35+
from collections import OrderedDict
36+
except ImportError:
37+
from ordereddict import OrderedDict
3538

3639
from six.moves import urllib
3740
urlparse, urlsplit, urlunsplit, quote, unquote = (urllib.parse.urlparse,
@@ -871,6 +874,7 @@ def _casesdefault(c, pop, popped, url_chars, counts, pre):
871874
url = self.shelveURL(self.encode_url(urlunsplit(uri_parts)))
872875
attributes = parse_attributes(atts)
873876
if title:
877+
title = title.encode('utf8')
874878
attributes['title'] = title
875879
attributes['href'] = url
876880
if self.rel:

textile/objects/block.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
from collections import OrderedDict
2-
1+
try:
2+
from collections import OrderedDict
3+
except ImportError:
4+
from ordereddict import OrderedDict
35
try:
46
import regex as re
57
except ImportError:

textile/utils.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
urlparse = urllib.parse.urlparse
1111
HTMLParser = html_parser.HTMLParser
1212

13-
from collections import OrderedDict
13+
try:
14+
from collections import OrderedDict
15+
except ImportError:
16+
from ordereddict import OrderedDict
1417

1518
from xml.etree import ElementTree
1619

@@ -47,22 +50,33 @@ def generate_tag(tag, content, attributes=None):
4750
content are strings, the attributes argument is a dictionary. As
4851
a convenience, if the content is ' /', a self-closing tag is generated."""
4952
content = six.text_type(content)
50-
element = ElementTree.Element(tag, attrib=attributes)
5153
enc = 'unicode'
5254
if six.PY2:
5355
enc = 'UTF-8'
56+
attributes = OrderedDict((k, v.decode('utf8')) for k, v in attributes.items())
5457
if not tag:
5558
return content
59+
element = ElementTree.Element(tag, attrib=attributes)
5660
# FIXME: Kind of an ugly hack. There *must* be a cleaner way. I tried
5761
# adding text by assigning it to element_tag.text. That results in
5862
# non-ascii text being html-entity encoded. Not bad, but not entirely
5963
# matching php-textile either.
60-
element_tag = ElementTree.tostringlist(element, encoding=enc,
61-
method='html')
62-
if six.PY2:
64+
try:
65+
element_tag = ElementTree.tostringlist(element, encoding=enc,
66+
method='html')
6367
element_tag = [v.decode('utf8') for v in element_tag]
64-
element_tag.insert(len(element_tag) - 1, content)
65-
element_text = ''.join(element_tag)
68+
element_tag.insert(len(element_tag) - 1, content)
69+
element_text = ''.join(element_tag)
70+
except AttributeError:
71+
# Python 2.6 doesn't have the tostringlist method, so we have to treat
72+
# it differently.
73+
element_tag = ElementTree.tostring(element, encoding=enc)
74+
element_text = re.sub(r"<\?xml version='1.0' encoding='UTF-8'\?>\n",
75+
'', element_tag)
76+
if content != six.text_type(' /'):
77+
element_text = element_text.rstrip(' />')
78+
element_text = six.text_type('{0}>{1}</{2}>').format(six.text_type(
79+
element_text), content, tag)
6680
return element_text
6781

6882
def has_raw_text(text):

0 commit comments

Comments
 (0)