You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by tr...@apache.org on 2008/11/21 16:36:06 UTC

svn commit: r719597 - /incubator/qpid/trunk/qpid/python/qmf/console.py

Author: tross
Date: Fri Nov 21 07:36:05 2008
New Revision: 719597

URL: http://svn.apache.org/viewvc?rev=719597&view=rev
Log:
Add ability to construct a ClassKey from it's __repr__ string.

Modified:
    incubator/qpid/trunk/qpid/python/qmf/console.py

Modified: incubator/qpid/trunk/qpid/python/qmf/console.py
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/python/qmf/console.py?rev=719597&r1=719596&r2=719597&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/python/qmf/console.py (original)
+++ incubator/qpid/trunk/qpid/python/qmf/console.py Fri Nov 21 07:36:05 2008
@@ -691,11 +691,28 @@
     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 @@
     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)