"""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
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():
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:
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)