]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
remove upload.upload_(data,filename,filehandle) convenience functions
authorBrian Warner <warner@allmydata.com>
Thu, 31 Jan 2008 02:03:19 +0000 (19:03 -0700)
committerBrian Warner <warner@allmydata.com>
Thu, 31 Jan 2008 02:03:19 +0000 (19:03 -0700)
src/allmydata/control.py
src/allmydata/test/test_helper.py
src/allmydata/test/test_upload.py
src/allmydata/upload.py

index 2fc3afc3887db54e2014819b94d4196e1300c254..2428948b92543751cb5ef5725ada8ddac3ee397f 100644 (file)
@@ -44,7 +44,8 @@ class ControlServer(Referenceable, service.Service, testutil.PollMixin):
 
     def remote_upload_from_file_to_uri(self, filename):
         uploader = self.parent.getServiceNamed("uploader")
-        d = uploader.upload_filename(filename)
+        u = upload.FileName(filename)
+        d = uploader.upload(u)
         return d
 
     def remote_download_from_uri_to_file(self, uri, filename):
index cf766ac732605a9e66ba6c03018884ade9cbabed..6fa96585d347e2b121abfea0966a69031b6de4a3 100644 (file)
@@ -53,6 +53,10 @@ def flush_but_dont_ignore(res):
     d.addCallback(_done)
     return d
 
+def upload_data(uploader, data):
+    u = upload.Data(data)
+    return uploader.upload(u)
+
 class AssistedUpload(unittest.TestCase):
     def setUp(self):
         self.s = FakeClient()
@@ -94,7 +98,7 @@ class AssistedUpload(unittest.TestCase):
             assert u._helper
 
             DATA = "I need help\n" * 1000
-            return u.upload_data(DATA)
+            return upload_data(u, DATA)
         d.addCallback(_ready)
         def _uploaded(uri):
             assert "CHK" in uri
@@ -137,7 +141,7 @@ class AssistedUpload(unittest.TestCase):
 
         def _ready(res):
             assert u._helper
-            return u.upload_data(DATA)
+            return upload_data(u, DATA)
         d.addCallback(_ready)
         def _uploaded(uri):
             assert "CHK" in uri
@@ -168,7 +172,7 @@ class AssistedUpload(unittest.TestCase):
             assert u._helper
 
             DATA = "I need help\n" * 1000
-            return u.upload_data(DATA)
+            return upload_data(u, DATA)
         d.addCallback(_ready)
         def _uploaded(uri):
             assert "CHK" in uri
index 52d84863b5569ad9065afe2ebc9f284e77dbc194..c402d08a2d5ec6d032f0399573dd4a73cec1d958 100644 (file)
@@ -181,6 +181,16 @@ SIZE_ZERO = 0
 SIZE_SMALL = 16
 SIZE_LARGE = len(DATA)
 
+def upload_data(uploader, data):
+    u = upload.Data(data)
+    return uploader.upload(u)
+def upload_filename(uploader, filename):
+    u = upload.FileName(filename)
+    return uploader.upload(u)
+def upload_filehandle(uploader, fh):
+    u = upload.FileHandle(fh)
+    return uploader.upload(u)
+
 class GoodServer(unittest.TestCase):
     def setUp(self):
         self.node = FakeClient(mode="good")
@@ -215,19 +225,19 @@ class GoodServer(unittest.TestCase):
 
     def test_data_zero(self):
         data = self.get_data(SIZE_ZERO)
-        d = self.u.upload_data(data)
+        d = upload_data(self.u, data)
         d.addCallback(self._check_small, SIZE_ZERO)
         return d
 
     def test_data_small(self):
         data = self.get_data(SIZE_SMALL)
-        d = self.u.upload_data(data)
+        d = upload_data(self.u, data)
         d.addCallback(self._check_small, SIZE_SMALL)
         return d
 
     def test_data_large(self):
         data = self.get_data(SIZE_LARGE)
-        d = self.u.upload_data(data)
+        d = upload_data(self.u, data)
         d.addCallback(self._check_large, SIZE_LARGE)
         return d
 
@@ -236,25 +246,25 @@ class GoodServer(unittest.TestCase):
         segsize = int(SIZE_LARGE / 2.5)
         # we want 3 segments, since that's not a power of two
         self.set_encoding_parameters(25, 75, 100, segsize)
-        d = self.u.upload_data(data)
+        d = upload_data(self.u, data)
         d.addCallback(self._check_large, SIZE_LARGE)
         return d
 
     def test_filehandle_zero(self):
         data = self.get_data(SIZE_ZERO)
