Merge branch '3451.immutable-downloader-start-python-3' into 3452.immutable-downloader-more-python-3

This commit is contained in:
Itamar Turner-Trauring 2020-09-30 11:52:37 -04:00
commit 6c72c8b77f
9 changed files with 90 additions and 21 deletions

0
newsfragments/3450.minor Normal file
View File

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

@ -1,8 +1,20 @@
"""
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
from io import BytesIO
from zope.interface import implementer
from twisted.internet import defer
from twisted.internet.interfaces import IPushProducer
from twisted.protocols import basic
from allmydata.interfaces import IImmutableFileNode, ICheckable
from allmydata.uri import LiteralFileURI
@ -33,29 +45,15 @@ class _ImmutableFileNodeBase(object):
def __hash__(self):
return self.u.__hash__()
def __eq__(self, other):
if isinstance(other, _ImmutableFileNodeBase):
return self.u.__eq__(other.u)
return self.u == other.u
else:
return False
def __ne__(self, other):
if isinstance(other, _ImmutableFileNodeBase):
return self.u.__eq__(other.u)
else:
return True
@implementer(IPushProducer)
class LiteralProducer(object):
def pauseProducing(self):
pass
def resumeProducing(self):
pass
def stopProducing(self):
pass
return not self == other
class LiteralFileNode(_ImmutableFileNodeBase):

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

@ -26,6 +26,7 @@ from allmydata.util.consumer import download_to_data
from allmydata.interfaces import NotEnoughSharesError
from allmydata.immutable.upload import Data
from allmydata.immutable.downloader import finder
from allmydata.immutable.literal import LiteralFileNode
from .no_network import (
NoNetworkServer,
@ -340,6 +341,24 @@ class Test(GridTestMixin, unittest.TestCase, common.ShouldFailMixin):
return d
class LiteralFileNodeTests(unittest.TestCase):
"""Tests for LiteralFileNode."""
def test_equality(self):
"""LiteralFileNodes are equal iff they have the same URI."""
uri1 = uri.LiteralFileURI(b"1")
uri2 = uri.LiteralFileURI(b"2")
lfn1 = LiteralFileNode(uri1)
lfn1b = LiteralFileNode(uri1)
lfn2 = LiteralFileNode(uri2)
self.assertTrue(lfn1 == lfn1b)
self.assertFalse(lfn1 != lfn1b)
self.assertTrue(lfn1 != lfn2)
self.assertFalse(lfn1 == lfn2)
self.assertTrue(lfn1 != 300)
self.assertFalse(lfn1 == 300)
# XXX extend these tests to show bad behavior of various kinds from servers:
# raising exception from each remove_foo() method, for example

View File

@ -32,11 +32,15 @@ PORTED_MODULES = [
"allmydata.crypto.rsa",
"allmydata.crypto.util",
"allmydata.hashtree",
"allmydata.immutable.happiness_upload",
"allmydata.immutable.downloader",
"allmydata.immutable.downloader.common",
"allmydata.immutable.downloader.fetcher",
"allmydata.immutable.downloader.finder",
"allmydata.immutable.downloader.node",
"allmydata.immutable.downloader.segmentation",
"allmydata.immutable.downloader.status",
"allmydata.immutable.happiness_upload",
"allmydata.immutable.literal",
"allmydata.interfaces",
"allmydata.introducer.interfaces",
"allmydata.monitor",