python: optimize to_x() & to_x_32() for python3

This commit is contained in:
Nguyen Anh Quynh 2014-04-14 16:21:34 +08:00
parent 5a46c146b5
commit b1e14f913d

View File

@ -53,7 +53,7 @@ def to_x(s):
from struct import pack
if not s: return '0'
x = pack(">q", s)
while x[0] == '\0': x = x[1:]
while x[0] in ('\0', 0): x = x[1:]
if _python3:
return "".join("{0:02x}".format(c) for c in x) # <-- Python 3 is OK
else:
@ -63,7 +63,7 @@ def to_x_32(s):
from struct import pack
if not s: return '0'
x = pack(">i", s)
while x[0] == '\0': x = x[1:]
while x[0] in ('\0', 0): x = x[1:]
if _python3:
return "".join("{0:02x}".format(c) for c in x) # <-- Python 3 is OK
else: