mirror of
https://github.com/dgelessus/python-rsrcfork.git
synced 2025-01-01 07:29:40 +00:00
Fix more issues reported by mypy
This commit is contained in:
parent
b77c85c295
commit
e0f73d3220
@ -65,7 +65,7 @@ def _bytes_unescape(string: str) -> bytes:
|
|||||||
|
|
||||||
return bytes(out)
|
return bytes(out)
|
||||||
|
|
||||||
def _bytes_escape(bs: bytes, *, quote: str=None) -> str:
|
def _bytes_escape(bs: bytes, *, quote: typing.Optional[str]=None) -> str:
|
||||||
"""Convert a bytestring to a string (using _TEXT_ENCODING), with non-printable characters hex-escaped.
|
"""Convert a bytestring to a string (using _TEXT_ENCODING), with non-printable characters hex-escaped.
|
||||||
|
|
||||||
(We implement our own escaping mechanism here to not depend on Python's str or bytes repr.)
|
(We implement our own escaping mechanism here to not depend on Python's str or bytes repr.)
|
||||||
|
@ -4,6 +4,7 @@ import enum
|
|||||||
import io
|
import io
|
||||||
import os
|
import os
|
||||||
import struct
|
import struct
|
||||||
|
import types
|
||||||
import typing
|
import typing
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
@ -197,7 +198,7 @@ class Resource(object):
|
|||||||
else:
|
else:
|
||||||
return self.data_raw
|
return self.data_raw
|
||||||
|
|
||||||
class ResourceFile(typing.Mapping[bytes, typing.Mapping[int, Resource]]):
|
class ResourceFile(typing.Mapping[bytes, typing.Mapping[int, Resource]], typing.ContextManager["ResourceFile"]):
|
||||||
"""A resource file reader operating on a byte stream."""
|
"""A resource file reader operating on a byte stream."""
|
||||||
|
|
||||||
# noinspection PyProtectedMember
|
# noinspection PyProtectedMember
|
||||||
@ -274,7 +275,7 @@ class ResourceFile(typing.Mapping[bytes, typing.Mapping[int, Resource]]):
|
|||||||
_references: typing.MutableMapping[bytes, typing.MutableMapping[int, typing.Tuple[int, ResourceAttrs, int]]]
|
_references: typing.MutableMapping[bytes, typing.MutableMapping[int, typing.Tuple[int, ResourceAttrs, int]]]
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def open(cls, filename: typing.Union[str, os.PathLike], *, fork: str="auto", **kwargs) -> "ResourceFile":
|
def open(cls, filename: typing.Union[str, os.PathLike], *, fork: str="auto", **kwargs: typing.Any) -> "ResourceFile":
|
||||||
"""Open the file at the given path as a ResourceFile.
|
"""Open the file at the given path as a ResourceFile.
|
||||||
|
|
||||||
The fork parameter controls which fork of the file the resource data will be read from. It accepts the following values:
|
The fork parameter controls which fork of the file the resource data will be read from. It accepts the following values:
|
||||||
@ -458,8 +459,14 @@ class ResourceFile(typing.Mapping[bytes, typing.Mapping[int, Resource]]):
|
|||||||
def __enter__(self) -> "ResourceFile":
|
def __enter__(self) -> "ResourceFile":
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def __exit__(self, exc_type, exc_val, exc_tb) -> None:
|
def __exit__(
|
||||||
|
self,
|
||||||
|
exc_type: typing.Optional[typing.Type[BaseException]],
|
||||||
|
exc_val: typing.Optional[BaseException],
|
||||||
|
exc_tb: typing.Optional[types.TracebackType]
|
||||||
|
) -> typing.Optional[bool]:
|
||||||
self.close()
|
self.close()
|
||||||
|
return None
|
||||||
|
|
||||||
def __len__(self) -> int:
|
def __len__(self) -> int:
|
||||||
"""Get the number of resource types in this ResourceFile."""
|
"""Get the number of resource types in this ResourceFile."""
|
||||||
|
@ -84,7 +84,7 @@ class CompressedApplicationHeaderInfo(CompressedHeaderInfo):
|
|||||||
self.working_buffer_fractional_size = working_buffer_fractional_size
|
self.working_buffer_fractional_size = working_buffer_fractional_size
|
||||||
self.expansion_buffer_size = expansion_buffer_size
|
self.expansion_buffer_size = expansion_buffer_size
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self) -> str:
|
||||||
return f"{type(self).__qualname__}(header_length={self.header_length}, compression_type=0x{self.compression_type:>04x}, decompressed_length={self.decompressed_length}, dcmp_id={self.dcmp_id}, working_buffer_fractional_size={self.working_buffer_fractional_size}, expansion_buffer_size={self.expansion_buffer_size})"
|
return f"{type(self).__qualname__}(header_length={self.header_length}, compression_type=0x{self.compression_type:>04x}, decompressed_length={self.decompressed_length}, dcmp_id={self.dcmp_id}, working_buffer_fractional_size={self.working_buffer_fractional_size}, expansion_buffer_size={self.expansion_buffer_size})"
|
||||||
|
|
||||||
|
|
||||||
@ -96,7 +96,7 @@ class CompressedSystemHeaderInfo(CompressedHeaderInfo):
|
|||||||
|
|
||||||
self.parameters = parameters
|
self.parameters = parameters
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self) -> str:
|
||||||
return f"{type(self).__qualname__}(header_length={self.header_length}, compression_type=0x{self.compression_type:>04x}, decompressed_length={self.decompressed_length}, dcmp_id={self.dcmp_id}, parameters={self.parameters!r})"
|
return f"{type(self).__qualname__}(header_length={self.header_length}, compression_type=0x{self.compression_type:>04x}, decompressed_length={self.decompressed_length}, dcmp_id={self.dcmp_id}, parameters={self.parameters!r})"
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user