]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
change uri-packer-unpacker to deal with dictionaries, not fragile tuples
authorBrian Warner <warner@allmydata.com>
Wed, 23 May 2007 18:18:49 +0000 (11:18 -0700)
committerBrian Warner <warner@allmydata.com>
Wed, 23 May 2007 18:18:49 +0000 (11:18 -0700)
src/allmydata/download.py
src/allmydata/test/test_system.py
src/allmydata/test/test_upload.py
src/allmydata/uri.py
src/allmydata/webish.py

index 656c8ecbcdb270fbc49895ecc67ce9506b0badd2..02b79547c40e8f8b921ab9c5444d089c9ebabe44 100644 (file)
@@ -214,17 +214,21 @@ class FileDownloader:
     def __init__(self, client, uri, downloadable):
         self._client = client
         self._downloadable = downloadable
-        (codec_name, codec_params, tail_codec_params, verifierid, fileid, key, roothash, needed_shares, total_shares, size, segment_size) = unpack_uri(uri)
+
+        d = unpack_uri(uri)
+        verifierid = d['verifierid']
+        size = d['size']
+        segment_size = d['segment_size']
         assert isinstance(verifierid, str)
         assert len(verifierid) == 20
         self._verifierid = verifierid
-        self._fileid = fileid
-        self._roothash = roothash
+        self._fileid = d['fileid']
+        self._roothash = d['roothash']
 
-        self._codec = codec.get_decoder_by_name(codec_name)
-        self._codec.set_serialized_params(codec_params)
-        self._tail_codec = codec.get_decoder_by_name(codec_name)
-        self._tail_codec.set_serialized_params(tail_codec_params)
+        self._codec = codec.get_decoder_by_name(d['codec_name'])
+        self._codec.set_serialized_params(d['codec_params'])
+        self._tail_codec = codec.get_decoder_by_name(d['codec_name'])
+        self._tail_codec.set_serialized_params(d['tail_codec_params'])
 
 
         self._total_segments = mathutil.div_ceil(size, segment_size)
@@ -233,10 +237,10 @@ class FileDownloader:
         self._size = size
         self._num_needed_shares = self._codec.get_needed_shares()
 
-        self._output = Output(downloadable, key)
+        self._output = Output(downloadable, d['key'])
 
-        self._share_hashtree = hashtree.IncompleteHashTree(total_shares)
-        self._share_hashtree.set_hashes({0: roothash})
+        self._share_hashtree = hashtree.IncompleteHashTree(d['total_shares'])
+        self._share_hashtree.set_hashes({0: self._roothash})
 
         self.active_buckets = {} # k: shnum, v: bucket
         self._share_buckets = {} # k: shnum, v: set of buckets
index e692c7713a6d28914ce9921fdb6126fbf16a4ad4..81aa91bc2f80e98ff828c3c8081fb54b1954dfdf 100644 (file)
@@ -212,11 +212,10 @@ class SystemTest(testutil.SignalMixin, unittest.TestCase):
     def mangle_uri(self, gooduri):
         # change the verifierid, which means we'll be asking about the wrong
         # file, so nobody will have any shares
-        pieces = list(uri.unpack_uri(gooduri))
-        # [3] is the verifierid
-        assert len(pieces[3]) == 20
-        pieces[3] = self.flip_bit(pieces[3])
-        return uri.pack_uri(*pieces)
+        d = uri.unpack_uri(gooduri)
+        assert len(d['verifierid']) == 20
+        d['verifierid'] = self.flip_bit(d['verifierid'])
+        return uri.pack_uri(**d)
 
     # TODO: add a test which mangles the fileid instead, and should fail in
     # the post-download phase when the file's integrity check fails. Do the
index 383462ae3f1c551e15a88884fa9de23fa492d644..efae86d48763fa431d7ff34708a732b9ebee6065 100644 (file)
@@ -24,14 +24,14 @@ class GoodServer(unittest.TestCase):
     def _check(self, uri):
         self.failUnless(isinstance(uri, str))
         self.failUnless(uri.startswith("URI:"))
