diff options
author | Rob Austein <sra@hactrn.net> | 2007-07-03 04:58:57 +0000 |
---|---|---|
committer | Rob Austein <sra@hactrn.net> | 2007-07-03 04:58:57 +0000 |
commit | daaf926e40e3bef50c458e7cc30d9026157d2f28 (patch) | |
tree | acc5b50e6b395db85e5be00d1769b53c82f68959 /scripts | |
parent | bbc75182b8ebf0eb6a0cc4072c9c228150736da5 (diff) |
Better constructors
svn path=/scripts/xml-parse-test.py; revision=714
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/xml-parse-test.py | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/scripts/xml-parse-test.py b/scripts/xml-parse-test.py index 643e13e7..22d42de8 100755 --- a/scripts/xml-parse-test.py +++ b/scripts/xml-parse-test.py @@ -15,8 +15,10 @@ class v4addr(long): bits = 32 def __new__(cls, x): - y = struct.unpack("!I", socket.inet_pton(socket.AF_INET, x)) - return long.__new__(cls, y[0]) + if isinstance(x, str): + y = struct.unpack("!I", socket.inet_pton(socket.AF_INET, x)) + x = y[0] + return long.__new__(cls, x) def __str__(self): return socket.inet_ntop(socket.AF_INET, struct.pack("!I", long(self))) @@ -25,8 +27,10 @@ class v6addr(long): bits = 128 def __new__(cls, x): - y = struct.unpack("!QQ", socket.inet_pton(socket.AF_INET6, x)) - return long.__new__(cls, (y[0] << 64) | y[1]) + if isinstance(x, str): + y = struct.unpack("!QQ", socket.inet_pton(socket.AF_INET6, x)) + x = (y[0] << 64) | y[1] + return long.__new__(cls, x) def __str__(self): return socket.inet_ntop(socket.AF_INET6, struct.pack("!QQ", long(self) >> 64, long(self) & 0xFFFFFFFFFFFFFFFF)) |