diff options
author | Rafael H. Schloming <rhs@apache.org> | 2009-03-06 15:03:00 +0000 |
---|---|---|
committer | Rafael H. Schloming <rhs@apache.org> | 2009-03-06 15:03:00 +0000 |
commit | 46f31b3247d507122eed102bfcc395c18fd0bfa8 (patch) | |
tree | d9ccfd43a25b3a8b56e0c9a6c35f77ca7b23bf77 /python/qpid/codec010.py | |
parent | 963fc80c1de0c8cbc8caff8608c061f578d39866 (diff) | |
download | qpid-python-46f31b3247d507122eed102bfcc395c18fd0bfa8.tar.gz |
codec and unicode tests and fixes
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@750934 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'python/qpid/codec010.py')
-rw-r--r-- | python/qpid/codec010.py | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/python/qpid/codec010.py b/python/qpid/codec010.py index f34025ef17..62b0f6cf2a 100644 --- a/python/qpid/codec010.py +++ b/python/qpid/codec010.py @@ -19,7 +19,7 @@ import datetime from packer import Packer -from datatypes import serial, timestamp, RangedSet, Struct +from datatypes import serial, timestamp, RangedSet, Struct, UUID class CodecException(Exception): pass @@ -131,6 +131,11 @@ class Codec(Packer): def write_str16(self, s): self.write_vbin16(s.encode("utf8")) + def read_str16_latin(self): + return self.read_vbin16().decode("iso-8859-15") + def write_str16_latin(self, s): + self.write_vbin16(s.encode("iso-8859-15")) + def read_vbin16(self): return self.read(self.read_uint16()) @@ -166,7 +171,7 @@ class Codec(Packer): if m is not None: sc.write_uint32(len(m)) for k, v in m.items(): - type = self.spec.encoding(v.__class__) + type = self.spec.encoding(v) if type == None: raise CodecException("no encoding for %s" % v.__class__) sc.write_str8(k) @@ -191,9 +196,9 @@ class Codec(Packer): sc = StringCodec(self.spec) if a is not None: if len(a) > 0: - type = self.spec.encoding(a[0].__class__) + type = self.spec.encoding(a[0]) else: - type = self.spec.encoding(None.__class__) + type = self.spec.encoding(None) sc.write_uint8(type.code) sc.write_uint32(len(a)) for o in a: @@ -216,7 +221,7 @@ class Codec(Packer): if l is not None: sc.write_uint32(len(l)) for o in l: - type = self.spec.encoding(o.__class__) + type = self.spec.encoding(o) sc.write_uint8(type.code) type.encode(sc, o) self.write_vbin32(sc.encoded) @@ -273,9 +278,11 @@ class Codec(Packer): getattr(self, attr)(n) def read_uuid(self): - return self.unpack("16s") + return UUID(self.unpack("16s")) def write_uuid(self, s): + if isinstance(s, UUID): + s = s.bytes self.pack("16s", s) def read_bin128(self): |