Dulwich.io dulwich / ab6d631
Split out parsing/formatting. Jelmer Vernooń≥ a month ago
1 changed file(s) with 13 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
149149 pass
150150
151151
152 def format_cmd_pkt(cmd, *args):
153 return cmd + b" " + b"".join([(a + b"\0") for a in args])
154
155
156 def parse_cmd_pkt(line):
157 splice_at = line.find(b" ")
158 cmd, args = line[:splice_at], line[splice_at+1:]
159 assert args[-1:] == b"\x00"
160 return cmd, args[:-1].split(b"\0")
161
162
152163 def pkt_line(data):
153164 """Wrap data in a pkt-line.
154165
326337 cmd: The remote service to access.
327338 args: List of arguments to send to remove service.
328339 """
329 self.write_pkt_line(cmd + b" " + b"".join([(a + b"\0") for a in args]))
340 self.write_pkt_line(format_cmd_pkt(cmd, *args))
330341
331342 def read_cmd(self):
332343 """Read a command and some arguments from the git client
336347 Returns: A tuple of (command, [list of arguments]).
337348 """
338349 line = self.read_pkt_line()
339 splice_at = line.find(b" ")
340 cmd, args = line[:splice_at], line[splice_at+1:]
341 assert args[-1:] == b"\x00"
342 return cmd, args[:-1].split(b"\0")
350 return parse_cmd_pkt(line)
343351
344352
345353 _RBUFSIZE = 8192 # Default read buffer size.