You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by rh...@apache.org on 2008/05/23 22:22:14 UTC
svn commit: r659647 - in /incubator/qpid/trunk/qpid/python: qpid/codec010.py
qpid/datatypes.py qpid/session.py tests/datatypes.py
Author: rhs
Date: Fri May 23 13:22:13 2008
New Revision: 659647
URL: http://svn.apache.org/viewvc?rev=659647&view=rev
Log:
QPID-947: Switched over to using proper RFC 1982 serial numbers.
Modified:
incubator/qpid/trunk/qpid/python/qpid/codec010.py
incubator/qpid/trunk/qpid/python/qpid/datatypes.py
incubator/qpid/trunk/qpid/python/qpid/session.py
incubator/qpid/trunk/qpid/python/tests/datatypes.py
Modified: incubator/qpid/trunk/qpid/python/qpid/codec010.py
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/python/qpid/codec010.py?rev=659647&r1=659646&r2=659647&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/python/qpid/codec010.py (original)
+++ incubator/qpid/trunk/qpid/python/qpid/codec010.py Fri May 23 13:22:13 2008
@@ -18,7 +18,7 @@
#
from packer import Packer
-from datatypes import RangedSet, Struct
+from datatypes import serial, RangedSet, Struct
class CodecException(Exception): pass
@@ -87,9 +87,9 @@
self.pack("!f", f)
def read_sequence_no(self):
- return self.read_uint32()
+ return serial(self.read_uint32())
def write_sequence_no(self, n):
- self.write_uint32(n)
+ self.write_uint32(n.value)
def read_uint64(self):
Modified: incubator/qpid/trunk/qpid/python/qpid/datatypes.py
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/python/qpid/datatypes.py?rev=659647&r1=659646&r2=659647&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/python/qpid/datatypes.py (original)
+++ incubator/qpid/trunk/qpid/python/qpid/datatypes.py Fri May 23 13:22:13 2008
@@ -116,14 +116,55 @@
args.append("id=%s" % self.id)
return "Message(%s)" % ", ".join(args)
+def serial(o):
+ if isinstance(o, Serial):
+ return o
+ else:
+ return Serial(o)
+
+class Serial:
+
+ def __init__(self, value):
+ self.value = value & 0xFFFFFFFF
+
+ def __hash__(self):
+ return hash(self.value)
+
+ def __cmp__(self, other):
+ if other is None:
+ return 1
+
+ other = serial(other)
+
+ delta = (self.value - other.value) & 0xFFFFFFFF
+ neg = delta & 0x80000000
+ mag = delta & 0x7FFFFFFF
+
+ if neg:
+ return -mag
+ else:
+ return mag
+
+ def __add__(self, other):
+ return Serial(self.value + other)
+
+ def __sub__(self, other):
+ return Serial(self.value - other)
+
+ def __repr__(self):
+ return "serial(%s)" % self.value
+
+ def __str__(self):
+ return str(self.value)
+
class Range:
def __init__(self, lower, upper = None):
- self.lower = lower
+ self.lower = serial(lower)
if upper is None:
- self.upper = lower
+ self.upper = self.lower
else:
- self.upper = upper
+ self.upper = serial(upper)
def __contains__(self, n):
return self.lower <= n and n <= self.upper
Modified: incubator/qpid/trunk/qpid/python/qpid/session.py
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/python/qpid/session.py?rev=659647&r1=659646&r2=659647&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/python/qpid/session.py (original)
+++ incubator/qpid/trunk/qpid/python/qpid/session.py Fri May 23 13:22:13 2008
@@ -23,7 +23,7 @@
from codec010 import StringCodec
from assembler import Segment
from queue import Queue
-from datatypes import Message
+from datatypes import Message, serial
from util import wait, notify
from exceptions import *
from logging import getLogger
@@ -304,7 +304,7 @@
def __init__(self, session):
self.session = session
- self.next_id = 0
+ self.next_id = serial(0)
self.next_offset = 0
self.segments = []
self._completed = RangedSet()
Modified: incubator/qpid/trunk/qpid/python/tests/datatypes.py
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/python/tests/datatypes.py?rev=659647&r1=659646&r2=659647&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/python/tests/datatypes.py (original)
+++ incubator/qpid/trunk/qpid/python/tests/datatypes.py Fri May 23 13:22:13 2008
@@ -22,6 +22,39 @@
from qpid.spec010 import load
from qpid.datatypes import *
+class SerialTest(TestCase):
+
+ def test(self):
+ for s in (serial(0), serial(0x8FFFFFFF), serial(0xFFFFFFFF)):
+ assert s + 1 > s
+ assert s - 1 < s
+ assert s < s + 1
+ assert s > s - 1
+
+ assert serial(0xFFFFFFFF) + 1 == serial(0)
+
+ assert min(serial(0xFFFFFFFF), serial(0x0)) == serial(0xFFFFFFFF)
+ assert max(serial(0xFFFFFFFF), serial(0x0)) == serial(0x0)
+
+ def testIncr(self):
+ s = serial(0)
+ s += 1
+ assert s == serial(1)
+
+ def testIn(self):
+ l = [serial(1), serial(2), serial(3), serial(4)]
+ assert serial(1) in l
+ assert serial(0xFFFFFFFF + 2) in l
+ assert 4 in l
+
+ def testNone(self):
+ assert serial(0) != None
+
+ def testHash(self):
+ d = {}
+ d[serial(0)] = "zero"
+ assert d[0] == "zero"
+
class RangedSetTest(TestCase):
def check(self, ranges):