You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by kg...@apache.org on 2013/02/20 19:02:00 UTC
svn commit: r1448323 - in /qpid/proton/trunk:
proton-c/bindings/python/proton.py tests/python/proton-test
tests/python/proton_tests/codec.py tests/python/proton_tests/message.py
Author: kgiusti
Date: Wed Feb 20 18:01:59 2013
New Revision: 1448323
URL: http://svn.apache.org/r1448323
Log:
PROTON-199: support python 2.4
Modified:
qpid/proton/trunk/proton-c/bindings/python/proton.py
qpid/proton/trunk/tests/python/proton-test
qpid/proton/trunk/tests/python/proton_tests/codec.py
qpid/proton/trunk/tests/python/proton_tests/message.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=1448323&r1=1448322&r2=1448323&view=diff
==============================================================================
--- qpid/proton/trunk/proton-c/bindings/python/proton.py (original)
+++ qpid/proton/trunk/proton-c/bindings/python/proton.py Wed Feb 20 18:01:59 2013
@@ -31,7 +31,58 @@ The proton APIs consist of the following
"""
from cproton import *
-import uuid
+try:
+ import uuid
+except ImportError:
+ """
+ No 'native' UUID support. Provide a very basic UUID type that is a compatible subset of the uuid type provided by more modern python releases.
+ """
+ import struct
+ class uuid:
+ class UUID:
+ def __init__(self, hex=None, bytes=None):
+ if [hex, bytes].count(None) != 1:
+ raise TypeErrror("need one of hex or bytes")
+ if bytes is not None:
+ self.bytes = bytes
+ elif hex is not None:
+ fields=hex.split("-")
+ fields[4:5] = [fields[4][:4], fields[4][4:]]
+ self.bytes = struct.pack("!LHHHHL", *[int(x,16) for x in fields])
+
+ def __cmp__(self, other):
+ if isinstance(other, uuid.UUID):
+ return cmp(self.bytes, other.bytes)
+ else:
+ return -1
+
+ def __str__(self):
+ return "%08x-%04x-%04x-%04x-%04x%08x" % struct.unpack("!LHHHHL", self.bytes)
+
+ def __repr__(self):
+ return "UUID(%r)" % str(self)
+
+ def __hash__(self):
+ return self.bytes.__hash__()
+
+ import os, random, socket, time
+ rand = random.Random()
+ rand.seed((os.getpid(), time.time(), socket.gethostname()))
+ def random_uuid():
+ bytes = [rand.randint(0, 255) for i in xrange(16)]
+
+ # From RFC4122, the version bits are set to 0100
+ bytes[7] &= 0x0F
+ bytes[7] |= 0x40
+
+ # From RFC4122, the top two bits of byte 8 get set to 01
+ bytes[8] &= 0x3F
+ bytes[8] |= 0x80
+ return "".join(map(chr, bytes))
+
+ def uuid4():
+ return uuid.UUID(bytes=random_uuid())
+
try:
bytes()
except NameError:
Modified: qpid/proton/trunk/tests/python/proton-test
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/tests/python/proton-test?rev=1448323&r1=1448322&r2=1448323&view=diff
==============================================================================
--- qpid/proton/trunk/tests/python/proton-test (original)
+++ qpid/proton/trunk/tests/python/proton-test Wed Feb 20 18:01:59 2013
@@ -367,10 +367,16 @@ class Runner:
return output
def get_exception_type(self):
- return self.exception[0] if self.exception else None
+ if self.exception:
+ return self.exception[0]
+ else:
+ return None
def get_exception_message(self):
- return self.exception[1] if self.exception else None
+ if self.exception:
+ return self.exception[1]
+ else:
+ return None
ST_WIDTH = 8
Modified: qpid/proton/trunk/tests/python/proton_tests/codec.py
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/tests/python/proton_tests/codec.py?rev=1448323&r1=1448322&r2=1448323&view=diff
==============================================================================
--- qpid/proton/trunk/tests/python/proton_tests/codec.py (original)
+++ qpid/proton/trunk/tests/python/proton_tests/codec.py Wed Feb 20 18:01:59 2013
@@ -19,7 +19,11 @@
import os, common
from proton import *
-from uuid import uuid3, NAMESPACE_OID
+try:
+ from uuid import uuid4
+except ImportError:
+ from proton import uuid4
+
class Test(common.Test):
@@ -163,9 +167,7 @@ class DataTest(Test):
self._testArray(None, None, "int", 1, 2, 3)
def testUUIDArray(self):
- self._testArray(None, None, "uuid", uuid3(NAMESPACE_OID, "one"),
- uuid3(NAMESPACE_OID, "one"),
- uuid3(NAMESPACE_OID, "three"))
+ self._testArray(None, None, "uuid", uuid4(), uuid4(), uuid4())
def testEmptyArray(self):
self._testArray(None, None, "null")
@@ -236,8 +238,7 @@ class DataTest(Test):
self._test("char", 'a', 'b', 'c', u'\u1234')
def testUUID(self):
- self._test("uuid", uuid3(NAMESPACE_OID, "test1"), uuid3(NAMESPACE_OID, "test2"),
- uuid3(NAMESPACE_OID, "test3"))
+ self._test("uuid", uuid4(), uuid4(), uuid4())
def testDecimal32(self):
self._test("decimal32", 0, 1, 2, 3, 4, 2**30)
Modified: qpid/proton/trunk/tests/python/proton_tests/message.py
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/tests/python/proton_tests/message.py?rev=1448323&r1=1448322&r2=1448323&view=diff
==============================================================================
--- qpid/proton/trunk/tests/python/proton_tests/message.py (original)
+++ qpid/proton/trunk/tests/python/proton_tests/message.py Wed Feb 20 18:01:59 2013
@@ -19,7 +19,10 @@
import os, common
from proton import *
-from uuid import uuid3, NAMESPACE_OID
+try:
+ from uuid import uuid4
+except ImportError:
+ from proton import uuid4
class Test(common.Test):
@@ -47,10 +50,10 @@ class AccessorsTest(Test):
self._test(name, 0, (0, 123456789, 987654321))
def testId(self):
- self._test("id", None, ("bytes", None, 123, u"string", uuid3(NAMESPACE_OID, "blah")))
+ self._test("id", None, ("bytes", None, 123, u"string", uuid4()))
def testCorrelationId(self):
- self._test("correlation_id", None, ("bytes", None, 123, u"string", uuid3(NAMESPACE_OID, "blah")))
+ self._test("correlation_id", None, ("bytes", None, 123, u"string", uuid4()))
def testDurable(self):
self._test("durable", False, (True, False))
@@ -104,7 +107,7 @@ class CodecTest(Test):
def testRoundTrip(self):
self.msg.id = "asdf"
- self.msg.correlation_id = uuid3(NAMESPACE_OID, "bleh")
+ self.msg.correlation_id = uuid4()
self.msg.ttl = 3
self.msg.priority = 100
self.msg.address = "address"
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org