From f227397ccf0830d7188aab93c22433ba1db5580c Mon Sep 17 00:00:00 2001 From: Hardirc Date: Fri, 6 Mar 2015 22:08:50 -0500 Subject: [PATCH] Improve PEP8 gluon/languages.py --- gluon/languages.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/gluon/languages.py b/gluon/languages.py index 695d553c..14b02c04 100644 --- a/gluon/languages.py +++ b/gluon/languages.py @@ -75,11 +75,13 @@ regex_plural_tuple = re.compile( '^{(?P[^[\]()]+)(?:\[(?P\d+)\])?}$') # %%{word[index]} or %%{word} regex_plural_file = re.compile('^plural-[a-zA-Z]{2}(-[a-zA-Z]{2})?\.py$') + def is_writable(): """ returns True if and only if the filesystem is writable """ from gluon.settings import global_settings return not global_settings.web2py_runtime_gae + def safe_eval(text): if text.strip(): try: @@ -314,9 +316,11 @@ def write_plural_dict(filename, contents): if fp: fp.close() -def sort_function(x,y): + +def sort_function(x, y): return cmp(unicode(x, 'utf-8').lower(), unicode(y, 'utf-8').lower()) + def write_dict(filename, contents): if '__corrupted__' in contents: return @@ -432,11 +436,13 @@ class lazyT(object): return lazyT(self) return lazyT(self.m, symbols, self.T, self.f, self.t, self.M) + def pickle_lazyT(c): return str, (c.xml(),) copy_reg.pickle(lazyT, pickle_lazyT) + class translator(object): """ This class is instantiated by gluon.compileapp.build_environment @@ -461,7 +467,7 @@ class translator(object): self.langpath = langpath self.http_accept_language = http_accept_language # filled in self.force(): - #------------------------ + # ------------------------ # self.cache # self.accepted_language # self.language_file @@ -472,9 +478,9 @@ class translator(object): # self.plural_file # self.plural_dict # self.requested_languages - #---------------------------------------- + # ---------------------------------------- # filled in self.set_current_languages(): - #---------------------------------------- + # ---------------------------------------- # self.default_language_file # self.default_t # self.current_languages @@ -723,7 +729,7 @@ class translator(object): try: otherT = self.otherTs[index] except KeyError: - otherT = self.otherTs[index] = translator(self.langpath, \ + otherT = self.otherTs[index] = translator(self.langpath, self.http_accept_language) if language: otherT.force(language) @@ -977,6 +983,7 @@ def findT(path, language=DEFAULT_LANGUAGE): else sentences['!langcode!']) write_dict(lang_file, sentences) + def update_all_languages(application_path): """ Note: