Source code for zipwire._errors
"""Exception hierarchy for zipwire."""
from __future__ import annotations
[docs]
class ZipwireError(Exception):
"""Base exception for all zipwire errors."""
[docs]
class BadZipFile(ZipwireError):
"""The data does not appear to be a valid ZIP archive."""
[docs]
class UnsupportedCompression(ZipwireError):
"""The file uses an unsupported compression method."""
def __init__(self, method: int) -> None:
self.method = method
super().__init__(f"Unsupported compression method: {method}")
[docs]
class CRCMismatch(ZipwireError):
"""CRC-32 check failed after decompression."""
def __init__(self, expected: int, actual: int) -> None:
self.expected = expected
self.actual = actual
super().__init__(f"CRC-32 mismatch: expected {expected:#010x}, got {actual:#010x}")
[docs]
class RangeRequestUnsupported(ZipwireError):
"""The HTTP server does not support range requests."""
[docs]
class FileNotFoundInZip(ZipwireError, KeyError):
"""The requested file was not found in the ZIP archive."""
def __init__(self, filename: str) -> None:
self.filename = filename
super().__init__(f"File not found in archive: {filename!r}")