forked from pool/python-polib
- Fixed issue #53 (bad magic number written on big endian platforms) endian_magic.patch OBS-URL: https://build.opensuse.org/request/show/198719 OBS-URL: https://build.opensuse.org/package/show/devel:languages:python/python-polib?expand=0&rev=20
56 lines
2.0 KiB
Diff
56 lines
2.0 KiB
Diff
Index: polib-1.0.3/polib.py
|
|
===================================================================
|
|
--- polib-1.0.3.orig/polib.py
|
|
+++ polib-1.0.3/polib.py
|
|
@@ -536,16 +536,11 @@ class _BaseFile(list):
|
|
koffsets += [l1, o1 + keystart]
|
|
voffsets += [l2, o2 + valuestart]
|
|
offsets = koffsets + voffsets
|
|
- # check endianness for magic number
|
|
- if struct.pack('@h', 1) == struct.pack('<h', 1):
|
|
- magic_number = MOFile.LITTLE_ENDIAN
|
|
- else:
|
|
- magic_number = MOFile.BIG_ENDIAN
|
|
|
|
output = struct.pack(
|
|
"Iiiiiii",
|
|
# Magic number
|
|
- magic_number,
|
|
+ MOFile.MAGIC,
|
|
# Version
|
|
0,
|
|
# number of entries
|
|
@@ -688,8 +683,8 @@ class MOFile(_BaseFile):
|
|
This class inherits the :class:`~polib._BaseFile` class and, by
|
|
extension, the python ``list`` type.
|
|
"""
|
|
- BIG_ENDIAN = 0xde120495
|
|
- LITTLE_ENDIAN = 0x950412de
|
|
+ MAGIC = 0x950412de
|
|
+ MAGIC_SWAPPED = 0xde120495
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
"""
|
|
@@ -1432,7 +1427,8 @@ class _POFileParser(object):
|
|
if self.current_state in ['MC', 'MS', 'MX']:
|
|
self.instance.append(self.current_entry)
|
|
self.current_entry = POEntry()
|
|
- self.current_entry.flags += self.current_token[3:].split(', ')
|
|
+ self.current_entry.flags += [c.strip() for c in
|
|
+ self.current_token[3:].split(',')]
|
|
return True
|
|
|
|
def handle_pp(self):
|
|
@@ -1564,9 +1560,9 @@ class _MOFileParser(object):
|
|
"""
|
|
# parse magic number
|
|
magic_number = self._readbinary('<I', 4)
|
|
- if magic_number == MOFile.LITTLE_ENDIAN:
|
|
+ if magic_number == MOFile.MAGIC:
|
|
ii = '<II'
|
|
- elif magic_number == MOFile.BIG_ENDIAN:
|
|
+ elif magic_number == MOFile.MAGIC_SWAPPED:
|
|
ii = '>II'
|
|
else:
|
|
raise IOError('Invalid mo file, magic number is incorrect !')
|