From e679d486605944e93b0d0f78581c23cab148476b Mon Sep 17 00:00:00 2001 From: robk-tahoe Date: Thu, 16 Oct 2008 19:59:31 -0700 Subject: [PATCH] fuse/blackmatch: update json handling to support simplejson v2 simplejson v2 returns strings as either unicode or str, depending upon its mood. thus the interpretation of the node's json repr of a directory, and the serialisation of strings in the json based rpc both exploded when built against simplejson v2. this makes both of these places liberal in their acceptance of either str or unicode. --- contrib/fuse/impl_c/blackmatch.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/contrib/fuse/impl_c/blackmatch.py b/contrib/fuse/impl_c/blackmatch.py index b167c713..322df4e2 100644 --- a/contrib/fuse/impl_c/blackmatch.py +++ b/contrib/fuse/impl_c/blackmatch.py @@ -105,9 +105,12 @@ def log(msg): fuse.flog = log -def unicode_to_utf8(u): - precondition(isinstance(u, unicode), repr(u)) - return u.encode('utf-8') +def unicode_to_utf8_or_str(u): + if isinstance(u, unicode): + return u.encode('utf-8') + else: + precondition(isinstance(u, str), repr(u)) + return u def do_http(method, url, body=''): resp = do_http_req(method, url, body) @@ -834,7 +837,7 @@ class Directory(object): assert nodetype == 'dirnode' self.children.clear() for cname,details in d['children'].items(): - cname = unicode_to_utf8(cname) + cname = unicode_to_utf8_or_str(cname) ctype, cattrs = details metadata = cattrs.get('metadata', {}) if ctype == 'dirnode': @@ -1142,7 +1145,7 @@ def print_tree(): def unmarshal(obj): if obj is None or isinstance(obj, int) or isinstance(obj, long) or isinstance(obj, float): return obj - elif isinstance(obj, unicode): + elif isinstance(obj, unicode) or isinstance(obj, str): #log('unmarshal(%r)' % (obj,)) return base64.b64decode(obj) elif isinstance(obj, list): -- 2.45.2