82
82
(?P<INVALID>\w+|.) # invalid token
83
83
""" , re .VERBOSE | re .DOTALL )
84
84
85
+
85
86
def _tokenize (plural ):
86
87
for mo in re .finditer (_token_pattern , plural ):
87
88
kind = mo .lastgroup
@@ -93,12 +94,14 @@ def _tokenize(plural):
93
94
yield value
94
95
yield ''
95
96
97
+
96
98
def _error (value ):
97
99
if value :
98
100
return ValueError ('unexpected token in plural form: %s' % value )
99
101
else :
100
102
return ValueError ('unexpected end of plural form' )
101
103
104
+
102
105
_binary_ops = (
103
106
('||' ,),
104
107
('&&' ,),
@@ -110,6 +113,7 @@ def _error(value):
110
113
_binary_ops = {op : i for i , ops in enumerate (_binary_ops , 1 ) for op in ops }
111
114
_c2py_ops = {'||' : 'or' , '&&' : 'and' , '/' : '//' }
112
115
116
+
113
117
def _parse (tokens , priority = - 1 ):
114
118
result = ''
115
119
nexttok = next (tokens )
@@ -159,9 +163,10 @@ def _parse(tokens, priority=-1):
159
163
160
164
return result , nexttok
161
165
166
+
162
167
def _as_int (n ):
163
168
try :
164
- i = round (n )
169
+ _ = round (n )
165
170
except TypeError :
166
171
raise TypeError ('Plural value must be an integer, got %s' %
167
172
(n .__class__ .__name__ ,)) from None
@@ -171,6 +176,7 @@ def _as_int(n):
171
176
DeprecationWarning , 4 )
172
177
return n
173
178
179
+
174
180
def c2py (plural ):
175
181
"""Gets a C expression as used in PO files for plural forms and returns a
176
182
Python function that implements an equivalent expression.
@@ -249,7 +255,6 @@ def _expand_lang(loc):
249
255
return ret
250
256
251
257
252
-
253
258
class NullTranslations :
254
259
def __init__ (self , fp = None ):
255
260
self ._info = {}
@@ -495,10 +500,10 @@ def find(domain, localedir=None, languages=None, all=False):
495
500
return result
496
501
497
502
498
-
499
503
# a mapping between absolute .mo file path and Translation object
500
504
_translations = {}
501
505
506
+
502
507
def translation (domain , localedir = None , languages = None ,
503
508
class_ = None , fallback = False ):
504
509
if class_ is None :
@@ -538,7 +543,6 @@ def install(domain, localedir=None, *, names=None):
538
543
t .install (names )
539
544
540
545
541
-
542
546
# a mapping b/w domains and locale directories
543
547
_localedirs = {}
544
548
# current global domain, `messages' used for compatibility w/ GNU gettext
0 commit comments