diff options
| author | Ted Ross <tross@apache.org> | 2008-11-21 15:36:05 +0000 |
|---|---|---|
| committer | Ted Ross <tross@apache.org> | 2008-11-21 15:36:05 +0000 |
| commit | dd41ba8fdfecb5e60e41b714945a7ef852d7b876 (patch) | |
| tree | dbbae1591cbc7db6a0d1d9700a43f0ab1d535b04 /qpid/python | |
| parent | ed6ad2636dfa46133f7202dea30313ba96b6fcb8 (diff) | |
| download | qpid-python-dd41ba8fdfecb5e60e41b714945a7ef852d7b876.tar.gz | |
Add ability to construct a ClassKey from it's __repr__ string.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk@719597 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/python')
| -rw-r--r-- | qpid/python/qmf/console.py | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/qpid/python/qmf/console.py b/qpid/python/qmf/console.py index 22c499e40a..4e74cac4ee 100644 --- a/qpid/python/qmf/console.py +++ b/qpid/python/qmf/console.py @@ -691,11 +691,28 @@ class Package: self.name = name class ClassKey: - """ """ - def __init__(self, codec): - self.pname = str(codec.read_str8()) - self.cname = str(codec.read_str8()) - self.hash = codec.read_bin128() + """ A ClassKey uniquely identifies a class from the schema. """ + def __init__(self, constructor): + if type(constructor) == str: + # construct from __repr__ string + try: + self.pname, cls = constructor.split(":") + self.cname, hsh = cls.split("(") + hsh = hsh.strip(")") + hexValues = hsh.split("-") + h0 = int(hexValues[0], 16) + h1 = int(hexValues[1], 16) + h2 = int(hexValues[2], 16) + h3 = int(hexValues[3], 16) + self.hash = struct.pack("!LLLL", h0, h1, h2, h3) + except: + raise Exception("Invalid ClassKey format") + else: + # construct from codec + codec = constructor + self.pname = str(codec.read_str8()) + self.cname = str(codec.read_str8()) + self.hash = codec.read_bin128() def encode(self, codec): codec.write_str8(self.pname) @@ -712,7 +729,7 @@ class ClassKey: return self.hash def getHashString(self): - return "%08x-%04x-%04x-%04x-%04x%08x" % struct.unpack ("!LHHHHL", self.hash) + return "%08x-%08x-%08x-%08x" % struct.unpack ("!LLLL", self.hash) def getPackageKey(self): return (self.cname, self.hash) |
