Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions Lib/gettext.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
(?P<INVALID>\w+|.) # invalid token
""", re.VERBOSE|re.DOTALL)


def _tokenize(plural):
for mo in re.finditer(_token_pattern, plural):
kind = mo.lastgroup
Expand All @@ -93,12 +94,14 @@ def _tokenize(plural):
yield value
yield ''


def _error(value):
if value:
return ValueError('unexpected token in plural form: %s' % value)
else:
return ValueError('unexpected end of plural form')


_binary_ops = (
('||',),
('&&',),
Expand All @@ -110,6 +113,7 @@ def _error(value):
_binary_ops = {op: i for i, ops in enumerate(_binary_ops, 1) for op in ops}
_c2py_ops = {'||': 'or', '&&': 'and', '/': '//'}


def _parse(tokens, priority=-1):
result = ''
nexttok = next(tokens)
Expand Down Expand Up @@ -159,9 +163,10 @@ def _parse(tokens, priority=-1):

return result, nexttok


def _as_int(n):
try:
i = round(n)
_ = round(n)
except TypeError:
raise TypeError('Plural value must be an integer, got %s' %
(n.__class__.__name__,)) from None
Expand All @@ -171,6 +176,7 @@ def _as_int(n):
DeprecationWarning, 4)
return n


def c2py(plural):
"""Gets a C expression as used in PO files for plural forms and returns a
Python function that implements an equivalent expression.
Expand Down Expand Up @@ -249,7 +255,6 @@ def _expand_lang(loc):
return ret



class NullTranslations:
def __init__(self, fp=None):
self._info = {}
Expand Down Expand Up @@ -495,10 +500,10 @@ def find(domain, localedir=None, languages=None, all=False):
return result



# a mapping between absolute .mo file path and Translation object
_translations = {}


def translation(domain, localedir=None, languages=None,
class_=None, fallback=False):
if class_ is None:
Expand Down Expand Up @@ -538,7 +543,6 @@ def install(domain, localedir=None, *, names=None):
t.install(names)



# a mapping b/w domains and locale directories
_localedirs = {}
# current global domain, `messages' used for compatibility w/ GNU gettext
Expand Down