Commit 9e8c76de authored by Jeremy Hylton's avatar Jeremy Hylton

Import struct pack and unpack at the top-level,

and eliminate default argument hack.
parent 973d486b
...@@ -13,18 +13,20 @@ ...@@ -13,18 +13,20 @@
############################################################################## ##############################################################################
import sys import sys
import TimeStamp, time, struct import TimeStamp, time
from struct import pack, unpack
if sys.version >= (2, 2): if sys.version >= (2, 2):
# Note that the distinction between ints and longs is blurred in # Note that the distinction between ints and longs is blurred in
# Python 2.2. So make u64() and U64() the same. # Python 2.2. So make u64() and U64() the same.
def p64(v, pack=struct.pack): def p64(v):
"""Pack an integer or long into a 8-byte string""" """Pack an integer or long into a 8-byte string"""
return pack(">Q", v) return pack(">Q", v)
def u64(v, unpack=struct.unpack): def u64(v):
"""Unpack an 8-byte string into a 64-bit long integer.""" """Unpack an 8-byte string into a 64-bit long integer."""
return unpack(">Q", v)[0] return unpack(">Q", v)[0]
...@@ -34,7 +36,7 @@ else: ...@@ -34,7 +36,7 @@ else:
t32 = 1L << 32 t32 = 1L << 32
def p64(v, pack=struct.pack): def p64(v):
"""Pack an integer or long into a 8-byte string""" """Pack an integer or long into a 8-byte string"""
if v < t32: if v < t32:
h = 0 h = 0
...@@ -42,7 +44,7 @@ else: ...@@ -42,7 +44,7 @@ else:
h, v = divmod(v, t32) h, v = divmod(v, t32)
return pack(">II", h, v) return pack(">II", h, v)
def u64(v, unpack=struct.unpack): def u64(v):
"""Unpack an 8-byte string into a 64-bit (or long) integer.""" """Unpack an 8-byte string into a 64-bit (or long) integer."""
h, v = unpack(">ii", v) h, v = unpack(">ii", v)
if v < 0: if v < 0:
...@@ -53,7 +55,7 @@ else: ...@@ -53,7 +55,7 @@ else:
v = (long(h) << 32) + v v = (long(h) << 32) + v
return v return v
def U64(v, unpack=struct.unpack): def U64(v):
"""Same as u64 but always returns a long.""" """Same as u64 but always returns a long."""
h, v = unpack(">II", v) h, v = unpack(">II", v)
if h: if h:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment