]> git.mxchange.org Git - quix0rs-apt-p2p.git/commitdiff
Make better use of defer.Fail for returning deferred errors.
authorCameron Dale <camrdale@gmail.com>
Tue, 15 Apr 2008 23:07:05 +0000 (16:07 -0700)
committerCameron Dale <camrdale@gmail.com>
Tue, 15 Apr 2008 23:07:05 +0000 (16:07 -0700)
apt_p2p/Hash.py
apt_p2p/MirrorManager.py
apt_p2p_Khashmir/DHT.py

index bf23e9635e546825f7a439cbee83a001af42c132..fe26a0129de9924ec39b54e0bf16fea9d3b088dc 100644 (file)
@@ -157,9 +157,7 @@ class HashObject:
         """Hashes a file in a separate thread, returning a deferred that will callback with the result."""
         file.restat(False)
         if not file.exists():
-            df = defer.Deferred()
-            df.errback(HashError("file not found"))
-            return df
+            return defer.fail(HashError("file not found"))
         
         df = threads.deferToThread(self._hashInThread, file)
         return df
index 5f511758dfda0026a722f2b7bd4b14120eb3d732..301c0dbc8332bfa9329a299b2f3ca59ca1b67972 100644 (file)
@@ -111,9 +111,7 @@ class MirrorManager:
         site, baseDir, path = self.extractPath(url)
         if site in self.apt_caches and baseDir in self.apt_caches[site]:
             return self.apt_caches[site][baseDir].findHash(path)
-        d = defer.Deferred()
-        d.errback(MirrorError("Site Not Found"))
-        return d
+        return defer.fail(MirrorError("Site Not Found"))
     
     def cleanup(self):
         for site in self.apt_caches.keys():
index 400b10de1d7098d692e80805c73dba9e8959cb7c..1870841d167b151b8953b7c2654deaf07a651918 100644 (file)
@@ -249,15 +249,12 @@ class DHT:
 
     def getValue(self, key):
         """See L{apt_p2p.interfaces.IDHT}."""
-        d = defer.Deferred()
-
         if self.config is None:
-            d.errback(DHTError("configuration not loaded"))
-            return d
+            return defer.fail(DHTError("configuration not loaded"))
         if not self.joined:
-            d.errback(DHTError("have not joined a network yet"))
-            return d
+            return defer.fail(DHTError("have not joined a network yet"))
         
+        d = defer.Deferred()
         key = self._normKey(key)
 
         if key not in self.retrieving:
@@ -283,15 +280,12 @@ class DHT:
 
     def storeValue(self, key, value):
         """See L{apt_p2p.interfaces.IDHT}."""
-        d = defer.Deferred()
-
         if self.config is None:
-            d.errback(DHTError("configuration not loaded"))
-            return d
+            return defer.fail(DHTError("configuration not loaded"))
         if not self.joined:
-            d.errback(DHTError("have not joined a network yet"))
-            return d
+            return defer.fail(DHTError("have not joined a network yet"))
 
+        d = defer.Deferred()
         key = self._normKey(key)
         bvalue = bencode(value)