11# -*- coding: utf-8 -*-
2- from django .template import Lexer , TOKEN_TEXT , TOKEN_VAR , TOKEN_BLOCK
2+ try :
3+ from django .template import Lexer , TOKEN_TEXT , TOKEN_VAR , TOKEN_BLOCK
4+ except ImportError :
5+ # Django 1.8 moved most stuff to .base
6+ from django .template .base import Lexer , TOKEN_TEXT , TOKEN_VAR , TOKEN_BLOCK
7+
38from django .utils .translation .trans_real import (
49 inline_re , block_re , endblock_re , plural_re , constant_re )
5- from django .utils .encoding import smart_text as smart_unicode
10+ from django .utils .encoding import smart_text
611
712
813def extract_django (fileobj , keywords , comment_tags , options ):
@@ -38,14 +43,14 @@ def extract_django(fileobj, keywords, comment_tags, options):
3843 yield (
3944 lineno ,
4045 'ngettext' ,
41- (smart_unicode (u'' .join (singular )),
42- smart_unicode (u'' .join (plural ))),
46+ (smart_text (u'' .join (singular )),
47+ smart_text (u'' .join (plural ))),
4348 [])
4449 else :
4550 yield (
4651 lineno ,
4752 None ,
48- smart_unicode (u'' .join (singular )),
53+ smart_text (u'' .join (singular )),
4954 [])
5055
5156 intrans = False
@@ -78,22 +83,22 @@ def extract_django(fileobj, keywords, comment_tags, options):
7883 g = g .strip ('"' )
7984 elif g [0 ] == "'" :
8085 g = g .strip ("'" )
81- yield lineno , None , smart_unicode (g ), []
86+ yield lineno , None , smart_text (g ), []
8287 elif bmatch :
8388 for fmatch in constant_re .findall (t .contents ):
84- yield lineno , None , smart_unicode (fmatch ), []
89+ yield lineno , None , smart_text (fmatch ), []
8590 intrans = True
8691 inplural = False
8792 singular = []
8893 plural = []
8994 elif cmatches :
9095 for cmatch in cmatches :
91- yield lineno , None , smart_unicode (cmatch ), []
96+ yield lineno , None , smart_text (cmatch ), []
9297 elif t .token_type == TOKEN_VAR :
9398 parts = t .contents .split ('|' )
9499 cmatch = constant_re .match (parts [0 ])
95100 if cmatch :
96- yield lineno , None , smart_unicode (cmatch .group (1 )), []
101+ yield lineno , None , smart_text (cmatch .group (1 )), []
97102 for p in parts [1 :]:
98103 if p .find (':_(' ) >= 0 :
99104 p1 = p .split (':' , 1 )[1 ]
@@ -105,4 +110,4 @@ def extract_django(fileobj, keywords, comment_tags, options):
105110 p1 = p1 .strip ("'" )
106111 elif p1 [0 ] == '"' :
107112 p1 = p1 .strip ('"' )
108- yield lineno , None , smart_unicode (p1 ), []
113+ yield lineno , None , smart_text (p1 ), []
0 commit comments