From 5908d70277bae4bda7f15c5700b836d1d815e53a Mon Sep 17 00:00:00 2001 From: Ramin Yaghoubzadeh <ryaghoub@techfak.uni-bielefeld.de> Date: Thu, 23 Aug 2012 11:29:46 +0200 Subject: [PATCH] Forced automatic conversion to UTF-8 in payload (python) --- ipaacalib/python/build.properties | 1 + ipaacalib/python/src/ipaaca.py | 23 ++++++++++++++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/ipaacalib/python/build.properties b/ipaacalib/python/build.properties index 0ff9423..4327599 100644 --- a/ipaacalib/python/build.properties +++ b/ipaacalib/python/build.properties @@ -6,5 +6,6 @@ pyzip.excludes= run.py=run.py publish.resolver=soa.core.repository dist.dir=../../dist +deps.dir=../../deps extra.python.path=/vol/soa/opt64/python-spread/current/lib/python2.7/site-packages diff --git a/ipaacalib/python/src/ipaaca.py b/ipaacalib/python/src/ipaaca.py index 07010b6..983c9eb 100755 --- a/ipaacalib/python/src/ipaaca.py +++ b/ipaacalib/python/src/ipaaca.py @@ -55,14 +55,14 @@ def enum(*sequential, **named): def pack_typed_payload_item(protobuf_object, key, value): - protobuf_object.key = str(key) - protobuf_object.value = str(value) + protobuf_object.key = key + protobuf_object.value = value protobuf_object.type = 'str' # TODO: more types def unpack_typed_payload_item(protobuf_object): # TODO: more types - return (protobuf_object.key, str(protobuf_object.value)) + return (protobuf_object.key, protobuf_object.value) class IpaacaLoggingHandler(logging.Handler): @@ -131,7 +131,14 @@ class IUNotFoundError(Exception): class Payload(dict): def __init__(self, iu, writer_name=None, new_payload=None, omit_init_update_message=False): - pl = {} if new_payload is None else new_payload + pl1 = {} if new_payload is None else new_payload + pl = {} + for k,v in pl1.items(): + if type(k)==str: + k=unicode(k,'utf8') + if type(v)==str: + v=unicode(v,'utf8') + pl[k] = v self.iu = iu # NOTE omit_init_update_message is necessary to prevent checking for # exceptions and sending updates in the case where we just receive @@ -141,9 +148,15 @@ class Payload(dict): for k, v in pl.items(): dict.__setitem__(self, k, v) def __setitem__(self, k, v, writer_name=None): + if type(k)==str: + k=unicode(k,'utf8') + if type(v)==str: + v=unicode(v,'utf8') self.iu._modify_payload(is_delta=True, new_items={k:v}, keys_to_remove=[], writer_name=writer_name) result = dict.__setitem__(self, k, v) def __delitem__(self, k, writer_name=None): + if type(k)==str: + k=unicode(k,'utf8') self.iu._modify_payload(is_delta=True, new_items={}, keys_to_remove=[k], writer_name=writer_name) result = dict.__delitem__(self, k) def _remotely_enforced_setitem(self, k, v): @@ -179,7 +192,7 @@ class IUInterface(object): #{{{ self._links = collections.defaultdict(set) def __str__(self): - s = str(self.__class__)+"{ " + s = unicode(self.__class__)+"{ " s += "uid="+self._uid+" " s += "(buffer="+(self.buffer.unique_name if self.buffer is not None else "<None>")+") " s += "owner_name=" + ("<None>" if self.owner_name is None else self.owner_name) + " " -- GitLab