Skip to content

Commit

Permalink
NullTranslations.__init__(): Back out of setting the default charset
Browse files Browse the repository at this point in the history
to iso-8859-1.

GNUTranslations._parse(): Back out the addition of a test for
Project-ID-Version in the metadata.  This was deliberately removed in
response to SF patch #700839.

Also, re-organize the code in _parse() so we parse the metadata header
containing the charset parameter before we try to decode any strings
using charset.
  • Loading branch information
warsaw committed Apr 11, 2003
1 parent 3bc093b commit 6008cbd
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions Lib/gettext.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def _expand_lang(locale):
class NullTranslations:
def __init__(self, fp=None):
self._info = {}
self._charset = 'iso-8859-1'
self._charset = None
self._fallback = None
if fp is not None:
self._parse(fp)
Expand Down Expand Up @@ -264,24 +264,10 @@ def _parse(self, fp):
if mend < buflen and tend < buflen:
msg = buf[moff:mend]
tmsg = buf[toff:tend]
if msg.find('\x00') >= 0:
# Plural forms
msgid1, msgid2 = msg.split('\x00')
tmsg = tmsg.split('\x00')
if self._coerce:
msgid1 = unicode(msgid1, self._charset)
tmsg = [unicode(x, self._charset) for x in tmsg]
for i in range(len(tmsg)):
catalog[(msgid1, i)] = tmsg[i]
else:
if self._coerce:
msg = unicode(msg, self._charset)
tmsg = unicode(tmsg, self._charset)
catalog[msg] = tmsg
else:
raise IOError(0, 'File is corrupt', filename)
# See if we're looking at GNU .mo conventions for metadata
if mlen == 0 and tmsg.lower().startswith('project-id-version:'):
if mlen == 0:
# Catalog description
for item in tmsg.splitlines():
item = item.strip()
Expand All @@ -299,6 +285,20 @@ def _parse(self, fp):
## nplurals = int(nplurals.strip())
plural = v[1].split('plural=')[1]
self.plural = c2py(plural)
if msg.find('\x00') >= 0:
# Plural forms
msgid1, msgid2 = msg.split('\x00')
tmsg = tmsg.split('\x00')
if self._coerce:
msgid1 = unicode(msgid1, self._charset)
tmsg = [unicode(x, self._charset) for x in tmsg]
for i in range(len(tmsg)):
catalog[(msgid1, i)] = tmsg[i]
else:
if self._coerce:
msg = unicode(msg, self._charset)
tmsg = unicode(tmsg, self._charset)
catalog[msg] = tmsg
# advance to next entry in the seek tables
masteridx += 8
transidx += 8
Expand Down

0 comments on commit 6008cbd

Please sign in to comment.