class documentation

class SHA1Reader(BinaryIO):

Constructor: SHA1Reader(f)

View In Hierarchy

Wrapper for file-like object that remembers the SHA1 of its data.

Method __enter__ Enter context manager.
Method __exit__ Exit context manager and close file.
Method __init__ Initialize SHA1Reader.
Method __iter__ Return iterator for reading file lines.
Method __next__ Get next line from file.
Method check_sha Check if the SHA1 matches the expected value.
Method close Close the underlying file.
Method fileno Return file descriptor number.
Method flush Flush the file buffer.
Method isatty Check if file is a terminal.
Method read Read bytes and update SHA1.
Method readable Check if file is readable.
Method readline Read a line from the file.
Method readlines Read all lines from the file.
Method seek Seek to position in file.
Method seekable Check if file is seekable.
Method tell Return current file position.
Method truncate Not supported for read-only file.
Method writable Check if file is writable.
Method write Write data to the file (not supported).
Method writelines Write multiple lines to the file (not supported).
Instance Variable f Undocumented
Instance Variable sha1 Undocumented
def __enter__(self) -> SHA1Reader:

Enter context manager.

def __exit__(self, type: type | None, value: BaseException | None, traceback: TracebackType | None):

Exit context manager and close file.

def __init__(self, f: IO[bytes]):

Initialize SHA1Reader.

Parameters
f:IO[bytes]File-like object to wrap
def __iter__(self) -> SHA1Reader:

Return iterator for reading file lines.

def __next__(self) -> bytes:

Get next line from file.

Returns
bytesNext line
Raises
StopIterationWhen no more lines
def check_sha(self, allow_empty: bool = False):

Check if the SHA1 matches the expected value.

Parameters
allow_empty:boolAllow empty SHA1 hash
Raises
ChecksumMismatchIf SHA1 doesn't match
def close(self):

Close the underlying file.

def fileno(self) -> int:

Return file descriptor number.

def flush(self):

Flush the file buffer.

def isatty(self) -> bool:

Check if file is a terminal.

def read(self, size: int = -1) -> bytes:

Read bytes and update SHA1.

Parameters
size:intNumber of bytes to read, -1 for all
Returns
bytesBytes read from file
def readable(self) -> bool:

Check if file is readable.

def readline(self, size: int = -1) -> bytes:

Read a line from the file.

Parameters
size:intMaximum bytes to read
Returns
bytesLine read from file
def readlines(self, hint: int = -1) -> list[bytes]:

Read all lines from the file.

Parameters
hint:intApproximate number of bytes to read
Returns
list[bytes]List of lines
def seek(self, offset: int, whence: int = 0) -> int:

Seek to position in file.

Parameters
offset:intPosition offset
whence:intReference point (0=start, 1=current, 2=end)
Returns
intNew file position
def seekable(self) -> bool:

Check if file is seekable.

def tell(self) -> int:

Return current file position.

def truncate(self, size: int | None = None) -> int:

Not supported for read-only file.

Raises
UnsupportedOperationAlways raised
def writable(self) -> bool:

Check if file is writable.

def write(self, data: bytes, /) -> int:

Write data to the file (not supported).

def writelines(self, lines: Iterable[bytes], /):

Write multiple lines to the file (not supported).

f =

Undocumented

sha1 =

Undocumented