From 46f31b3247d507122eed102bfcc395c18fd0bfa8 Mon Sep 17 00:00:00 2001 From: "Rafael H. Schloming" Date: Fri, 6 Mar 2009 15:03:00 +0000 Subject: codec and unicode tests and fixes git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@750934 13f79535-47bb-0310-9956-ffa450edef68 --- python/qpid/spec010.py | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) (limited to 'python/qpid/spec010.py') 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 -- cgit v1.2.1