def Byte(value=None): ''' Match or read a byte (if a value is given, it must match). ''' if value is None: return BEnd(8) else: return _Constant(BitString.from_byte(value))
def test_from_byte(self): self.assert_error(lambda: BitString.from_byte(-1)) self.assert_length_value(8, b'\x00', BitString.from_byte(0)) self.assert_length_value(8, b'\x01', BitString.from_byte(1)) self.assert_length_value(8, b'\xff', BitString.from_byte(255)) self.assert_error(lambda: BitString.from_byte(256))