mirror of
https://github.com/python/cpython.git
synced 2025-09-22 08:23:36 +00:00
Patch by Tim to shut up the compiler's DeprecationWarnings on the
high-bit-set hex constants.
This commit is contained in:
parent
20f0b36a04
commit
09707e3637
1 changed files with 9 additions and 18 deletions
|
@ -139,14 +139,11 @@ class NullTranslations:
|
||||||
|
|
||||||
class GNUTranslations(NullTranslations):
|
class GNUTranslations(NullTranslations):
|
||||||
# Magic number of .mo files
|
# Magic number of .mo files
|
||||||
LE_MAGIC = 0x950412de
|
LE_MAGIC = 0x950412deL
|
||||||
BE_MAGIC = 0xde120495
|
BE_MAGIC = 0xde120495L
|
||||||
|
|
||||||
def _parse(self, fp):
|
def _parse(self, fp):
|
||||||
"""Override this method to support alternative .mo formats."""
|
"""Override this method to support alternative .mo formats."""
|
||||||
# We need to & all 32 bit unsigned integers with 0xffffffff for
|
|
||||||
# portability to 64 bit machines.
|
|
||||||
MASK = 0xffffffff
|
|
||||||
unpack = struct.unpack
|
unpack = struct.unpack
|
||||||
filename = getattr(fp, 'name', '')
|
filename = getattr(fp, 'name', '')
|
||||||
# Parse the .mo file header, which consists of 5 little endian 32
|
# Parse the .mo file header, which consists of 5 little endian 32
|
||||||
|
@ -155,28 +152,22 @@ class GNUTranslations(NullTranslations):
|
||||||
buf = fp.read()
|
buf = fp.read()
|
||||||
buflen = len(buf)
|
buflen = len(buf)
|
||||||
# Are we big endian or little endian?
|
# Are we big endian or little endian?
|
||||||
magic = unpack('<i', buf[:4])[0] & MASK
|
magic = unpack('<I', buf[:4])[0]
|
||||||
if magic == self.LE_MAGIC:
|
if magic == self.LE_MAGIC:
|
||||||
version, msgcount, masteridx, transidx = unpack('<4i', buf[4:20])
|
version, msgcount, masteridx, transidx = unpack('<4I', buf[4:20])
|
||||||
ii = '<ii'
|
ii = '<II'
|
||||||
elif magic == self.BE_MAGIC:
|
elif magic == self.BE_MAGIC:
|
||||||
version, msgcount, masteridx, transidx = unpack('>4i', buf[4:20])
|
version, msgcount, masteridx, transidx = unpack('>4I', buf[4:20])
|
||||||
ii = '>ii'
|
ii = '>II'
|
||||||
else:
|
else:
|
||||||
raise IOError(0, 'Bad magic number', filename)
|
raise IOError(0, 'Bad magic number', filename)
|
||||||
# more unsigned ints
|
|
||||||
msgcount &= MASK
|
|
||||||
masteridx &= MASK
|
|
||||||
transidx &= MASK
|
|
||||||
# Now put all messages from the .mo file buffer into the catalog
|
# Now put all messages from the .mo file buffer into the catalog
|
||||||
# dictionary.
|
# dictionary.
|
||||||
for i in xrange(0, msgcount):
|
for i in xrange(0, msgcount):
|
||||||
mlen, moff = unpack(ii, buf[masteridx:masteridx+8])
|
mlen, moff = unpack(ii, buf[masteridx:masteridx+8])
|
||||||
moff &= MASK
|
mend = moff + mlen
|
||||||
mend = moff + (mlen & MASK)
|
|
||||||
tlen, toff = unpack(ii, buf[transidx:transidx+8])
|
tlen, toff = unpack(ii, buf[transidx:transidx+8])
|
||||||
toff &= MASK
|
tend = toff + tlen
|
||||||
tend = toff + (tlen & MASK)
|
|
||||||
if mend < buflen and tend < buflen:
|
if mend < buflen and tend < buflen:
|
||||||
tmsg = buf[toff:tend]
|
tmsg = buf[toff:tend]
|
||||||
catalog[buf[moff:mend]] = tmsg
|
catalog[buf[moff:mend]] = tmsg
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue