Replace deprecated chunk module with inline IFF parser
The chunk module was deprecated in 3.11 and removed in 3.13. Our usage was minimal (read name, size, data, skip padding), so a small _read_iff_chunk() helper replaces it with no deps.
This commit is contained in:
parent
3140a4d617
commit
909ee0932b
1 changed files with 23 additions and 11 deletions
|
|
@ -12,14 +12,30 @@
|
||||||
# root directory of this distribution.
|
# root directory of this distribution.
|
||||||
#
|
#
|
||||||
|
|
||||||
# Woohoo! Python has a module to parse IFF files, which is a generic
|
|
||||||
# interchange format. A Quetzal file is in fact a type of IFF file.
|
|
||||||
import chunk
|
|
||||||
import os
|
import os
|
||||||
|
import struct
|
||||||
|
|
||||||
from . import bitfield, zstackmanager
|
from . import bitfield, zstackmanager
|
||||||
from .zlogging import log
|
from .zlogging import log
|
||||||
|
|
||||||
|
|
||||||
|
def _read_iff_chunk(f):
|
||||||
|
"""Read one IFF chunk from a file-like object. Returns (name, data).
|
||||||
|
|
||||||
|
Raises EOFError when there are no more chunks to read.
|
||||||
|
"""
|
||||||
|
header = f.read(8)
|
||||||
|
if len(header) < 8:
|
||||||
|
raise EOFError
|
||||||
|
name = header[:4]
|
||||||
|
(size,) = struct.unpack(">I", header[4:8])
|
||||||
|
data = f.read(size)
|
||||||
|
# IFF chunks are padded to even byte boundaries
|
||||||
|
if size % 2 == 1:
|
||||||
|
f.read(1)
|
||||||
|
return name, data
|
||||||
|
|
||||||
|
|
||||||
# The general format of Queztal is that of a "FORM" IFF file, which is
|
# The general format of Queztal is that of a "FORM" IFF file, which is
|
||||||
# a container class for 'chunks'.
|
# a container class for 'chunks'.
|
||||||
#
|
#
|
||||||
|
|
@ -339,10 +355,8 @@ class QuetzalParser:
|
||||||
log("Parsing chunks from byte data")
|
log("Parsing chunks from byte data")
|
||||||
try:
|
try:
|
||||||
while 1:
|
while 1:
|
||||||
c = chunk.Chunk(self._file)
|
chunkname, chunk_data = _read_iff_chunk(self._file)
|
||||||
chunkname = c.getname()
|
chunksize = len(chunk_data)
|
||||||
chunksize = c.getsize()
|
|
||||||
chunk_data = c.read(chunksize)
|
|
||||||
log(f"** Found chunk ID {chunkname}: length {chunksize}")
|
log(f"** Found chunk ID {chunkname}: length {chunksize}")
|
||||||
self._last_loaded_metadata[chunkname] = chunksize
|
self._last_loaded_metadata[chunkname] = chunksize
|
||||||
|
|
||||||
|
|
@ -406,10 +420,8 @@ class QuetzalParser:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
while 1:
|
while 1:
|
||||||
c = chunk.Chunk(self._file)
|
chunkname, data = _read_iff_chunk(self._file)
|
||||||
chunkname = c.getname()
|
chunksize = len(data)
|
||||||
chunksize = c.getsize()
|
|
||||||
data = c.read(chunksize)
|
|
||||||
log(f"** Found chunk ID {chunkname}: length {chunksize}")
|
log(f"** Found chunk ID {chunkname}: length {chunksize}")
|
||||||
self._last_loaded_metadata[chunkname] = chunksize
|
self._last_loaded_metadata[chunkname] = chunksize
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue