class documentation

Class for interacting with a remote git process over the wire.

Parts of the git wire protocol use 'pkt-lines' to communicate. A pkt-line consists of the length of the line as a 4-byte hex string, followed by the payload data. The length includes the 4-byte header. The special line '0000' indicates the end of a section of input and is called a 'flush-pkt'.

For details on the pkt-line format, see the cgit distribution:
Documentation/technical/protocol-common.txt
Method __del__ Ensure transport is closed when Protocol is garbage collected.
Method __enter__ Enter context manager.
Method __exit__ Exit context manager and close transport.
Method __init__ Initialize Protocol.
Method close Close the underlying transport if a close function was provided.
Method eof Test whether the protocol stream has reached EOF.
Method read_cmd Read a command and some arguments from the git client.
Method read_pkt_line Reads a pkt-line from the remote git process.
Method read_pkt_seq Read a sequence of pkt-lines from the remote git process.
Method send_cmd Send a command and some arguments to a git server.
Method unread_pkt_line Unread a single line of data into the readahead buffer.
Method write_pkt_line Sends a pkt-line to the remote git process.
Method write_sideband Write multiplexed data to the sideband.
Instance Variable read Undocumented
Instance Variable report_activity Undocumented
Instance Variable write Undocumented
Instance Variable _close Undocumented
Instance Variable _readahead Undocumented
def __del__(self):

Ensure transport is closed when Protocol is garbage collected.

def __enter__(self) -> Protocol:

Enter context manager.

def __exit__(self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: types.TracebackType | None):

Exit context manager and close transport.

def __init__(self, read: Callable[[int], bytes], write: Callable[[bytes], int | None], close: Callable[[], None] | None = None, report_activity: Callable[[int, str], None] | None = None):

Initialize Protocol.

Parameters
read:Callable[[int], bytes]Function to read bytes from the transport
write:Callable[[bytes], int | None]Function to write bytes to the transport
close:Callable[[], None] | NoneOptional function to close the transport
report_activity:Callable[[int, str], None] | NoneOptional function to report activity
def close(self):

Close the underlying transport if a close function was provided.

def eof(self) -> bool:

Test whether the protocol stream has reached EOF.

Note that this refers to the actual stream EOF and not just a flush-pkt.

Returns: True if the stream is at EOF, False otherwise.

def read_cmd(self) -> tuple[bytes, list[bytes]]:

Read a command and some arguments from the git client.

Only used for the TCP git protocol (git://).

Returns: A tuple of (command, [list of arguments]).

def read_pkt_line(self) -> bytes | None:

Reads a pkt-line from the remote git process.

This method may read from the readahead buffer; see unread_pkt_line.

Returns: The next string from the stream, without the length prefix, or
None for a flush-pkt ('0000') or delim-pkt ('0001').
def read_pkt_seq(self) -> Iterable[bytes]:

Read a sequence of pkt-lines from the remote git process.

Returns: Yields each line of data up to but not including the next
flush-pkt.
def send_cmd(self, cmd: bytes, *args: bytes):

Send a command and some arguments to a git server.

Only used for the TCP git protocol (git://).

Parameters
cmd:bytesThe remote service to access.
*args:bytesList of arguments to send to remove service.
def unread_pkt_line(self, data: bytes | None):

Unread a single line of data into the readahead buffer.

This method can be used to unread a single pkt-line into a fixed readahead buffer.

Parameters
data:bytes | NoneThe data to unread, without the length prefix.
Raises
ValueErrorIf more than one pkt-line is unread.
def write_pkt_line(self, line: bytes | None):

Sends a pkt-line to the remote git process.

Parameters
line:bytes | NoneA string containing the data to send, without the length prefix.
def write_sideband(self, channel: int, blob: bytes):

Write multiplexed data to the sideband.

Parameters
channel:intAn int specifying the channel to write to.
blob:bytesA blob of data (as a string) to send on this channel.
read =

Undocumented

report_activity =

Undocumented

write =

Undocumented

_close =

Undocumented

_readahead: BytesIO | None =

Undocumented