-        codec_name, codec_params, tail_codec_params, verifierid, fileid, key, roothash, needed_shares, total_shares, size, segment_size = unpack_uri(uri)
-        self.failUnless(isinstance(verifierid, str))
-        self.failUnlessEqual(len(verifierid), 20)
-        self.failUnless(isinstance(fileid, str))
-        self.failUnlessEqual(len(fileid), 20)
-        self.failUnless(isinstance(key, str))
-        self.failUnlessEqual(len(key), 16)
-        self.failUnless(isinstance(codec_params, str))
+        d = unpack_uri(uri)
+        self.failUnless(isinstance(d['verifierid'], str))
+        self.failUnlessEqual(len(d['verifierid']), 20)
+        self.failUnless(isinstance(d['fileid'], str))
+        self.failUnlessEqual(len(d['fileid']), 20)
+        self.failUnless(isinstance(d['key'], str))
+        self.failUnlessEqual(len(d['key']), 16)
+        self.failUnless(isinstance(d['codec_params'], str))
 
     def testData(self):
         data = "This is some data to upload"
index 356e409bfed9ac95f783c80665f6741810009c22..96fca1da4281d25fea7c9a3199dfaf4910fa9981 100644 (file)
@@ -8,6 +8,7 @@ from allmydata.util import idlib
 def pack_uri(codec_name, codec_params, tail_codec_params,
              verifierid, fileid, key,
              roothash, needed_shares, total_shares, size, segment_size):
+    # applications should pass keyword parameters into this
     assert isinstance(codec_name, str)
     assert len(codec_name) < 10
     assert ":" not in codec_name
@@ -26,15 +27,17 @@ def pack_uri(codec_name, codec_params, tail_codec_params,
 
 def unpack_uri(uri):
     assert uri.startswith("URI:")
-    header, codec_name, codec_params, tail_codec_params, verifierid_s, fileid_s, key_s, roothash_s, needed_shares_s, total_shares_s, size_s, segment_size_s = uri.split(":")
-    verifierid = idlib.a2b(verifierid_s)
-    fileid = idlib.a2b(fileid_s)
-    key = idlib.a2b(key_s)
-    roothash = idlib.a2b(roothash_s)
-    needed_shares = int(needed_shares_s)
-    total_shares = int(total_shares_s)
-    size = int(size_s)
-    segment_size = int(segment_size_s)
-    return codec_name, codec_params, tail_codec_params, verifierid, fileid, key, roothash, needed_shares, total_shares, size, segment_size
+    d = {}
+    header, d['codec_name'], d['codec_params'], d['tail_codec_params'], verifierid_s, fileid_s, key_s, roothash_s, needed_shares_s, total_shares_s, size_s, segment_size_s = uri.split(":")
+    assert header == "URI"
+    d['verifierid'] = idlib.a2b(verifierid_s)
+    d['fileid'] = idlib.a2b(fileid_s)
+    d['key'] = idlib.a2b(key_s)
+    d['roothash'] = idlib.a2b(roothash_s)
+    d['needed_shares'] = int(needed_shares_s)
+    d['total_shares'] = int(total_shares_s)
+    d['size'] = int(size_s)
+    d['segment_size'] = int(segment_size_s)
+    return d
 
 
index 5275b0deeeacd82e644027acb90e68a9669801da..687d63bff2f1fa454e5b21a15104e75844609a9f 100644 (file)
@@ -128,8 +128,7 @@ class Directory(rend.Page):
             ctx.fillSlots("uri", T.a(href=dl_uri_url)[html.escape(uri)])
 
             #extract and display file size
-            unpacked = unpack_uri(uri)
-            ctx.fillSlots("size", unpacked[9])
+            ctx.fillSlots("size", unpack_uri(uri)['size'])
 
             # this creates a button which will cause our child__delete method
             # to be invoked, which deletes the file and then redirects the