diff options
Diffstat (limited to 'modules/language/python/module/gettext.py')
-rw-r--r-- | modules/language/python/module/gettext.py | 32 |
1 files changed, 7 insertions, 25 deletions
diff --git a/modules/language/python/module/gettext.py b/modules/language/python/module/gettext.py index 80a9ebe..0ea54aa 100644 --- a/modules/language/python/module/gettext.py +++ b/modules/language/python/module/gettext.py @@ -335,26 +335,18 @@ class GNUTranslations(NullTranslations): def _parse(self, fp): """Override this method to support alternative .mo formats.""" - pk('_parse') - unpack = pk('unpack',struct.unpack) - pk(1) + unpack = struct.unpack filename = getattr(fp, 'name', '') - pk(2,filename) # Parse the .mo file header, which consists of 5 little endian 32 # bit words. self._catalog = catalog = {} self.plural = lambda n: int(n != 1) # germanic plural by default - pk(3) buf = fp.read() buflen = len(buf) - pk(4,buf) # Are we big endian or little endian? magic = unpack('<I', buf[:4])[0] - pk('magic') - pk('magic',magic,'LE',self.LE_MAGIC,'BE',self.BE_MAGIC) if magic == self.LE_MAGIC: version, msgcount, masteridx, transidx = unpack('<4I', buf[4:20]) - pk(version,msgcount,masteridx,transidx) ii = '<II' elif magic == self.BE_MAGIC: version, msgcount, masteridx, transidx = unpack('>4I', buf[4:20]) @@ -363,7 +355,6 @@ class GNUTranslations(NullTranslations): raise OSError(0, 'Bad magic number', filename) major_version, minor_version = self._get_versions(version) - pk('version',major_version,self.VERSIONS) if major_version not in self.VERSIONS: raise OSError(0, 'Bad version number ' + str(major_version), filename) @@ -379,15 +370,13 @@ class GNUTranslations(NullTranslations): tmsg = buf[toff:tend] else: raise OSError(0, 'File is corrupt', filename) - pk('msg',mlen,tlen,msg,tmsg) + # See if we're looking at GNU .mo conventions for metadata if mlen == 0: # Catalog description lastk = None - for b_item in pk('split',tmsg.split(b'\n')): - pk('item',b_item) + for b_item in tmsg.split(b'\n'): item = b_item.decode().strip() - pk('decode',item) if not item: continue k = v = None @@ -395,20 +384,16 @@ class GNUTranslations(NullTranslations): k, v = item.split(':', 1) k = k.strip().lower() v = v.strip() - pk('pair',k,v) self._info[k] = v lastk = k elif lastk: self._info[lastk] += '\n' + item - pk('lastk',lastk,self._info[lastk]) if k == 'content-type': self._charset = v.split('charset=')[1] - pk('charset',self._charset) elif k == 'plural-forms': v = v.split(';') plural = v[1].split('plural=')[1] self.plural = c2py(plural) - pk('plural',self.plural) # Note: we unconditionally convert both msgids and msgstrs to # Unicode using the character encoding specified in the charset # parameter of the Content-Type header. The gettext documentation @@ -548,19 +533,16 @@ def translation(domain, localedir=None, languages=None, # once. result = None for mofile in mofiles: - pk('mofile',mofile) - key = pk((class_, os.path.abspath(mofile))) - t = pk('tr',_translations.get(key)) + key = (class_, os.path.abspath(mofile)) + t = _translations.get(key) if t is None: with open(mofile, 'rb') as fp: - pk('process') - t = _translations.setdefault(key, pk('cl',class_(fp))) + t = _translations.setdefault(key, class_(fp)) # Copy the translation object to allow setting fallbacks and # output charset. All other instance data is shared with the # cached object. - pk('t1',t) t = copy.copy(t) - pk('t2',t) + if codeset: t.set_output_charset(codeset) if result is None: |