-        d = self.u.upload_filehandle(StringIO(data))
+        d = upload_filehandle(self.u, StringIO(data))
         d.addCallback(self._check_small, SIZE_ZERO)
         return d
 
     def test_filehandle_small(self):
         data = self.get_data(SIZE_SMALL)
-        d = self.u.upload_filehandle(StringIO(data))
+        d = upload_filehandle(self.u, StringIO(data))
         d.addCallback(self._check_small, SIZE_SMALL)
         return d
 
     def test_filehandle_large(self):
         data = self.get_data(SIZE_LARGE)
-        d = self.u.upload_filehandle(StringIO(data))
+        d = upload_filehandle(self.u, StringIO(data))
         d.addCallback(self._check_large, SIZE_LARGE)
         return d
 
@@ -264,7 +274,7 @@ class GoodServer(unittest.TestCase):
         data = self.get_data(SIZE_ZERO)
         f.write(data)
         f.close()
-        d = self.u.upload_filename(fn)
+        d = upload_filename(self.u, fn)
         d.addCallback(self._check_small, SIZE_ZERO)
         return d
 
@@ -274,7 +284,7 @@ class GoodServer(unittest.TestCase):
         data = self.get_data(SIZE_SMALL)
         f.write(data)
         f.close()
-        d = self.u.upload_filename(fn)
+        d = upload_filename(self.u, fn)
         d.addCallback(self._check_small, SIZE_SMALL)
         return d
 
@@ -284,7 +294,7 @@ class GoodServer(unittest.TestCase):
         data = self.get_data(SIZE_LARGE)
         f.write(data)
         f.close()
-        d = self.u.upload_filename(fn)
+        d = upload_filename(self.u, fn)
         d.addCallback(self._check_large, SIZE_LARGE)
         return d
 
@@ -300,7 +310,7 @@ class FullServer(unittest.TestCase):
 
     def test_data_large(self):
         data = DATA
-        d = self.u.upload_data(data)
+        d = upload_data(self.u, data)
         d.addBoth(self._should_fail)
         return d
 
@@ -339,7 +349,7 @@ class PeerSelection(unittest.TestCase):
         self.make_client()
         data = self.get_data(SIZE_LARGE)
         self.set_encoding_parameters(25, 30, 50)
-        d = self.u.upload_data(data)
+        d = upload_data(self.u, data)
         d.addCallback(self._check_large, SIZE_LARGE)
         def _check(res):
             for p in self.node.last_peers:
@@ -356,7 +366,7 @@ class PeerSelection(unittest.TestCase):
         self.make_client()
         data = self.get_data(SIZE_LARGE)
         self.set_encoding_parameters(50, 75, 100)
-        d = self.u.upload_data(data)
+        d = upload_data(self.u, data)
         d.addCallback(self._check_large, SIZE_LARGE)
         def _check(res):
             for p in self.node.last_peers:
@@ -373,7 +383,7 @@ class PeerSelection(unittest.TestCase):
         self.make_client()
         data = self.get_data(SIZE_LARGE)
         self.set_encoding_parameters(24, 41, 51)
-        d = self.u.upload_data(data)
+        d = upload_data(self.u, data)
         d.addCallback(self._check_large, SIZE_LARGE)
         def _check(res):
             got_one = []
@@ -400,7 +410,7 @@ class PeerSelection(unittest.TestCase):
         self.make_client()
         data = self.get_data(SIZE_LARGE)
         self.set_encoding_parameters(100, 150, 200)
-        d = self.u.upload_data(data)
+        d = upload_data(self.u, data)
         d.addCallback(self._check_large, SIZE_LARGE)
         def _check(res):
             for p in self.node.last_peers:
@@ -417,7 +427,7 @@ class PeerSelection(unittest.TestCase):
         self.make_client(3)
         data = self.get_data(SIZE_LARGE)
         self.set_encoding_parameters(3, 5, 10)
-        d = self.u.upload_data(data)
+        d = upload_data(self.u, data)
         d.addCallback(self._check_large, SIZE_LARGE)
         def _check(res):
             counts = {}
index 9837f62a87fed4959e42364c7c4289637bd81f27..7a9d0b347ca821b084ac2dd45968b9b509ee7946 100644 (file)
@@ -973,11 +973,3 @@ class Uploader(service.MultiService):
             return res
         d.addBoth(_done)
         return d
-
-    # utility functions
-    def upload_data(self, data, contenthashkey=True):
-        return self.upload(Data(data, contenthashkey=contenthashkey))
-    def upload_filename(self, filename, contenthashkey=True):
-        return self.upload(FileName(filename, contenthashkey=contenthashkey))
-    def upload_filehandle(self, filehandle, contenthashkey=True):
-        return self.upload(FileHandle(filehandle, contenthashkey=contenthashkey))