Skip to content

Commit d113e40

Browse files
committed
Some more unicode/py3k compat
1 parent 135fb4b commit d113e40

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

django_babel/extract.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from django.template import Lexer, TOKEN_TEXT, TOKEN_VAR, TOKEN_BLOCK
33
from django.utils.translation.trans_real import (
44
inline_re, block_re, endblock_re, plural_re, constant_re)
5+
from django.utils.encoding import smart_unicode
56

67

78
def extract_django(fileobj, keywords, comment_tags, options):
@@ -34,10 +35,18 @@ def extract_django(fileobj, keywords, comment_tags, options):
3435
pluralmatch = plural_re.match(t.contents)
3536
if endbmatch:
3637
if inplural:
37-
yield lineno, 'ngettext', (unicode(''.join(singular)),
38-
unicode(''.join(plural))), []
38+
yield (
39+
lineno,
40+
'ngettext',
41+
(smart_unicode(u''.join(singular)),
42+
smart_unicode(u''.join(plural))),
43+
[]
3944
else:
40-
yield lineno, None, unicode(''.join(singular)), []
45+
yield (
46+
lineno,
47+
None,
48+
smart_unicode(u''.join(singular)),
49+
[])
4150
intrans = False
4251
inplural = False
4352
singular = []
@@ -68,22 +77,22 @@ def extract_django(fileobj, keywords, comment_tags, options):
6877
g = g.strip('"')
6978
elif g[0] == "'":
7079
g = g.strip("'")
71-
yield lineno, None, unicode(g), []
80+
yield lineno, None, smart_unicode(g), []
7281
elif bmatch:
7382
for fmatch in constant_re.findall(t.contents):
74-
yield lineno, None, unicode(fmatch), []
83+
yield lineno, None, smart_unicode(fmatch), []
7584
intrans = True
7685
inplural = False
7786
singular = []
7887
plural = []
7988
elif cmatches:
8089
for cmatch in cmatches:
81-
yield lineno, None, unicode(cmatch), []
90+
yield lineno, None, smart_unicode(cmatch), []
8291
elif t.token_type == TOKEN_VAR:
8392
parts = t.contents.split('|')
8493
cmatch = constant_re.match(parts[0])
8594
if cmatch:
86-
yield lineno, None, unicode(cmatch.group(1)), []
95+
yield lineno, None, smart_unicode(cmatch.group(1)), []
8796
for p in parts[1:]:
8897
if p.find(':_(') >= 0:
8998
p1 = p.split(':', 1)[1]
@@ -95,4 +104,4 @@ def extract_django(fileobj, keywords, comment_tags, options):
95104
p1 = p1.strip("'")
96105
elif p1[0] == '"':
97106
p1 = p1.strip('"')
98-
yield lineno, None, unicode(p1), []
107+
yield lineno, None, smart_unicode(p1), []

django_babel/templatetags/babel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
except ImportError:
99
timezone = None
1010

11-
from ..middleware import get_current_locale
11+
from django_babel.middleware import get_current_locale
1212

1313
babel = __import__('babel', {}, {}, ['core', 'support'])
1414
Format = babel.support.Format

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
from setuptools.command.test import test as TestCommand
66

77

8-
with open('README.md') as fobj:
8+
with open('README.md', 'rb') as fobj:
99
readme = fobj.read()
1010

1111

12-
with open('CHANGES.md') as fobj:
12+
with open('CHANGES.md', 'rb') as fobj:
1313
history = fobj.read()
1414

1515

0 commit comments

Comments
 (0)