Accepting request 198719 from home:k0da:ppc

- 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
This commit is contained in:
Sascha Peilicke
2013-09-13 15:10:13 +00:00
committed by Git OBS Bridge
parent 242c67c892
commit 295fccece0
3 changed files with 63 additions and 0 deletions

55
endian_magic.patch Normal file
View File

@@ -0,0 +1,55 @@
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 !')

View File

@@ -1,3 +1,9 @@
-------------------------------------------------------------------
Thu Sep 12 14:51:41 UTC 2013 - dvaleev@suse.com
- Fixed issue #53 (bad magic number written on big endian platforms)
endian_magic.patch
-------------------------------------------------------------------
Mon Feb 11 17:31:17 UTC 2013 - lazy.kent@opensuse.org

View File

@@ -25,6 +25,7 @@ Summary: A library to manipulate gettext files
License: MIT
Group: Development/Languages/Python
Source0: http://bitbucket.org/izi/polib/downloads/polib-%{version}.tar.gz
Patch0: endian_magic.patch
BuildRoot: %{_tmppath}/%{name}-%{version}-build
BuildRequires: python-Sphinx
BuildRequires: python-devel
@@ -63,6 +64,7 @@ This package contains documentation in HTML format.
%prep
%setup -q -n polib-%{version}
%patch0 -p1
%build
python setup.py build