Commit 31e87203 authored by Benjamin Peterson's avatar Benjamin Peterson

kill some function imports

parent a91dd1e4
...@@ -46,7 +46,7 @@ internationalized, to the local language and cultural habits. ...@@ -46,7 +46,7 @@ internationalized, to the local language and cultural habits.
# find this format documented anywhere. # find this format documented anywhere.
import locale, copy, os, re, struct, sys import locale, copy, io, os, re, struct, sys
from errno import ENOENT from errno import ENOENT
...@@ -63,9 +63,8 @@ def c2py(plural): ...@@ -63,9 +63,8 @@ def c2py(plural):
Python lambda function that implements an equivalent expression. Python lambda function that implements an equivalent expression.
""" """
# Security check, allow only the "n" identifier # Security check, allow only the "n" identifier
from io import StringIO
import token, tokenize import token, tokenize
tokens = tokenize.generate_tokens(StringIO(plural).readline) tokens = tokenize.generate_tokens(io.StringIO(plural).readline)
try: try:
danger = [x for x in tokens if x[0] == token.NAME and x[1] != 'n'] danger = [x for x in tokens if x[0] == token.NAME and x[1] != 'n']
except tokenize.TokenError: except tokenize.TokenError:
...@@ -109,36 +108,35 @@ def c2py(plural): ...@@ -109,36 +108,35 @@ def c2py(plural):
def _expand_lang(locale): def _expand_lang(loc):
from locale import normalize loc = locale.normalize(loc)
locale = normalize(locale)
COMPONENT_CODESET = 1 << 0 COMPONENT_CODESET = 1 << 0
COMPONENT_TERRITORY = 1 << 1 COMPONENT_TERRITORY = 1 << 1
COMPONENT_MODIFIER = 1 << 2 COMPONENT_MODIFIER = 1 << 2
# split up the locale into its base components # split up the locale into its base components
mask = 0 mask = 0
pos = locale.find('@') pos = loc.find('@')
if pos >= 0: if pos >= 0:
modifier = locale[pos:] modifier = loc[pos:]
locale = locale[:pos] loc = loc[:pos]
mask |= COMPONENT_MODIFIER mask |= COMPONENT_MODIFIER
else: else:
modifier = '' modifier = ''
pos = locale.find('.') pos = loc.find('.')
if pos >= 0: if pos >= 0:
codeset = locale[pos:] codeset = loc[pos:]
locale = locale[:pos] loc = loc[:pos]
mask |= COMPONENT_CODESET mask |= COMPONENT_CODESET
else: else:
codeset = '' codeset = ''
pos = locale.find('_') pos = loc.find('_')
if pos >= 0: if pos >= 0:
territory = locale[pos:] territory = loc[pos:]
locale = locale[:pos] loc = loc[:pos]
mask |= COMPONENT_TERRITORY mask |= COMPONENT_TERRITORY
else: else:
territory = '' territory = ''
language = locale language = loc
ret = [] ret = []
for i in range(mask+1): for i in range(mask+1):
if not (i & ~mask): # if all components for this combo exist ... if not (i & ~mask): # if all components for this combo exist ...
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment