14
0
forked from pool/python-polib

Accepting request 634930 from home:mcepl:work

Update the big endian patch.

OBS-URL: https://build.opensuse.org/request/show/634930
OBS-URL: https://build.opensuse.org/package/show/devel:languages:python/python-polib?expand=0&rev=32
This commit is contained in:
2018-09-11 09:52:02 +00:00
committed by Git OBS Bridge
parent d2746e983b
commit c2e54c2fda

View File

@@ -1,24 +1,6 @@
--- a/polib.py
+++ b/polib.py
@@ -14,12 +14,17 @@ modify entries, comments or metadata, et
import array
import codecs
+import logging
import os
import re
import struct
import sys
import textwrap
+logging.basicConfig(format='%(levelname)s:%(funcName)s:%(message)s',
+ stream=sys.stdout, level=logging.DEBUG)
+log = logging.getLogger('polib')
+
try:
import io
except ImportError:
@@ -592,7 +597,7 @@ class _BaseFile(list):
@@ -592,7 +592,7 @@ class _BaseFile(list):
offsets = koffsets + voffsets
output = struct.pack(
@@ -27,24 +9,21 @@
# Magic number
MOFile.MAGIC,
# Version
@@ -608,9 +613,9 @@ class _BaseFile(list):
@@ -607,10 +607,15 @@ class _BaseFile(list):
0, keystart
)
+ outarr = array.array("i", offsets)
+ # since 0.19.8 msgfmt produces little-endian files by default
+ if sys.byteorder == "big":
+ outarr.byteswap()
+
if PY3 and sys.version_info.minor > 1: # python 3.2 or superior
- output += array.array("i", offsets).tobytes()
+ output += array.array("<i", offsets).tobytes()
+ output += outarr.tobytes()
else:
- output += array.array("i", offsets).tostring()
+ output += array.array("<i", offsets).tostring()
+ output += outarr.tostring()
output += ids
output += strs
return output
@@ -1688,6 +1693,8 @@ class _MOFileParser(object):
"""
# parse magic number
magic_number = self._readbinary('<I', 4)
+ log.debug('magic_number = %s (magic = %s, magic swapped = %s)',
+ magic_number, MOFile.MAGIC, MOFile.MAGIC_SWAPPED)
if magic_number == MOFile.MAGIC:
ii = '<II'
elif magic_number == MOFile.MAGIC_SWAPPED: