addresses: raise varintEncodeError in encodeVarint()
instead of SystemExit (looks like a bug)
This commit is contained in:
parent
7a1f803c92
commit
0967f03b40
|
@ -54,11 +54,20 @@ def decodeBase58(string, alphabet=ALPHABET):
|
||||||
return num
|
return num
|
||||||
|
|
||||||
|
|
||||||
|
class varintEncodeError(Exception):
|
||||||
|
"""Exception class for encoding varint"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class varintDecodeError(Exception):
|
||||||
|
"""Exception class for decoding varint data"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def encodeVarint(integer):
|
def encodeVarint(integer):
|
||||||
"""Convert integer into varint bytes"""
|
"""Convert integer into varint bytes"""
|
||||||
if integer < 0:
|
if integer < 0:
|
||||||
logger.error('varint cannot be < 0')
|
raise varintEncodeError('varint cannot be < 0')
|
||||||
raise SystemExit
|
|
||||||
if integer < 253:
|
if integer < 253:
|
||||||
return pack('>B', integer)
|
return pack('>B', integer)
|
||||||
if integer >= 253 and integer < 65536:
|
if integer >= 253 and integer < 65536:
|
||||||
|
@ -68,13 +77,7 @@ def encodeVarint(integer):
|
||||||
if integer >= 4294967296 and integer < 18446744073709551616:
|
if integer >= 4294967296 and integer < 18446744073709551616:
|
||||||
return pack('>B', 255) + pack('>Q', integer)
|
return pack('>B', 255) + pack('>Q', integer)
|
||||||
if integer >= 18446744073709551616:
|
if integer >= 18446744073709551616:
|
||||||
logger.error('varint cannot be >= 18446744073709551616')
|
raise varintEncodeError('varint cannot be >= 18446744073709551616')
|
||||||
raise SystemExit
|
|
||||||
|
|
||||||
|
|
||||||
class varintDecodeError(Exception):
|
|
||||||
"""Exception class for decoding varint data"""
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def decodeVarint(data):
|
def decodeVarint(data):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user