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/spec010.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/spec010.py')
-rw-r--r-- | python/qpid/spec010.py | 40 |
1 files changed, 27 insertions, 13 deletions
diff --git a/python/qpid/spec010.py b/python/qpid/spec010.py index cbc85a5e8b..9a88b88169 100644 --- a/python/qpid/spec010.py +++ b/python/qpid/spec010.py @@ -467,19 +467,30 @@ class Exception(Named, Node): node.exceptions.append(self) Node.register(self) +def direct(t): + return lambda x: t + +def map_str(s): + for c in s: + if ord(c) >= 0x80: + return "vbin16" + return "str16_latin" + class Spec(Node): ENCODINGS = { - basestring: "vbin16", - int: "int64", - long: "int64", - float: "float", - None.__class__: "void", - list: "list", - tuple: "list", - dict: "map", - datatypes.timestamp: "datetime", - datetime.datetime: "datetime" + unicode: direct("str16"), + str: map_str, + int: direct("int64"), + long: direct("int64"), + float: direct("float"), + None.__class__: direct("void"), + list: direct("list"), + tuple: direct("list"), + dict: direct("map"), + datatypes.timestamp: direct("datetime"), + datetime.datetime: direct("datetime"), + datatypes.UUID: direct("uuid") } def __init__(self, major, minor, port, children): @@ -500,11 +511,14 @@ class Spec(Node): self.structs_by_name = {} self.enums = {} - def encoding(self, klass): + def encoding(self, obj): + return self._encoding(obj.__class__, obj) + + def _encoding(self, klass, obj): if Spec.ENCODINGS.has_key(klass): - return self.named[Spec.ENCODINGS[klass]] + return self.named[Spec.ENCODINGS[klass](obj)] for base in klass.__bases__: - result = self.encoding(base) + result = self._encoding(base, obj) if result != None: return result |