Move _LazyResourceMap out of ResourceFile

This commit is contained in:
dgelessus 2019-12-03 15:56:09 +01:00
parent af2ac70676
commit cf6ce3c2a6

View File

@ -229,10 +229,6 @@ class Resource(object):
else:
return self.data_raw
class ResourceFile(typing.Mapping[bytes, typing.Mapping[int, Resource]], typing.ContextManager["ResourceFile"]):
"""A resource file reader operating on a byte stream."""
# noinspection PyProtectedMember
class _LazyResourceMap(typing.Mapping[int, Resource]):
"""Internal class: Read-only wrapper for a mapping of resource IDs to resource objects.
@ -274,6 +270,9 @@ class ResourceFile(typing.Mapping[bytes, typing.Mapping[int, Resource]], typing.
else:
return f"<{type(self).__module__}.{type(self).__qualname__} at {id(self):#x} containing {len(self)} resources with IDs: {list(self)}>"
class ResourceFile(typing.Mapping[bytes, typing.Mapping[int, Resource]], typing.ContextManager["ResourceFile"]):
"""A resource file reader operating on a byte stream."""
_close_stream: bool
_stream: typing.BinaryIO
@ -500,10 +499,10 @@ class ResourceFile(typing.Mapping[bytes, typing.Mapping[int, Resource]], typing.
return key in self._references
def __getitem__(self, key: bytes) -> "ResourceFile._LazyResourceMap":
def __getitem__(self, key: bytes) -> "_LazyResourceMap":
"""Get a lazy mapping of all resources with the given type in this ResourceFile."""
return ResourceFile._LazyResourceMap(self._references[key])
return _LazyResourceMap(self._references[key])
def __repr__(self) -> str:
return f"<{type(self).__module__}.{type(self).__qualname__} at {id(self):#x}, attributes {self.file_attributes}, containing {len(self)} resource types: {list(self)}>"