dulwich.protocol module¶
Generic functions for talking the git smart server protocol.
- class dulwich.protocol.BufferedPktLineWriter(write, bufsize=65515)¶
Bases:
object
Writer that wraps its data in pkt-lines and has an independent buffer.
Consecutive calls to write() wrap the data in a pkt-line and then buffers it until enough lines have been written such that their total length (including length prefix) reach the buffer size.
Initialize the BufferedPktLineWriter.
- Parameters
write – A write callback for the underlying writer.
bufsize – The internal buffer size, including length prefixes.
- flush()¶
Flush all data from the buffer.
- write(data)¶
Write data, wrapping it in a pkt-line.
- class dulwich.protocol.PktLineParser(handle_pkt)¶
Bases:
object
Packet line parser that hands completed packets off to a callback.
- get_tail()¶
Read back any unused data.
- parse(data)¶
Parse a fragment of data and call back for any completed packets.
- class dulwich.protocol.Protocol(read, write, close=None, report_activity=None)¶
Bases:
object
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
- close()¶
- eof()¶
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.
- read_cmd()¶
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]).
- read_pkt_line()¶
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’).
- read_pkt_seq()¶
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.
- send_cmd(cmd, *args)¶
Send a command and some arguments to a git server.
Only used for the TCP git protocol (git://).
- Parameters
cmd – The remote service to access.
args – List of arguments to send to remove service.
- unread_pkt_line(data)¶
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 – The data to unread, without the length prefix.
- Raises
ValueError – If more than one pkt-line is unread.
- write_pkt_line(line)¶
Sends a pkt-line to the remote git process.
- Parameters
line – A string containing the data to send, without the length prefix.
- write_sideband(channel, blob)¶
Write multiplexed data to the sideband.
- Parameters
channel – An int specifying the channel to write to.
blob – A blob of data (as a string) to send on this channel.
- class dulwich.protocol.ReceivableProtocol(recv, write, close=None, report_activity=None, rbufsize=8192)¶
Bases:
Protocol
Variant of Protocol that allows reading up to a size without blocking.
This class has a recv() method that behaves like socket.recv() in addition to a read() method.
If you want to read n bytes from the wire and block until exactly n bytes (or EOF) are read, use read(n). If you want to read at most n bytes from the wire but don’t care if you get less, use recv(n). Note that recv(n) will still block until at least one byte is read.
- read(size)¶
- recv(size)¶
- dulwich.protocol.ack_type(capabilities)¶
Extract the ack type from a capabilities list.
- dulwich.protocol.agent_string()¶
- dulwich.protocol.capability_agent()¶
- dulwich.protocol.capability_symref(from_ref, to_ref)¶
- dulwich.protocol.extract_capabilities(text)¶
Extract a capabilities list from a string, if present.
- Parameters
text – String to extract from
Returns: Tuple with text with capabilities removed and list of capabilities
- dulwich.protocol.extract_capability_names(capabilities)¶
- dulwich.protocol.extract_want_line_capabilities(text)¶
Extract a capabilities list from a want line, if present.
Note that want lines have capabilities separated from the rest of the line by a space instead of a null byte. Thus want lines have the form:
want obj-id cap1 cap2 …
- Parameters
text – Want line to extract from
Returns: Tuple with text with capabilities removed and list of capabilities
- dulwich.protocol.format_ack_line(sha, ack_type=b'')¶
- dulwich.protocol.format_capability_line(capabilities)¶
- dulwich.protocol.format_cmd_pkt(cmd, *args)¶
- dulwich.protocol.format_ref_line(ref, sha, capabilities=None)¶
- dulwich.protocol.format_shallow_line(sha)¶
- dulwich.protocol.format_unshallow_line(sha)¶
- dulwich.protocol.parse_capability(capability)¶
- dulwich.protocol.parse_cmd_pkt(line)¶
- dulwich.protocol.pkt_line(data)¶
Wrap data in a pkt-line.
- Parameters
data – The data to wrap, as a str or None.
- Returns: The data prefixed with its length in pkt-line format; if data was
None, returns the flush-pkt (‘0000’).
- dulwich.protocol.symref_capabilities(symrefs)¶