Merge pull request #837 from tahoe-lafs/3451.immutable-downloader-start-python-3

Start porting allmydata.immutable.downloader to Python 3

Fixes ticket:3451
This commit is contained in:
Itamar Turner-Trauring 2020-09-30 13:14:38 -04:00 committed by GitHub
commit 1182ed0508
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 52 additions and 1 deletions

0
newsfragments/3451.minor Normal file
View File

View File

@ -1,4 +1,15 @@
"""
Ported to Python 3.
"""
from __future__ import print_function
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from future.utils import PY2
if PY2:
from future.builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, list, object, range, str, max, min # noqa: F401
from twisted.python.failure import Failure
from foolscap.api import eventually
@ -222,7 +233,7 @@ class SegmentFetcher(object):
# add_shares() or no_more_shares() later.
def _cancel_all_requests(self):
for o in self._share_observers.values():
for o in list(self._share_observers.values()):
o.cancel()
self._share_observers = {}

View File

@ -1,3 +1,14 @@
"""
Ported to Python 3.
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
from future.utils import PY2
if PY2:
from future.builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, list, object, range, str, max, min # noqa: F401
import time
now = time.time

View File

@ -1,3 +1,14 @@
"""
Ported to Python 3.
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
from future.utils import PY2
if PY2:
from future.builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, list, object, range, str, max, min # noqa: F401
import time
now = time.time

View File

@ -1334,6 +1334,21 @@ class FakeNode(object):
class Selection(unittest.TestCase):
def test_failure(self):
"""If the fetch loop fails, it tell the Node the fetch failed."""
node = FakeNode()
# Simulate a failure:
node.get_num_segments = lambda: 1/0
sf = SegmentFetcher(node, 0, 3, None)
sf.add_shares([])
d = flushEventualQueue()
def _check1(ign):
[_] = self.flushLoggedErrors(ZeroDivisionError)
self.failUnless(node.failed)
self.failUnless(node.failed.check(ZeroDivisionError))
d.addCallback(_check1)
return d
def test_no_shares(self):
node = FakeNode()
sf = SegmentFetcher(node, 0, 3, None)

View File

@ -32,6 +32,9 @@ PORTED_MODULES = [
"allmydata.crypto.rsa",
"allmydata.crypto.util",
"allmydata.hashtree",
"allmydata.immutable.downloader.fetcher",
"allmydata.immutable.downloader.finder",
"allmydata.immutable.downloader.segmentation",
"allmydata.immutable.happiness_upload",
"allmydata.immutable.literal",
"allmydata.interfaces",