9
"""ABC for objects that can be RLP encoded as is."""
10
__metaclass__ = abc.ABCMeta
14
Atomic.register(bytearray)
15
Atomic.register(unicode)
21
def str_to_bytes(value):
22
if isinstance(value, (bytes, bytearray)):
24
elif isinstance(value, unicode):
25
return codecs.encode(value, 'utf8')
27
raise TypeError("Value must be text, bytes, or bytearray")
30
def _old_int_to_big_endian(value):
33
cs.append(chr(value % 256))
35
s = ''.join(reversed(cs))
46
s = binascii.unhexlify(s)
49
int_to_big_endian = packl
52
def big_endian_to_int(value):
56
return struct.unpack('>Q', value.rjust(8, '\x00'))[0]
58
return int(encode_hex(value), 16)
61
def is_integer(value):
62
return isinstance(value, (int, long))
66
if isinstance(s, bytearray):
68
if not isinstance(s, (str, unicode)):
69
raise TypeError('Value must be an instance of str or unicode')
70
return s.decode('hex')
74
if isinstance(s, bytearray):
76
if not isinstance(s, (str, unicode)):
77
raise TypeError('Value must be an instance of str or unicode')
78
return s.encode('hex')
82
if isinstance(s, int):