1 class protoerr(Exception):
10 elif c >= b'0' or c <= b'9':
11 hln = (hln * 10) + (ord(c) - ord(b'0'))
13 raise protoerr("Invalid netstring length byte: " + c)
15 if sk.read(1) != b',':
16 raise protoerr("Non-terminated netstring")
20 parts = readns(sk).split(b'\0')[:-1]
21 if len(parts) % 2 != 0:
22 raise protoerr("Malformed headers")
26 ret[parts[i]] = parts[i + 1]
30 def decodehead(head, coding):
31 return {k.decode(coding): v.decode(coding) for k, v in head.items()}