mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-04-08 11:24:25 +00:00
Merge pull request #836 from tahoe-lafs/3450.immutable-literal-python-3
Port allmydata.immutable.literal to Python 3 (and fix a bug) Fixes ticket:3450
This commit is contained in:
commit
df69ca8b5b
0
newsfragments/3450.minor
Normal file
0
newsfragments/3450.minor
Normal 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):
|
||||
|
@ -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
|
||||
|
||||
|
@ -33,6 +33,7 @@ PORTED_MODULES = [
|
||||
"allmydata.crypto.util",
|
||||
"allmydata.hashtree",
|
||||
"allmydata.immutable.happiness_upload",
|
||||
"allmydata.immutable.literal",
|
||||
"allmydata.interfaces",
|
||||
"allmydata.introducer.interfaces",
|
||||
"allmydata.monitor",
|
||||
|
Loading…
x
Reference in New Issue
Block a user