Commit Graph

25 Commits

Author SHA1 Message Date
dgelessus
6adf8eb88d Fix mypy errors about byte strings as format string parameters 2019-12-30 01:48:33 +01:00
dgelessus
546edbc31a Update and improve resource and resource map reprs 2019-12-04 02:01:40 +01:00
dgelessus
cf6ce3c2a6 Move _LazyResourceMap out of ResourceFile 2019-12-04 02:01:40 +01:00
dgelessus
af2ac70676 Simplify ResourceFile._references and ._LazyResourceMap
The _references map now stores Resource objects directly, instead of
constructing them only when they are looked up. Resource objects are
now lazy themselves, so the previous lazy resource creation mechanism
is redundant.

_LazyResourceMap is now a simple read-only wrapper around an existing
map. The custom class is now only used to provide a specialized repr.
2019-12-04 02:01:40 +01:00
dgelessus
5af455992b Refactor resource reading internals
The reading of resource name and data is now performed in the Resource
class (lazily, when the respective attributes are accessed) instead of
in ResourceFile._LazyResourceMap.
2019-12-04 02:01:40 +01:00
dgelessus
e0f73d3220 Fix more issues reported by mypy 2019-09-29 16:28:07 +02:00
dgelessus
e5875ffe67 Fix various issues reported by mypy 2019-09-29 16:14:55 +02:00
dgelessus
449bf4dd71 Use parameterized typing.Mapping in ResourceFile definition
Previously the un-parameterized collections.abc.Mapping was used, which
makes type checking less accurate, as the exact key/value types are not
known.
2019-09-29 15:42:19 +02:00
dgelessus
29ddd21740 Add missing type annotations on some methods 2019-09-29 15:32:18 +02:00
dgelessus
add22b704a Fix ResourceFile.__enter__ not returning anything 2019-09-29 15:09:41 +02:00
dgelessus
fdd04c944b Remove __slots__ declaration from Resource class
It doesn't seem to have any noticeable performance benefit.
2019-09-29 15:00:45 +02:00
dgelessus
97c459bca7 Change attribute type annotations to standard format
Previously, the types of instance attributes were annotated with the
first assignment of each attribute. The standard way to annotate
instance attributes is to do so at class level without assigning any
value.
2019-09-29 14:58:18 +02:00
dgelessus
9ef084de58 Remove uses of the typing.io pseudo-module
According to https://bugs.python.org/issue35089, typing.io should not
be used anymore, and the types that it contains should be accessed
through the main typing module instead.
2019-09-28 01:40:34 +02:00
dgelessus
c108af60ca Add length and length_raw attributes to Resource (closes #3)
For compressed resources, the value of the length attribute can be
accessed much more quickly than the data itself (because it only
requires parsing the header, rather than decompressing the entire
data). This is used to speed up listing of compressed resources on the
command line.

The length_raw attribute is added for symmetry, although it is not
specifically optimized in any case yet.
2019-09-24 00:13:23 +02:00
dgelessus
868a322b8e Add Resource.compressed_info attribute
This allows accessing a compressed resource's header data, without
having to decompress it or parse the compressed data manually.
2019-09-23 23:50:29 +02:00
dgelessus
c6337bdfbd Rename resource_type and resource_id attributes to type and id
The old names were chosen to avoid conflicts with Python's type and id
builtins, but for attribute names this is not necessary.
2019-09-15 15:56:03 +02:00
dgelessus
e6779b021a Replace rsrcfork.open's rsrcfork parameter with a more usable version
The new fork parameter accepts strings, which are more understandable
than the old None/True/False values, and can be extended in the future.
2019-08-31 20:07:26 +02:00
dgelessus
acdbbc89b2 Improve automatic fork selection when resource fork is invalid 2019-08-30 23:17:59 +02:00
dgelessus
d7fb67fac1 Add better error checking for invalid resource files 2019-08-30 23:17:59 +02:00
dgelessus
5ede8a351a Rework how non-seekable streams are handled by ResourceFile
The broken non-seeking read implementation of ResourceFile is removed,
and non-seekable streams are now handled by reading the entire stream
data first and wrapping it in a BytesIO to make it seekable.

The manual selection of seeking/non-seeking reading has been removed as
well, since it is no longer needed and was already nearly useless.
2019-08-30 23:17:18 +02:00
dgelessus
2fb1d02064 Add initial support for compressed resources
Not all compression formats are supported yet.
2019-07-14 02:16:49 +02:00
dgelessus
a9a3168345 Change flag enum definitions to use bit shift instead of literals
Bit shifts are easier to read and less error-prone than typing the
values out by hand.
2018-02-25 17:11:39 +01:00
dgelessus
0b8699c2f1 Do not close user-supplied streams in ResourceFork.close by default
When using ResourceFork.open, the stream is still closed when the
ResourceFile is closed, because the user has no access to the stream.
This matches the behavior of modules like zipfile and tarfile, which
close their underlying streams if they created them themselves, but not
if they were supplied by the user.
2018-02-16 22:47:36 +01:00
dgelessus
2dbf0f7047 Fix ResourceFork.open and __init__ not closing streams in some cases 2018-02-16 22:30:18 +01:00
dgelessus
cbc55fcbc2 Refactor rsrcfork.py into a package 2018-02-12 22:48:46 +01:00