fix failures

This commit is contained in:
senstella
2026-01-18 03:29:42 +09:00
parent ca85a52839
commit 6560ac93f1
6 changed files with 243 additions and 65 deletions

View File

@@ -31,7 +31,11 @@ from .wire import (
ContainerDecoder = Callable[[bytes], Any]
def _split_decoder(decoder: ContainerDecoder | tuple[ContainerDecoder | None, ContainerDecoder | None] | None):
def _split_decoder(
decoder: ContainerDecoder
| tuple[ContainerDecoder | None, ContainerDecoder | None]
| None,
):
if decoder is None:
return None, None
if isinstance(decoder, tuple):
@@ -56,7 +60,14 @@ class FilePatch:
class PatchReader:
def __init__(self, stream, *, container_decoder: ContainerDecoder | tuple[ContainerDecoder | None, ContainerDecoder | None] | None = None):
def __init__(
self,
stream,
*,
container_decoder: ContainerDecoder
| tuple[ContainerDecoder | None, ContainerDecoder | None]
| None = None,
):
self._stream = stream
self._raw_wire = WireReader(stream)
self._wire: WireReader | None = None
@@ -70,7 +81,14 @@ class PatchReader:
self._init_stream(container_decoder)
@classmethod
def open(cls, path: str, *, container_decoder: ContainerDecoder | tuple[ContainerDecoder | None, ContainerDecoder | None] | None = None):
def open(
cls,
path: str,
*,
container_decoder: ContainerDecoder
| tuple[ContainerDecoder | None, ContainerDecoder | None]
| None = None,
):
return cls(open(path, "rb"), container_decoder=container_decoder)
def _init_stream(self, container_decoder):
@@ -81,8 +99,12 @@ class PatchReader:
self._wire = WireReader(decompressed)
target_decoder, source_decoder = _split_decoder(container_decoder)
self.target_container_raw, self.target_container = self._read_container(target_decoder)
self.source_container_raw, self.source_container = self._read_container(source_decoder)
self.target_container_raw, self.target_container = self._read_container(
target_decoder
)
self.source_container_raw, self.source_container = self._read_container(
source_decoder
)
def _read_container(self, decoder: ContainerDecoder | None):
assert self._wire is not None
@@ -92,18 +114,12 @@ class PatchReader:
def iter_file_entries(self) -> Iterator[FilePatch]:
assert self._wire is not None
file_index = 0
while True:
try:
sync_header = self._wire.read_message(SyncHeader)
except EOFError:
return
if sync_header.file_index is None:
sync_header.file_index = file_index
else:
file_index = int(sync_header.file_index)
header_type = sync_header.type
if header_type is None:
header_type = SyncHeaderType.RSYNC
@@ -131,7 +147,6 @@ class PatchReader:
bsdiff_header=bsdiff_header,
bsdiff_controls=controls,
)
file_index += 1
continue
if header_type != SyncHeaderType.RSYNC:
@@ -145,7 +160,6 @@ class PatchReader:
ops.append(op)
yield FilePatch(sync_header=sync_header, sync_ops=ops)
file_index += 1
def close(self) -> None:
if self._wire:
@@ -182,7 +196,9 @@ class SignatureReader:
self._wire = WireReader(decompressed)
self.container_raw = self._wire.read_message_bytes()
self.container = container_decoder(self.container_raw) if container_decoder else None
self.container = (
container_decoder(self.container_raw) if container_decoder else None
)
def iter_block_hashes(self) -> Iterator[BlockHash]:
assert self._wire is not None
@@ -227,7 +243,9 @@ class ManifestReader:
self._wire = WireReader(decompressed)
self.container_raw = self._wire.read_message_bytes()
self.container = container_decoder(self.container_raw) if container_decoder else None
self.container = (
container_decoder(self.container_raw) if container_decoder else None
)
def iter_block_hashes(self) -> Iterator[ManifestBlockHash]:
assert self._wire is not None
@@ -267,7 +285,9 @@ class WoundsReader:
self._wire.expect_magic(WOUNDS_MAGIC)
self.header = self._wire.read_message(WoundsHeader)
self.container_raw = self._wire.read_message_bytes()
self.container = container_decoder(self.container_raw) if container_decoder else None
self.container = (
container_decoder(self.container_raw) if container_decoder else None
)
def iter_wounds(self) -> Iterator[Wound]:
while True: