qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r..@apache.org
Subject svn commit: r1611451 - /qpid/proton/trunk/proton-c/bindings/python/proton.py
Date Thu, 17 Jul 2014 19:51:44 GMT
Author: rhs
Date: Thu Jul 17 19:51:44 2014
New Revision: 1611451

URL: http://svn.apache.org/r1611451
Log:
added pretty printing for disposition types

Modified:
    qpid/proton/trunk/proton-c/bindings/python/proton.py

Modified: qpid/proton/trunk/proton-c/bindings/python/proton.py
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/proton-c/bindings/python/proton.py?rev=1611451&r1=1611450&r2=1611451&view=diff
==============================================================================
--- qpid/proton/trunk/proton-c/bindings/python/proton.py (original)
+++ qpid/proton/trunk/proton-c/bindings/python/proton.py Thu Jul 17 19:51:44 2014
@@ -2761,13 +2761,38 @@ class Receiver(Link):
   def draining(self):
     return pn_link_draining(self._link)
 
+class NamedInt(int):
+
+  values = {}
+
+  def __new__(cls, i, name):
+    ni = super(NamedInt, cls).__new__(cls, i)
+    cls.values[i] = ni
+    return ni
+
+  def __init__(self, i, name):
+    self.name = name
+
+  def __repr__(self):
+    return self.name
+
+  def __str__(self):
+    return self.name
+
+  @classmethod
+  def get(cls, i):
+    return cls.values.get(i, i)
+
+class DispositionType(NamedInt):
+  values = {}
+
 class Disposition(object):
 
-  RECEIVED = PN_RECEIVED
-  ACCEPTED = PN_ACCEPTED
-  REJECTED = PN_REJECTED
-  RELEASED = PN_RELEASED
-  MODIFIED = PN_MODIFIED
+  RECEIVED = DispositionType(PN_RECEIVED, "RECEIVED")
+  ACCEPTED = DispositionType(PN_ACCEPTED, "ACCEPTED")
+  REJECTED = DispositionType(PN_REJECTED, "REJECTED")
+  RELEASED = DispositionType(PN_RELEASED, "RELEASED")
+  MODIFIED = DispositionType(PN_MODIFIED, "MODIFIED")
 
   def __init__(self, impl, local):
     self._impl = impl
@@ -2778,7 +2803,7 @@ class Disposition(object):
 
   @property
   def type(self):
-    return pn_disposition_type(self._impl)
+    return DispositionType.get(pn_disposition_type(self._impl))
 
   def _get_section_number(self):
     return pn_disposition_get_section_number(self._impl)
@@ -2905,11 +2930,11 @@ class Delivery(object):
 
   @property
   def local_state(self):
-    return pn_delivery_local_state(self._dlv)
+    return DispositionType.get(pn_delivery_local_state(self._dlv))
 
   @property
   def remote_state(self):
-    return pn_delivery_remote_state(self._dlv)
+    return DispositionType.get(pn_delivery_remote_state(self._dlv))
 
   @property
   def settled(self):



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message