|
21 | 21 | import re |
22 | 22 | import uuid |
23 | 23 | from sys import maxunicode, version_info |
24 | | -from collections import OrderedDict |
25 | 24 |
|
26 | 25 | from textile.tools import sanitizer, imagesize |
27 | 26 |
|
28 | 27 |
|
| 28 | +# We're going to use the Python 2.7+ OrderedDict data type. Import it if it's |
| 29 | +# available, otherwise, use the included tool. |
| 30 | +try: |
| 31 | + from collections import OrderedDict |
| 32 | +except ImportError: |
| 33 | + from textile.tools import OrderedDict |
| 34 | + |
| 35 | + |
29 | 36 | try: |
30 | 37 | # Python 3 |
31 | 38 | from urllib.parse import urlparse, urlsplit, urlunsplit, quote, unquote |
@@ -473,8 +480,11 @@ def fTable(self, match): |
473 | 480 | colgrp, last_rgrp = '', '' |
474 | 481 | c_row = 1 |
475 | 482 | rows = [] |
476 | | - for row in [x for x in re.split(r'\|\s*?$', match.group(3), flags=re.M) |
477 | | - if x]: |
| 483 | + try: |
| 484 | + split = re.split(r'\|\s*?$', match.group(3), flags=re.M) |
| 485 | + except TypeError: |
| 486 | + split = re.compile(r'\|\s*?$', re.M).split(match.group(3)) |
| 487 | + for row in [x for x in split if x]: |
478 | 488 | row = row.lstrip() |
479 | 489 |
|
480 | 490 | # Caption -- only occurs on row 1, otherwise treat '|=. foo |...' |
@@ -608,7 +618,10 @@ def lists(self, text): |
608 | 618 | return pattern.sub(self.fList, bullet_pattern.sub('*', text)) |
609 | 619 |
|
610 | 620 | def fList(self, match): |
611 | | - text = re.split(r'\n(?=[*#;:])', match.group(), flags=re.M) |
| 621 | + try: |
| 622 | + text = re.split(r'\n(?=[*#;:])', match.group(), flags=re.M) |
| 623 | + except TypeError: |
| 624 | + text = re.compile(r'\n(?=[*#;:])', re.M).split(match.group()) |
612 | 625 | pt = '' |
613 | 626 | result = [] |
614 | 627 | ls = OrderedDict() |
@@ -1445,7 +1458,10 @@ def redcloth_list(self, text): |
1445 | 1458 | def fRCList(self, match): |
1446 | 1459 | """Format a definition list.""" |
1447 | 1460 | out = [] |
1448 | | - text = re.split(r'\n(?=[-])', match.group(), flags=re.M) |
| 1461 | + try: |
| 1462 | + text = re.split(r'\n(?=[-])', match.group(), flags=re.M) |
| 1463 | + except TypeError: |
| 1464 | + text = re.compile(r'\n(?=[-])', re.M).split(match.group()) |
1449 | 1465 | for line in text: |
1450 | 1466 | # parse the attributes and content |
1451 | 1467 | m = re.match(r'^[-]+(%s)[ .](.*)$' % self.lc, line, re.M | re.S) |
|
0 commit comments