Some more unicode/py3k compat

This commit is contained in:
Christopher Grebs
2014-02-22 14:52:15 +01:00
parent 135fb4b751
commit d113e40aa6
3 changed files with 20 additions and 11 deletions

View File

@@ -2,6 +2,7 @@
from django.template import Lexer, TOKEN_TEXT, TOKEN_VAR, TOKEN_BLOCK
from django.utils.translation.trans_real import (
inline_re, block_re, endblock_re, plural_re, constant_re)
from django.utils.encoding import smart_unicode
def extract_django(fileobj, keywords, comment_tags, options):
@@ -34,10 +35,18 @@ def extract_django(fileobj, keywords, comment_tags, options):
pluralmatch = plural_re.match(t.contents)
if endbmatch:
if inplural:
yield lineno, 'ngettext', (unicode(''.join(singular)),
unicode(''.join(plural))), []
yield (
lineno,
'ngettext',
(smart_unicode(u''.join(singular)),
smart_unicode(u''.join(plural))),
[]
else:
yield lineno, None, unicode(''.join(singular)), []
yield (
lineno,
None,
smart_unicode(u''.join(singular)),
[])
intrans = False
inplural = False
singular = []
@@ -68,22 +77,22 @@ def extract_django(fileobj, keywords, comment_tags, options):
g = g.strip('"')
elif g[0] == "'":
g = g.strip("'")
yield lineno, None, unicode(g), []
yield lineno, None, smart_unicode(g), []
elif bmatch:
for fmatch in constant_re.findall(t.contents):
yield lineno, None, unicode(fmatch), []
yield lineno, None, smart_unicode(fmatch), []
intrans = True
inplural = False
singular = []
plural = []
elif cmatches:
for cmatch in cmatches:
yield lineno, None, unicode(cmatch), []
yield lineno, None, smart_unicode(cmatch), []
elif t.token_type == TOKEN_VAR:
parts = t.contents.split('|')
cmatch = constant_re.match(parts[0])
if cmatch:
yield lineno, None, unicode(cmatch.group(1)), []
yield lineno, None, smart_unicode(cmatch.group(1)), []
for p in parts[1:]:
if p.find(':_(') >= 0:
p1 = p.split(':', 1)[1]
@@ -95,4 +104,4 @@ def extract_django(fileobj, keywords, comment_tags, options):
p1 = p1.strip("'")
elif p1[0] == '"':
p1 = p1.strip('"')
yield lineno, None, unicode(p1), []
yield lineno, None, smart_unicode(p1), []

View File

@@ -8,7 +8,7 @@ try:
except ImportError:
timezone = None
from ..middleware import get_current_locale
from django_babel.middleware import get_current_locale
babel = __import__('babel', {}, {}, ['core', 'support'])
Format = babel.support.Format

View File

@@ -5,11 +5,11 @@ from setuptools import setup, find_packages
from setuptools.command.test import test as TestCommand
with open('README.md') as fobj:
with open('README.md', 'rb') as fobj:
readme = fobj.read()
with open('CHANGES.md') as fobj:
with open('CHANGES.md', 'rb') as fobj:
history = fobj.read()