]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
tolerate simplejson-2.0.0 and newer, which frequently return bytestrings instead...
authorBrian Warner <warner@allmydata.com>
Tue, 30 Sep 2008 22:21:06 +0000 (15:21 -0700)
committerBrian Warner <warner@allmydata.com>
Tue, 30 Sep 2008 22:21:06 +0000 (15:21 -0700)
src/allmydata/scripts/tahoe_cp.py
src/allmydata/scripts/tahoe_ls.py
src/allmydata/scripts/tahoe_mv.py
src/allmydata/test/check_load.py
src/allmydata/test/test_web.py
src/allmydata/web/directory.py

index 32e0ca9e518382f28726cb6dc0e26ffe3ad4405e..91cc1ea2827668fc1754941368d922e23b0b8941 100644 (file)
@@ -222,7 +222,9 @@ class TahoeDirectorySource:
         nodetype, d = parsed
         assert nodetype == "dirnode"
         self.mutable = d.get("mutable", False) # older nodes don't provide it
-        self.children_d = d["children"]
+        self.children_d = dict( [(unicode(name),value)
+                                 for (name,value)
+                                 in d["children"].iteritems()] )
         self.children = None
 
     def init_from_parsed(self, parsed):
@@ -230,7 +232,9 @@ class TahoeDirectorySource:
         self.writecap = ascii_or_none(d.get("rw_uri"))
         self.readcap = ascii_or_none(d.get("ro_uri"))
         self.mutable = d.get("mutable", False) # older nodes don't provide it
-        self.children_d = d["children"]
+        self.children_d = dict( [(unicode(name),value)
+                                 for (name,value)
+                                 in d["children"].iteritems()] )
         self.children = None
 
     def populate(self, recurse):
@@ -294,7 +298,9 @@ class TahoeDirectoryTarget:
         self.writecap = ascii_or_none(d.get("rw_uri"))
         self.readcap = ascii_or_none(d.get("ro_uri"))
         self.mutable = d.get("mutable", False) # older nodes don't provide it
-        self.children_d = d["children"]
+        self.children_d = dict( [(unicode(name),value)
+                                 for (name,value)
+                                 in d["children"].iteritems()] )
         self.children = None
 
     def init_from_grid(self, writecap, readcap):
@@ -308,7 +314,9 @@ class TahoeDirectoryTarget:
         nodetype, d = parsed
         assert nodetype == "dirnode"
         self.mutable = d.get("mutable", False) # older nodes don't provide it
-        self.children_d = d["children"]
+        self.children_d = dict( [(unicode(name),value)
+                                 for (name,value)
+                                 in d["children"].iteritems()] )
         self.children = None
 
     def just_created(self, writecap):
index 39d6d49b0b310723435c8feb4d175c1c0b49d4fc..d0d63799be51696a188581e7453bcd637aadb12f 100644 (file)
@@ -53,6 +53,7 @@ def list(options):
     rows = []
 
     for name in childnames:
+        name = unicode(name)
         child = children[name]
         childtype = child[0]
         ctime = child[1]["metadata"].get("ctime")
index c06631f970d1a8e3cf48ed6c0c5be8b0608cbb89..6889032e9c2a33544fd465abf02d20a8ef0f7f4d 100644 (file)
@@ -25,8 +25,8 @@ def mv(options, mode="move"):
     data = urllib.urlopen(from_url + "?t=json").read()
     nodetype, attrs = simplejson.loads(data)
     cap = attrs.get("rw_uri") or attrs["ro_uri"]
-    # simplejson always returns unicode, but we know that it's really just an
-    # ASCII file-cap.
+    # simplejson sometimes returns unicode, but we know that it's really just
+    # an ASCII file-cap.
     cap = str(cap)
 
     # now get the target
index 5515dde8196d5f7b3b383bef9c85898ed301d376..6b4d2cd5f7d0bc8a54889bafd1f91c2033073a7a 100644 (file)
@@ -115,7 +115,10 @@ def listdir(nodeurl, root, vdrive_pathname):
     assert nodetype == "dirnode"
     global directories_read
     directories_read += 1
-    return d['children']
+    children = dict( [(unicode(name),value)
+                      for (name,value)
+                      in d["children"].iteritems()] )
+    return children
 
 
 def choose_random_descendant(server_url, root, pathname=""):
index 365b5de969fdba27f56d36ec1c18086d2809f9ea..93d7ce38a4fa5e1040fe0e2878e15e4209c88aa6 100644 (file)
@@ -197,7 +197,7 @@ class WebMixin(object):
     def failUnlessIsBarJSON(self, res):
         data = simplejson.loads(res)
         self.failUnless(isinstance(data, list))
-        self.failUnlessEqual(data[0], "filenode")
+        self.failUnlessEqual(data[0], u"filenode")
         self.failUnless(isinstance(data[1], dict))
         self.failIf(data[1]["mutable"])
         self.failIf("rw_uri" in data[1]) # immutable
@@ -214,11 +214,13 @@ class WebMixin(object):
         self.failUnlessEqual(data[1]["rw_uri"], self._foo_uri)
         self.failUnlessEqual(data[1]["ro_uri"], self._foo_readonly_uri)
 
-        kidnames = sorted(data[1]["children"])
+        kidnames = sorted([unicode(n) for n in data[1]["children"]])
         self.failUnlessEqual(kidnames,
                              [u"bar.txt", u"blockingfile", u"empty",
                               u"n\u00fc.txt", u"sub"])
-        kids = data[1]["children"]
+        kids = dict( [(unicode(name),value)
+                      for (name,value)
+                      in data[1]["children"].iteritems()] )
         self.failUnlessEqual(kids[u"sub"][0], "dirnode")
         self.failUnless("metadata" in kids[u"sub"][1])
         self.failUnless("ctime" in kids[u"sub"][1]["metadata"])
@@ -1226,7 +1228,9 @@ class Web(WebMixin, unittest.TestCase):
         def _check_page_json(res):
             parsed = simplejson.loads(res)
             self.failUnlessEqual(parsed[0], "dirnode")
-            children = parsed[1]["children"]
+            children = dict( [(unicode(name),value)
+                              for (name,value)
+                              in parsed[1]["children"].iteritems()] )
             self.failUnless("new.txt" in children)
             new_json = children["new.txt"]
             self.failUnlessEqual(new_json[0], "filenode")
index 5990570acbc0310bddffe9a56a7eb2dd028470b8..f6b8055ef6760b860a50952dcfc6f83b0ef6059b 100644 (file)
@@ -372,6 +372,7 @@ class DirectoryNodeHandler(RenderMixin, rend.Page, ReplaceMeMixin):
             raise
         cs = []
         for name, (file_or_dir, mddict) in children.iteritems():
+            name = unicode(name) # simplejson-2.0.1 returns str *or* unicode
             cap = str(mddict.get('rw_uri') or mddict.get('ro_uri'))
             cs.append((name, cap, mddict.get('metadata')))
         d = self.node.set_children(cs, replace)