Merge pull request #853 from BuhtigithuB/pep8-languages-py
Improve PEP8 gluon/languages.py
This commit is contained in:
+12
-5
@@ -75,11 +75,13 @@ regex_plural_tuple = re.compile(
|
|||||||
'^{(?P<w>[^[\]()]+)(?:\[(?P<i>\d+)\])?}$') # %%{word[index]} or %%{word}
|
'^{(?P<w>[^[\]()]+)(?:\[(?P<i>\d+)\])?}$') # %%{word[index]} or %%{word}
|
||||||
regex_plural_file = re.compile('^plural-[a-zA-Z]{2}(-[a-zA-Z]{2})?\.py$')
|
regex_plural_file = re.compile('^plural-[a-zA-Z]{2}(-[a-zA-Z]{2})?\.py$')
|
||||||
|
|
||||||
|
|
||||||
def is_writable():
|
def is_writable():
|
||||||
""" returns True if and only if the filesystem is writable """
|
""" returns True if and only if the filesystem is writable """
|
||||||
from gluon.settings import global_settings
|
from gluon.settings import global_settings
|
||||||
return not global_settings.web2py_runtime_gae
|
return not global_settings.web2py_runtime_gae
|
||||||
|
|
||||||
|
|
||||||
def safe_eval(text):
|
def safe_eval(text):
|
||||||
if text.strip():
|
if text.strip():
|
||||||
try:
|
try:
|
||||||
@@ -314,9 +316,11 @@ def write_plural_dict(filename, contents):
|
|||||||
if fp:
|
if fp:
|
||||||
fp.close()
|
fp.close()
|
||||||
|
|
||||||
def sort_function(x,y):
|
|
||||||
|
def sort_function(x, y):
|
||||||
return cmp(unicode(x, 'utf-8').lower(), unicode(y, 'utf-8').lower())
|
return cmp(unicode(x, 'utf-8').lower(), unicode(y, 'utf-8').lower())
|
||||||
|
|
||||||
|
|
||||||
def write_dict(filename, contents):
|
def write_dict(filename, contents):
|
||||||
if '__corrupted__' in contents:
|
if '__corrupted__' in contents:
|
||||||
return
|
return
|
||||||
@@ -432,11 +436,13 @@ class lazyT(object):
|
|||||||
return lazyT(self)
|
return lazyT(self)
|
||||||
return lazyT(self.m, symbols, self.T, self.f, self.t, self.M)
|
return lazyT(self.m, symbols, self.T, self.f, self.t, self.M)
|
||||||
|
|
||||||
|
|
||||||
def pickle_lazyT(c):
|
def pickle_lazyT(c):
|
||||||
return str, (c.xml(),)
|
return str, (c.xml(),)
|
||||||
|
|
||||||
copy_reg.pickle(lazyT, pickle_lazyT)
|
copy_reg.pickle(lazyT, pickle_lazyT)
|
||||||
|
|
||||||
|
|
||||||
class translator(object):
|
class translator(object):
|
||||||
"""
|
"""
|
||||||
This class is instantiated by gluon.compileapp.build_environment
|
This class is instantiated by gluon.compileapp.build_environment
|
||||||
@@ -461,7 +467,7 @@ class translator(object):
|
|||||||
self.langpath = langpath
|
self.langpath = langpath
|
||||||
self.http_accept_language = http_accept_language
|
self.http_accept_language = http_accept_language
|
||||||
# filled in self.force():
|
# filled in self.force():
|
||||||
#------------------------
|
# ------------------------
|
||||||
# self.cache
|
# self.cache
|
||||||
# self.accepted_language
|
# self.accepted_language
|
||||||
# self.language_file
|
# self.language_file
|
||||||
@@ -472,9 +478,9 @@ class translator(object):
|
|||||||
# self.plural_file
|
# self.plural_file
|
||||||
# self.plural_dict
|
# self.plural_dict
|
||||||
# self.requested_languages
|
# self.requested_languages
|
||||||
#----------------------------------------
|
# ----------------------------------------
|
||||||
# filled in self.set_current_languages():
|
# filled in self.set_current_languages():
|
||||||
#----------------------------------------
|
# ----------------------------------------
|
||||||
# self.default_language_file
|
# self.default_language_file
|
||||||
# self.default_t
|
# self.default_t
|
||||||
# self.current_languages
|
# self.current_languages
|
||||||
@@ -723,7 +729,7 @@ class translator(object):
|
|||||||
try:
|
try:
|
||||||
otherT = self.otherTs[index]
|
otherT = self.otherTs[index]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
otherT = self.otherTs[index] = translator(self.langpath, \
|
otherT = self.otherTs[index] = translator(self.langpath,
|
||||||
self.http_accept_language)
|
self.http_accept_language)
|
||||||
if language:
|
if language:
|
||||||
otherT.force(language)
|
otherT.force(language)
|
||||||
@@ -977,6 +983,7 @@ def findT(path, language=DEFAULT_LANGUAGE):
|
|||||||
else sentences['!langcode!'])
|
else sentences['!langcode!'])
|
||||||
write_dict(lang_file, sentences)
|
write_dict(lang_file, sentences)
|
||||||
|
|
||||||
|
|
||||||
def update_all_languages(application_path):
|
def update_all_languages(application_path):
|
||||||
"""
|
"""
|
||||||
Note:
|
Note:
|
||||||
|
|||||||
Reference in New Issue
Block a user