Skip to content

Commit

Permalink
fixed python bindings, broken by commit 60c1e1a "modified API to reac…
Browse files Browse the repository at this point in the history
…h a final state for the upcoming libmpq version"
  • Loading branch information
forrestv authored and glebm committed Nov 2, 2021
1 parent 14c913f commit b20ab3f
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions bindings/python/mpq.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def seek(self, offset, whence=os.SEEK_SET, os=os):
elif whence == os.SEEK_CUR:
offset += self._pos
elif whence == os.SEEK_END:
offset += self._file.unpacked_size
offset += self._file.size_unpacked
else:
raise ValueError, "invalid whence"

Expand Down Expand Up @@ -176,8 +176,8 @@ def __init__(self, archive, number, ctypes=ctypes, libmpq=libmpq):
self.number = number

for name, atype in [
("packed_size", ctypes.c_uint64),
("unpacked_size", ctypes.c_uint64),
("size_packed", ctypes.c_uint64),
("size_unpacked", ctypes.c_uint64),
("offset", ctypes.c_uint64),
("blocks", ctypes.c_uint32),
("encrypted", ctypes.c_uint32),
Expand All @@ -189,8 +189,11 @@ def __init__(self, archive, number, ctypes=ctypes, libmpq=libmpq):
func(self._archive._mpq, self.number, ctypes.byref(data))
setattr(self, name, data.value)

packed_size = property(lambda self: self.size_packed)
unpacked_size = property(lambda self: self.size_unpacked)

def __str__(self, ctypes=ctypes, libmpq=libmpq):
data = ctypes.create_string_buffer(self.unpacked_size)
data = ctypes.create_string_buffer(self.size_unpacked)
libmpq.libmpq__file_read(self._archive._mpq, self.number,
data, ctypes.c_uint64(len(data)), None)
return data.raw
Expand Down Expand Up @@ -221,8 +224,8 @@ def __init__(self, source, ctypes=ctypes, File=File, libmpq=libmpq):
self._opened = True

for field_name, field_type in [
("packed_size", ctypes.c_uint64),
("unpacked_size", ctypes.c_uint64),
("size_packed", ctypes.c_uint64),
("size_unpacked", ctypes.c_uint64),
("offset", ctypes.c_uint64),
("version", ctypes.c_uint32),
("files", ctypes.c_uint32),
Expand All @@ -232,6 +235,9 @@ def __init__(self, source, ctypes=ctypes, File=File, libmpq=libmpq):
func(self._mpq, ctypes.byref(data))
setattr(self, field_name, data.value)

packed_size = property(lambda self: self.size_packed)
unpacked_size = property(lambda self: self.size_unpacked)

def __del__(self, libmpq=libmpq):
if getattr(self, "_opened", False):
libmpq.libmpq__archive_close(self._mpq)
Expand Down Expand Up @@ -308,7 +314,7 @@ def __repr__(self):
d = "".join(d)

assert a == b == c == d, map(hash, [a,b,c,d])
assert len(a) == file.unpacked_size
assert len(a) == file.size_unpacked

repr(iter(file))

Expand Down

0 comments on commit b20ab3f

Please sign in to comment.