4
__all__ = ["make_packet", "Packet"]
6
from wlms.errors import MSGarbageError
9
def __init__(self, args):
10
"""Convenience wrapper around a received packet"""
15
return self._args.pop(0)
17
raise MSGarbageError("Wanted a string but got no arguments left")
24
raise MSGarbageError("Invalid integer: %r" % s)
28
if s == "1" or s.lower() == "true":
30
elif s == "0" or s.lower() == "false":
32
raise MSGarbageError("Invalid bool: %r" % s)
34
def unpack(self, codes):
35
return [ self._CODES2FUNC[c](self) for c in codes ]
44
def make_packet(*args):
45
pstr = ''.join(str(x) + '\x00' for x in args)
47
return chr(size >> 8) + chr(size & 0xff) + pstr