From 66c6522325b7740ce575917b9a29755bf193d241 Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Mon, 28 Sep 2020 16:44:50 -0400 Subject: [PATCH 1/4] Unused code. --- src/allmydata/immutable/literal.py | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/src/allmydata/immutable/literal.py b/src/allmydata/immutable/literal.py index 4832da7c1..f5eca564e 100644 --- a/src/allmydata/immutable/literal.py +++ b/src/allmydata/immutable/literal.py @@ -2,7 +2,6 @@ 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 @@ -45,19 +44,6 @@ class _ImmutableFileNodeBase(object): return True -@implementer(IPushProducer) -class LiteralProducer(object): - - def pauseProducing(self): - pass - - def resumeProducing(self): - pass - - def stopProducing(self): - pass - - class LiteralFileNode(_ImmutableFileNodeBase): def __init__(self, filecap): From e3a9f5fa75732c43c8d6845678b838866840f3fe Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Mon, 28 Sep 2020 16:49:30 -0400 Subject: [PATCH 2/4] Test and bugfix for LiteralFileNode equality. --- src/allmydata/immutable/literal.py | 9 ++++----- src/allmydata/test/test_immutable.py | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/allmydata/immutable/literal.py b/src/allmydata/immutable/literal.py index f5eca564e..59577afb1 100644 --- a/src/allmydata/immutable/literal.py +++ b/src/allmydata/immutable/literal.py @@ -32,16 +32,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 + return not self == other class LiteralFileNode(_ImmutableFileNodeBase): diff --git a/src/allmydata/test/test_immutable.py b/src/allmydata/test/test_immutable.py index 2646d2c38..12f2012e0 100644 --- a/src/allmydata/test/test_immutable.py +++ b/src/allmydata/test/test_immutable.py @@ -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 From a0a8b4403d4eda7e1cb734a6d5eedb7d9bca5327 Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Mon, 28 Sep 2020 16:49:51 -0400 Subject: [PATCH 3/4] News file. --- newsfragments/3450.minor | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 newsfragments/3450.minor diff --git a/newsfragments/3450.minor b/newsfragments/3450.minor new file mode 100644 index 000000000..e69de29bb From f42634cfe776668a315b93fa750ac44475545840 Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Mon, 28 Sep 2020 16:51:29 -0400 Subject: [PATCH 4/4] Port to Python 3. --- src/allmydata/immutable/literal.py | 13 +++++++++++++ src/allmydata/util/_python3.py | 1 + 2 files changed, 14 insertions(+) diff --git a/src/allmydata/immutable/literal.py b/src/allmydata/immutable/literal.py index 59577afb1..68db478f3 100644 --- a/src/allmydata/immutable/literal.py +++ b/src/allmydata/immutable/literal.py @@ -1,3 +1,16 @@ +""" +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 diff --git a/src/allmydata/util/_python3.py b/src/allmydata/util/_python3.py index 4c5eaa6af..e2b6c3ddb 100644 --- a/src/allmydata/util/_python3.py +++ b/src/allmydata/util/_python3.py @@ -33,6 +33,7 @@ PORTED_MODULES = [ "allmydata.crypto.util", "allmydata.hashtree", "allmydata.immutable.happiness_upload", + "allmydata.immutable.literal", "allmydata.interfaces", "allmydata.monitor", "allmydata.storage.common",