mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2024-12-19 21:17:54 +00:00
Merge pull request #923 from tahoe-lafs/3553.nodemaker-python-3
Port allmydata.nodemaker and .dirnode to Python 3 Fixes ticket:3553
This commit is contained in:
commit
919f31acf3
0
newsfragments/3553.minor
Normal file
0
newsfragments/3553.minor
Normal file
@ -1,4 +1,16 @@
|
||||
"""Directory Node implementation."""
|
||||
"""Directory Node implementation.
|
||||
|
||||
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:
|
||||
# Skip dict so it doesn't break things.
|
||||
from future.builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, list, object, range, str, max, min # noqa: F401
|
||||
from past.builtins import unicode
|
||||
|
||||
import time
|
||||
@ -37,6 +49,8 @@ from eliot.twisted import (
|
||||
|
||||
NAME = Field.for_types(
|
||||
u"name",
|
||||
# Make sure this works on Python 2; with str, it gets Future str which
|
||||
# breaks Eliot.
|
||||
[unicode],
|
||||
u"The name linking the parent to this node.",
|
||||
)
|
||||
@ -179,7 +193,7 @@ class Adder(object):
|
||||
def modify(self, old_contents, servermap, first_time):
|
||||
children = self.node._unpack_contents(old_contents)
|
||||
now = time.time()
|
||||
for (namex, (child, new_metadata)) in self.entries.iteritems():
|
||||
for (namex, (child, new_metadata)) in list(self.entries.items()):
|
||||
name = normalize(namex)
|
||||
precondition(IFilesystemNode.providedBy(child), child)
|
||||
|
||||
@ -205,8 +219,8 @@ class Adder(object):
|
||||
return new_contents
|
||||
|
||||
def _encrypt_rw_uri(writekey, rw_uri):
|
||||
precondition(isinstance(rw_uri, str), rw_uri)
|
||||
precondition(isinstance(writekey, str), writekey)
|
||||
precondition(isinstance(rw_uri, bytes), rw_uri)
|
||||
precondition(isinstance(writekey, bytes), writekey)
|
||||
|
||||
salt = hashutil.mutable_rwcap_salt_hash(rw_uri)
|
||||
key = hashutil.mutable_rwcap_key_hash(salt, writekey)
|
||||
@ -221,7 +235,7 @@ def _encrypt_rw_uri(writekey, rw_uri):
|
||||
def pack_children(childrenx, writekey, deep_immutable=False):
|
||||
# initial_children must have metadata (i.e. {} instead of None)
|
||||
children = {}
|
||||
for (namex, (node, metadata)) in childrenx.iteritems():
|
||||
for (namex, (node, metadata)) in list(childrenx.items()):
|
||||
precondition(isinstance(metadata, dict),
|
||||
"directory creation requires metadata to be a dict, not None", metadata)
|
||||
children[normalize(namex)] = (node, metadata)
|
||||
@ -245,18 +259,19 @@ def _pack_normalized_children(children, writekey, deep_immutable=False):
|
||||
If deep_immutable is True, I will require that all my children are deeply
|
||||
immutable, and will raise a MustBeDeepImmutableError if not.
|
||||
"""
|
||||
precondition((writekey is None) or isinstance(writekey, str), writekey)
|
||||
precondition((writekey is None) or isinstance(writekey, bytes), writekey)
|
||||
|
||||
has_aux = isinstance(children, AuxValueDict)
|
||||
entries = []
|
||||
for name in sorted(children.keys()):
|
||||
assert isinstance(name, unicode)
|
||||
assert isinstance(name, str)
|
||||
entry = None
|
||||
(child, metadata) = children[name]
|
||||
child.raise_error()
|
||||
if deep_immutable and not child.is_allowed_in_immutable_directory():
|
||||
raise MustBeDeepImmutableError("child %s is not allowed in an immutable directory" %
|
||||
quote_output(name, encoding='utf-8'), name)
|
||||
raise MustBeDeepImmutableError(
|
||||
"child %r is not allowed in an immutable directory" % (name,),
|
||||
name)
|
||||
if has_aux:
|
||||
entry = children.get_aux(name)
|
||||
if not entry:
|
||||
@ -264,26 +279,26 @@ def _pack_normalized_children(children, writekey, deep_immutable=False):
|
||||
assert isinstance(metadata, dict)
|
||||
rw_uri = child.get_write_uri()
|
||||
if rw_uri is None:
|
||||
rw_uri = ""
|
||||
assert isinstance(rw_uri, str), rw_uri
|
||||
rw_uri = b""
|
||||
assert isinstance(rw_uri, bytes), rw_uri
|
||||
|
||||
# should be prevented by MustBeDeepImmutableError check above
|
||||
assert not (rw_uri and deep_immutable)
|
||||
|
||||
ro_uri = child.get_readonly_uri()
|
||||
if ro_uri is None:
|
||||
ro_uri = ""
|
||||
assert isinstance(ro_uri, str), ro_uri
|
||||
ro_uri = b""
|
||||
assert isinstance(ro_uri, bytes), ro_uri
|
||||
if writekey is not None:
|
||||
writecap = netstring(_encrypt_rw_uri(writekey, rw_uri))
|
||||
else:
|
||||
writecap = ZERO_LEN_NETSTR
|
||||
entry = "".join([netstring(name.encode("utf-8")),
|
||||
entry = b"".join([netstring(name.encode("utf-8")),
|
||||
netstring(strip_prefix_for_ro(ro_uri, deep_immutable)),
|
||||
writecap,
|
||||
netstring(json.dumps(metadata))])
|
||||
netstring(json.dumps(metadata).encode("utf-8"))])
|
||||
entries.append(netstring(entry))
|
||||
return "".join(entries)
|
||||
return b"".join(entries)
|
||||
|
||||
@implementer(IDirectoryNode, ICheckable, IDeepCheckable)
|
||||
class DirectoryNode(object):
|
||||
@ -352,9 +367,9 @@ class DirectoryNode(object):
|
||||
# cleartext. The 'name' is UTF-8 encoded, and should be normalized to NFC.
|
||||
# The rwcapdata is formatted as:
|
||||
# pack("16ss32s", iv, AES(H(writekey+iv), plaintext_rw_uri), mac)
|
||||
assert isinstance(data, str), (repr(data), type(data))
|
||||
assert isinstance(data, bytes), (repr(data), type(data))
|
||||
# an empty directory is serialized as an empty string
|
||||
if data == "":
|
||||
if data == b"":
|
||||
return AuxValueDict()
|
||||
writeable = not self.is_readonly()
|
||||
mutable = self.is_mutable()
|
||||
@ -373,7 +388,7 @@ class DirectoryNode(object):
|
||||
# Therefore we normalize names going both in and out of directories.
|
||||
name = normalize(namex_utf8.decode("utf-8"))
|
||||
|
||||
rw_uri = ""
|
||||
rw_uri = b""
|
||||
if writeable:
|
||||
rw_uri = self._decrypt_rwcapdata(rwcapdata)
|
||||
|
||||
@ -384,8 +399,8 @@ class DirectoryNode(object):
|
||||
# ro_uri is treated in the same way for consistency.
|
||||
# rw_uri and ro_uri will be either None or a non-empty string.
|
||||
|
||||
rw_uri = rw_uri.rstrip(' ') or None
|
||||
ro_uri = ro_uri.rstrip(' ') or None
|
||||
rw_uri = rw_uri.rstrip(b' ') or None
|
||||
ro_uri = ro_uri.rstrip(b' ') or None
|
||||
|
||||
try:
|
||||
child = self._create_and_validate_node(rw_uri, ro_uri, name)
|
||||
@ -468,7 +483,7 @@ class DirectoryNode(object):
|
||||
exists a child of the given name, False if not."""
|
||||
name = normalize(namex)
|
||||
d = self._read()
|
||||
d.addCallback(lambda children: children.has_key(name))
|
||||
d.addCallback(lambda children: name in children)
|
||||
return d
|
||||
|
||||
def _get(self, children, name):
|
||||
@ -543,7 +558,7 @@ class DirectoryNode(object):
|
||||
else:
|
||||
pathx = pathx.split("/")
|
||||
for p in pathx:
|
||||
assert isinstance(p, unicode), p
|
||||
assert isinstance(p, str), p
|
||||
childnamex = pathx[0]
|
||||
remaining_pathx = pathx[1:]
|
||||
if remaining_pathx:
|
||||
@ -555,8 +570,8 @@ class DirectoryNode(object):
|
||||
return d
|
||||
|
||||
def set_uri(self, namex, writecap, readcap, metadata=None, overwrite=True):
|
||||
precondition(isinstance(writecap, (str,type(None))), writecap)
|
||||
precondition(isinstance(readcap, (str,type(None))), readcap)
|
||||
precondition(isinstance(writecap, (bytes, type(None))), writecap)
|
||||
precondition(isinstance(readcap, (bytes, type(None))), readcap)
|
||||
|
||||
# We now allow packing unknown nodes, provided they are valid
|
||||
# for this type of directory.
|
||||
@ -569,16 +584,16 @@ class DirectoryNode(object):
|
||||
# this takes URIs
|
||||
a = Adder(self, overwrite=overwrite,
|
||||
create_readonly_node=self._create_readonly_node)
|
||||
for (namex, e) in entries.iteritems():
|
||||
assert isinstance(namex, unicode), namex
|
||||
for (namex, e) in entries.items():
|
||||
assert isinstance(namex, str), namex
|
||||
if len(e) == 2:
|
||||
writecap, readcap = e
|
||||
metadata = None
|
||||
else:
|
||||
assert len(e) == 3
|
||||
writecap, readcap, metadata = e
|
||||
precondition(isinstance(writecap, (str,type(None))), writecap)
|
||||
precondition(isinstance(readcap, (str,type(None))), readcap)
|
||||
precondition(isinstance(writecap, (bytes,type(None))), writecap)
|
||||
precondition(isinstance(readcap, (bytes,type(None))), readcap)
|
||||
|
||||
# We now allow packing unknown nodes, provided they are valid
|
||||
# for this type of directory.
|
||||
@ -779,7 +794,7 @@ class DirectoryNode(object):
|
||||
# in the nodecache) seem to consume about 2000 bytes.
|
||||
dirkids = []
|
||||
filekids = []
|
||||
for name, (child, metadata) in sorted(children.iteritems()):
|
||||
for name, (child, metadata) in sorted(children.items()):
|
||||
childpath = path + [name]
|
||||
if isinstance(child, UnknownNode):
|
||||
walker.add_node(child, childpath)
|
||||
|
@ -1,3 +1,15 @@
|
||||
"""
|
||||
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 weakref
|
||||
from zope.interface import implementer
|
||||
from allmydata.util.assertutil import precondition
|
||||
@ -126,7 +138,7 @@ class NodeMaker(object):
|
||||
|
||||
def create_new_mutable_directory(self, initial_children={}, version=None):
|
||||
# initial_children must have metadata (i.e. {} instead of None)
|
||||
for (name, (node, metadata)) in initial_children.iteritems():
|
||||
for (name, (node, metadata)) in initial_children.items():
|
||||
precondition(isinstance(metadata, dict),
|
||||
"create_new_mutable_directory requires metadata to be a dict, not None", metadata)
|
||||
node.raise_error()
|
||||
|
@ -1,5 +1,19 @@
|
||||
"""Tests for the dirnode module."""
|
||||
import six
|
||||
"""Tests for the dirnode module.
|
||||
|
||||
Ported to Python 3.
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from past.builtins import long
|
||||
|
||||
from future.utils import PY2
|
||||
if PY2:
|
||||
# Skip list() since it results in spurious test failures
|
||||
from future.builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, object, range, str, max, min # noqa: F401
|
||||
|
||||
import time
|
||||
import unicodedata
|
||||
from zope.interface import implementer
|
||||
@ -31,9 +45,6 @@ import allmydata.test.common_util as testutil
|
||||
from hypothesis import given
|
||||
from hypothesis.strategies import text
|
||||
|
||||
if six.PY3:
|
||||
long = int
|
||||
|
||||
|
||||
@implementer(IConsumer)
|
||||
class MemAccum(object):
|
||||
@ -48,16 +59,16 @@ class MemAccum(object):
|
||||
self.data = data
|
||||
self.producer.resumeProducing()
|
||||
|
||||
setup_py_uri = "URI:CHK:n7r3m6wmomelk4sep3kw5cvduq:os7ijw5c3maek7pg65e5254k2fzjflavtpejjyhshpsxuqzhcwwq:3:20:14861"
|
||||
one_uri = "URI:LIT:n5xgk" # LIT for "one"
|
||||
mut_write_uri = "URI:SSK:vfvcbdfbszyrsaxchgevhmmlii:euw4iw7bbnkrrwpzuburbhppuxhc3gwxv26f6imekhz7zyw2ojnq"
|
||||
mdmf_write_uri = "URI:MDMF:x533rhbm6kiehzl5kj3s44n5ie:4gif5rhneyd763ouo5qjrgnsoa3bg43xycy4robj2rf3tvmhdl3a"
|
||||
empty_litdir_uri = "URI:DIR2-LIT:"
|
||||
tiny_litdir_uri = "URI:DIR2-LIT:gqytunj2onug64tufqzdcosvkjetutcjkq5gw4tvm5vwszdgnz5hgyzufqydulbshj5x2lbm" # contains one child which is itself also LIT
|
||||
mut_read_uri = "URI:SSK-RO:jf6wkflosyvntwxqcdo7a54jvm:euw4iw7bbnkrrwpzuburbhppuxhc3gwxv26f6imekhz7zyw2ojnq"
|
||||
mdmf_read_uri = "URI:MDMF-RO:d4cydxselputycfzkw6qgz4zv4:4gif5rhneyd763ouo5qjrgnsoa3bg43xycy4robj2rf3tvmhdl3a"
|
||||
future_write_uri = "x-tahoe-crazy://I_am_from_the_future."
|
||||
future_read_uri = "x-tahoe-crazy-readonly://I_am_from_the_future."
|
||||
setup_py_uri = b"URI:CHK:n7r3m6wmomelk4sep3kw5cvduq:os7ijw5c3maek7pg65e5254k2fzjflavtpejjyhshpsxuqzhcwwq:3:20:14861"
|
||||
one_uri = b"URI:LIT:n5xgk" # LIT for "one"
|
||||
mut_write_uri = b"URI:SSK:vfvcbdfbszyrsaxchgevhmmlii:euw4iw7bbnkrrwpzuburbhppuxhc3gwxv26f6imekhz7zyw2ojnq"
|
||||
mdmf_write_uri = b"URI:MDMF:x533rhbm6kiehzl5kj3s44n5ie:4gif5rhneyd763ouo5qjrgnsoa3bg43xycy4robj2rf3tvmhdl3a"
|
||||
empty_litdir_uri = b"URI:DIR2-LIT:"
|
||||
tiny_litdir_uri = b"URI:DIR2-LIT:gqytunj2onug64tufqzdcosvkjetutcjkq5gw4tvm5vwszdgnz5hgyzufqydulbshj5x2lbm" # contains one child which is itself also LIT
|
||||
mut_read_uri = b"URI:SSK-RO:jf6wkflosyvntwxqcdo7a54jvm:euw4iw7bbnkrrwpzuburbhppuxhc3gwxv26f6imekhz7zyw2ojnq"
|
||||
mdmf_read_uri = b"URI:MDMF-RO:d4cydxselputycfzkw6qgz4zv4:4gif5rhneyd763ouo5qjrgnsoa3bg43xycy4robj2rf3tvmhdl3a"
|
||||
future_write_uri = b"x-tahoe-crazy://I_am_from_the_future."
|
||||
future_read_uri = b"x-tahoe-crazy-readonly://I_am_from_the_future."
|
||||
future_nonascii_write_uri = u"x-tahoe-even-more-crazy://I_am_from_the_future_rw_\u263A".encode('utf-8')
|
||||
future_nonascii_read_uri = u"x-tahoe-even-more-crazy-readonly://I_am_from_the_future_ro_\u263A".encode('utf-8')
|
||||
|
||||
@ -95,13 +106,13 @@ class Dirnode(GridTestMixin, unittest.TestCase,
|
||||
self.failUnless(u)
|
||||
cap_formats = []
|
||||
if mdmf:
|
||||
cap_formats = ["URI:DIR2-MDMF:",
|
||||
"URI:DIR2-MDMF-RO:",
|
||||
"URI:DIR2-MDMF-Verifier:"]
|
||||
cap_formats = [b"URI:DIR2-MDMF:",
|
||||
b"URI:DIR2-MDMF-RO:",
|
||||
b"URI:DIR2-MDMF-Verifier:"]
|
||||
else:
|
||||
cap_formats = ["URI:DIR2:",
|
||||
"URI:DIR2-RO",
|
||||
"URI:DIR2-Verifier:"]
|
||||
cap_formats = [b"URI:DIR2:",
|
||||
b"URI:DIR2-RO",
|
||||
b"URI:DIR2-Verifier:"]
|
||||
rw, ro, v = cap_formats
|
||||
self.failUnless(u.startswith(rw), u)
|
||||
u_ro = n.get_readonly_uri()
|
||||
@ -149,7 +160,7 @@ class Dirnode(GridTestMixin, unittest.TestCase,
|
||||
self.failUnless(isinstance(subdir, dirnode.DirectoryNode))
|
||||
self.subdir = subdir
|
||||
new_v = subdir.get_verify_cap().to_string()
|
||||
assert isinstance(new_v, str)
|
||||
assert isinstance(new_v, bytes)
|
||||
self.expected_manifest.append( ((u"subdir",), subdir.get_uri()) )
|
||||
self.expected_verifycaps.add(new_v)
|
||||
si = subdir.get_storage_index()
|
||||
@ -182,7 +193,7 @@ class Dirnode(GridTestMixin, unittest.TestCase,
|
||||
"largest-directory-children": 2,
|
||||
"largest-immutable-file": 0,
|
||||
}
|
||||
for k,v in expected.iteritems():
|
||||
for k,v in expected.items():
|
||||
self.failUnlessReallyEqual(stats[k], v,
|
||||
"stats[%s] was %s, not %s" %
|
||||
(k, stats[k], v))
|
||||
@ -272,8 +283,8 @@ class Dirnode(GridTestMixin, unittest.TestCase,
|
||||
{ 'tahoe': {'linkcrtime': "bogus"}}))
|
||||
d.addCallback(lambda res: n.get_metadata_for(u"c2"))
|
||||
def _has_good_linkcrtime(metadata):
|
||||
self.failUnless(metadata.has_key('tahoe'))
|
||||
self.failUnless(metadata['tahoe'].has_key('linkcrtime'))
|
||||
self.failUnless('tahoe' in metadata)
|
||||
self.failUnless('linkcrtime' in metadata['tahoe'])
|
||||
self.failIfEqual(metadata['tahoe']['linkcrtime'], 'bogus')
|
||||
d.addCallback(_has_good_linkcrtime)
|
||||
|
||||
@ -423,7 +434,7 @@ class Dirnode(GridTestMixin, unittest.TestCase,
|
||||
# moved on to stdlib "json" which doesn't have it either.
|
||||
d.addCallback(self.stall, 0.1)
|
||||
d.addCallback(lambda res: n.add_file(u"timestamps",
|
||||
upload.Data("stamp me", convergence="some convergence string")))
|
||||
upload.Data(b"stamp me", convergence=b"some convergence string")))
|
||||
d.addCallback(self.stall, 0.1)
|
||||
def _stop(res):
|
||||
self._stop_timestamp = time.time()
|
||||
@ -472,11 +483,11 @@ class Dirnode(GridTestMixin, unittest.TestCase,
|
||||
self.failUnlessReallyEqual(set(children.keys()),
|
||||
set([u"child"])))
|
||||
|
||||
uploadable1 = upload.Data("some data", convergence="converge")
|
||||
uploadable1 = upload.Data(b"some data", convergence=b"converge")
|
||||
d.addCallback(lambda res: n.add_file(u"newfile", uploadable1))
|
||||
d.addCallback(lambda newnode:
|
||||
self.failUnless(IImmutableFileNode.providedBy(newnode)))
|
||||
uploadable2 = upload.Data("some data", convergence="stuff")
|
||||
uploadable2 = upload.Data(b"some data", convergence=b"stuff")
|
||||
d.addCallback(lambda res:
|
||||
self.shouldFail(ExistingChildError, "add_file-no",
|
||||
"child 'newfile' already exists",
|
||||
@ -491,7 +502,7 @@ class Dirnode(GridTestMixin, unittest.TestCase,
|
||||
d.addCallback(lambda metadata:
|
||||
self.failUnlessEqual(set(metadata.keys()), set(["tahoe"])))
|
||||
|
||||
uploadable3 = upload.Data("some data", convergence="converge")
|
||||
uploadable3 = upload.Data(b"some data", convergence=b"converge")
|
||||
d.addCallback(lambda res: n.add_file(u"newfile-metadata",
|
||||
uploadable3,
|
||||
{"key": "value"}))
|
||||
@ -507,8 +518,8 @@ class Dirnode(GridTestMixin, unittest.TestCase,
|
||||
def _created2(subdir2):
|
||||
self.subdir2 = subdir2
|
||||
# put something in the way, to make sure it gets overwritten
|
||||
return subdir2.add_file(u"child", upload.Data("overwrite me",
|
||||
"converge"))
|
||||
return subdir2.add_file(u"child", upload.Data(b"overwrite me",
|
||||
b"converge"))
|
||||
d.addCallback(_created2)
|
||||
|
||||
d.addCallback(lambda res:
|
||||
@ -666,22 +677,22 @@ class Dirnode(GridTestMixin, unittest.TestCase,
|
||||
|
||||
self.failUnless(fut_node.is_unknown())
|
||||
self.failUnlessReallyEqual(fut_node.get_uri(), future_write_uri)
|
||||
self.failUnlessReallyEqual(fut_node.get_readonly_uri(), "ro." + future_read_uri)
|
||||
self.failUnlessReallyEqual(fut_node.get_readonly_uri(), b"ro." + future_read_uri)
|
||||
self.failUnless(isinstance(fut_metadata, dict), fut_metadata)
|
||||
|
||||
self.failUnless(futna_node.is_unknown())
|
||||
self.failUnlessReallyEqual(futna_node.get_uri(), future_nonascii_write_uri)
|
||||
self.failUnlessReallyEqual(futna_node.get_readonly_uri(), "ro." + future_nonascii_read_uri)
|
||||
self.failUnlessReallyEqual(futna_node.get_readonly_uri(), b"ro." + future_nonascii_read_uri)
|
||||
self.failUnless(isinstance(futna_metadata, dict), futna_metadata)
|
||||
|
||||
self.failUnless(fro_node.is_unknown())
|
||||
self.failUnlessReallyEqual(fro_node.get_uri(), "ro." + future_read_uri)
|
||||
self.failUnlessReallyEqual(fut_node.get_readonly_uri(), "ro." + future_read_uri)
|
||||
self.failUnlessReallyEqual(fro_node.get_uri(), b"ro." + future_read_uri)
|
||||
self.failUnlessReallyEqual(fut_node.get_readonly_uri(), b"ro." + future_read_uri)
|
||||
self.failUnless(isinstance(fro_metadata, dict), fro_metadata)
|
||||
|
||||
self.failUnless(frona_node.is_unknown())
|
||||
self.failUnlessReallyEqual(frona_node.get_uri(), "ro." + future_nonascii_read_uri)
|
||||
self.failUnlessReallyEqual(futna_node.get_readonly_uri(), "ro." + future_nonascii_read_uri)
|
||||
self.failUnlessReallyEqual(frona_node.get_uri(), b"ro." + future_nonascii_read_uri)
|
||||
self.failUnlessReallyEqual(futna_node.get_readonly_uri(), b"ro." + future_nonascii_read_uri)
|
||||
self.failUnless(isinstance(frona_metadata, dict), frona_metadata)
|
||||
|
||||
self.failIf(emptylit_node.is_unknown())
|
||||
@ -697,7 +708,7 @@ class Dirnode(GridTestMixin, unittest.TestCase,
|
||||
set([u"short"])))
|
||||
d2.addCallback(lambda ignored: tinylit_node.list())
|
||||
d2.addCallback(lambda children: children[u"short"][0].read(MemAccum()))
|
||||
d2.addCallback(lambda accum: self.failUnlessReallyEqual(accum.data, "The end."))
|
||||
d2.addCallback(lambda accum: self.failUnlessReallyEqual(accum.data, b"The end."))
|
||||
return d2
|
||||
d.addCallback(_check_kids)
|
||||
|
||||
@ -782,7 +793,7 @@ class Dirnode(GridTestMixin, unittest.TestCase,
|
||||
rep = str(dn)
|
||||
self.failUnless("RO-IMM" in rep)
|
||||
cap = dn.get_cap()
|
||||
self.failUnlessIn("CHK", cap.to_string())
|
||||
self.failUnlessIn(b"CHK", cap.to_string())
|
||||
self.cap = cap
|
||||
return dn.list()
|
||||
d.addCallback(_created)
|
||||
@ -808,13 +819,13 @@ class Dirnode(GridTestMixin, unittest.TestCase,
|
||||
self.failUnlessEqual(two_metadata["metakey"], "metavalue")
|
||||
|
||||
self.failUnless(fut_node.is_unknown())
|
||||
self.failUnlessReallyEqual(fut_node.get_uri(), "imm." + future_read_uri)
|
||||
self.failUnlessReallyEqual(fut_node.get_readonly_uri(), "imm." + future_read_uri)
|
||||
self.failUnlessReallyEqual(fut_node.get_uri(), b"imm." + future_read_uri)
|
||||
self.failUnlessReallyEqual(fut_node.get_readonly_uri(), b"imm." + future_read_uri)
|
||||
self.failUnless(isinstance(fut_metadata, dict), fut_metadata)
|
||||
|
||||
self.failUnless(futna_node.is_unknown())
|
||||
self.failUnlessReallyEqual(futna_node.get_uri(), "imm." + future_nonascii_read_uri)
|
||||
self.failUnlessReallyEqual(futna_node.get_readonly_uri(), "imm." + future_nonascii_read_uri)
|
||||
self.failUnlessReallyEqual(futna_node.get_uri(), b"imm." + future_nonascii_read_uri)
|
||||
self.failUnlessReallyEqual(futna_node.get_readonly_uri(), b"imm." + future_nonascii_read_uri)
|
||||
self.failUnless(isinstance(futna_metadata, dict), futna_metadata)
|
||||
|
||||
self.failIf(emptylit_node.is_unknown())
|
||||
@ -830,7 +841,7 @@ class Dirnode(GridTestMixin, unittest.TestCase,
|
||||
set([u"short"])))
|
||||
d2.addCallback(lambda ignored: tinylit_node.list())
|
||||
d2.addCallback(lambda children: children[u"short"][0].read(MemAccum()))
|
||||
d2.addCallback(lambda accum: self.failUnlessReallyEqual(accum.data, "The end."))
|
||||
d2.addCallback(lambda accum: self.failUnlessReallyEqual(accum.data, b"The end."))
|
||||
return d2
|
||||
|
||||
d.addCallback(_check_kids)
|
||||
@ -894,8 +905,8 @@ class Dirnode(GridTestMixin, unittest.TestCase,
|
||||
rep = str(dn)
|
||||
self.failUnless("RO-IMM" in rep)
|
||||
cap = dn.get_cap()
|
||||
self.failUnlessIn("LIT", cap.to_string())
|
||||
self.failUnlessReallyEqual(cap.to_string(), "URI:DIR2-LIT:")
|
||||
self.failUnlessIn(b"LIT", cap.to_string())
|
||||
self.failUnlessReallyEqual(cap.to_string(), b"URI:DIR2-LIT:")
|
||||
self.cap = cap
|
||||
return dn.list()
|
||||
d.addCallback(_created_empty)
|
||||
@ -912,13 +923,13 @@ class Dirnode(GridTestMixin, unittest.TestCase,
|
||||
rep = str(dn)
|
||||
self.failUnless("RO-IMM" in rep)
|
||||
cap = dn.get_cap()
|
||||
self.failUnlessIn("LIT", cap.to_string())
|
||||
self.failUnlessIn(b"LIT", cap.to_string())
|
||||
self.failUnlessReallyEqual(cap.to_string(),
|
||||
"URI:DIR2-LIT:gi4tumj2n4wdcmz2kvjesosmjfkdu3rvpbtwwlbqhiwdeot3puwcy")
|
||||
b"URI:DIR2-LIT:gi4tumj2n4wdcmz2kvjesosmjfkdu3rvpbtwwlbqhiwdeot3puwcy")
|
||||
self.cap = cap
|
||||
return dn.list()
|
||||
d.addCallback(_created_small)
|
||||
d.addCallback(lambda kids: self.failUnlessReallyEqual(kids.keys(), [u"o"]))
|
||||
d.addCallback(lambda kids: self.failUnlessReallyEqual(list(kids.keys()), [u"o"]))
|
||||
|
||||
# now test n.create_subdirectory(mutable=False)
|
||||
d.addCallback(lambda ign: c.create_dirnode())
|
||||
@ -928,7 +939,7 @@ class Dirnode(GridTestMixin, unittest.TestCase,
|
||||
d.addCallback(_check_kids)
|
||||
d.addCallback(lambda ign: n.list())
|
||||
d.addCallback(lambda children:
|
||||
self.failUnlessReallyEqual(children.keys(), [u"subdir"]))
|
||||
self.failUnlessReallyEqual(list(children.keys()), [u"subdir"]))
|
||||
d.addCallback(lambda ign: n.get(u"subdir"))
|
||||
d.addCallback(lambda sd: sd.list())
|
||||
d.addCallback(_check_kids)
|
||||
@ -962,14 +973,14 @@ class Dirnode(GridTestMixin, unittest.TestCase,
|
||||
# It also tests that we store child names as UTF-8 NFC, and normalize
|
||||
# them again when retrieving them.
|
||||
|
||||
stripped_write_uri = "lafs://from_the_future\t"
|
||||
stripped_read_uri = "lafs://readonly_from_the_future\t"
|
||||
spacedout_write_uri = stripped_write_uri + " "
|
||||
spacedout_read_uri = stripped_read_uri + " "
|
||||
stripped_write_uri = b"lafs://from_the_future\t"
|
||||
stripped_read_uri = b"lafs://readonly_from_the_future\t"
|
||||
spacedout_write_uri = stripped_write_uri + b" "
|
||||
spacedout_read_uri = stripped_read_uri + b" "
|
||||
|
||||
child = nm.create_from_cap(spacedout_write_uri, spacedout_read_uri)
|
||||
self.failUnlessReallyEqual(child.get_write_uri(), spacedout_write_uri)
|
||||
self.failUnlessReallyEqual(child.get_readonly_uri(), "ro." + spacedout_read_uri)
|
||||
self.failUnlessReallyEqual(child.get_readonly_uri(), b"ro." + spacedout_read_uri)
|
||||
|
||||
child_dottedi = u"ch\u0131\u0307ld"
|
||||
|
||||
@ -1003,7 +1014,7 @@ class Dirnode(GridTestMixin, unittest.TestCase,
|
||||
self.failUnlessIn(name, kids_out)
|
||||
(expected_child, ign) = kids_out[name]
|
||||
self.failUnlessReallyEqual(rw_uri, expected_child.get_write_uri())
|
||||
self.failUnlessReallyEqual("ro." + ro_uri, expected_child.get_readonly_uri())
|
||||
self.failUnlessReallyEqual(b"ro." + ro_uri, expected_child.get_readonly_uri())
|
||||
numkids += 1
|
||||
|
||||
self.failUnlessReallyEqual(numkids, len(kids_out))
|
||||
@ -1039,7 +1050,7 @@ class Dirnode(GridTestMixin, unittest.TestCase,
|
||||
child_node, child_metadata = children[u"child"]
|
||||
|
||||
self.failUnlessReallyEqual(child_node.get_write_uri(), stripped_write_uri)
|
||||
self.failUnlessReallyEqual(child_node.get_readonly_uri(), "ro." + stripped_read_uri)
|
||||
self.failUnlessReallyEqual(child_node.get_readonly_uri(), b"ro." + stripped_read_uri)
|
||||
d.addCallback(_check_kids)
|
||||
|
||||
d.addCallback(lambda ign: nm.create_from_cap(self.cap.to_string()))
|
||||
@ -1074,7 +1085,7 @@ class Dirnode(GridTestMixin, unittest.TestCase,
|
||||
d.addCallback(_created_root)
|
||||
def _created_subdir(subdir):
|
||||
self._subdir = subdir
|
||||
d = subdir.add_file(u"file1", upload.Data("data"*100, None))
|
||||
d = subdir.add_file(u"file1", upload.Data(b"data"*100, None))
|
||||
d.addCallback(lambda res: subdir.set_node(u"link", self._rootnode))
|
||||
d.addCallback(lambda res: c.create_dirnode())
|
||||
d.addCallback(lambda dn:
|
||||
@ -1250,7 +1261,7 @@ class Dirnode(GridTestMixin, unittest.TestCase,
|
||||
nm = c.nodemaker
|
||||
filecap = make_chk_file_uri(1234)
|
||||
filenode = nm.create_from_cap(filecap)
|
||||
uploadable = upload.Data("some data", convergence="some convergence string")
|
||||
uploadable = upload.Data(b"some data", convergence=b"some convergence string")
|
||||
|
||||
d = c.create_dirnode(version=version)
|
||||
def _created(rw_dn):
|
||||
@ -1386,7 +1397,7 @@ class Dirnode(GridTestMixin, unittest.TestCase,
|
||||
|
||||
class MinimalFakeMutableFile(object):
|
||||
def get_writekey(self):
|
||||
return "writekey"
|
||||
return b"writekey"
|
||||
|
||||
class Packing(testutil.ReallyEqualMixin, unittest.TestCase):
|
||||
# This is a base32-encoded representation of the directory tree
|
||||
@ -1405,7 +1416,7 @@ class Packing(testutil.ReallyEqualMixin, unittest.TestCase):
|
||||
nodemaker = NodeMaker(None, None, None,
|
||||
None, None,
|
||||
{"k": 3, "n": 10}, None, None)
|
||||
write_uri = "URI:SSK-RO:e3mdrzfwhoq42hy5ubcz6rp3o4:ybyibhnp3vvwuq2vaw2ckjmesgkklfs6ghxleztqidihjyofgw7q"
|
||||
write_uri = b"URI:SSK-RO:e3mdrzfwhoq42hy5ubcz6rp3o4:ybyibhnp3vvwuq2vaw2ckjmesgkklfs6ghxleztqidihjyofgw7q"
|
||||
filenode = nodemaker.create_from_cap(write_uri)
|
||||
node = dirnode.DirectoryNode(filenode, nodemaker, None)
|
||||
children = node._unpack_contents(known_tree)
|
||||
@ -1417,13 +1428,13 @@ class Packing(testutil.ReallyEqualMixin, unittest.TestCase):
|
||||
|
||||
def _check_children(self, children):
|
||||
# Are all the expected child nodes there?
|
||||
self.failUnless(children.has_key(u'file1'))
|
||||
self.failUnless(children.has_key(u'file2'))
|
||||
self.failUnless(children.has_key(u'file3'))
|
||||
self.failUnless(u'file1' in children)
|
||||
self.failUnless(u'file2' in children)
|
||||
self.failUnless(u'file3' in children)
|
||||
|
||||
# Are the metadata for child 3 right?
|
||||
file3_rocap = "URI:CHK:cmtcxq7hwxvfxan34yiev6ivhy:qvcekmjtoetdcw4kmi7b3rtblvgx7544crnwaqtiewemdliqsokq:3:10:5"
|
||||
file3_rwcap = "URI:CHK:cmtcxq7hwxvfxan34yiev6ivhy:qvcekmjtoetdcw4kmi7b3rtblvgx7544crnwaqtiewemdliqsokq:3:10:5"
|
||||
file3_rocap = b"URI:CHK:cmtcxq7hwxvfxan34yiev6ivhy:qvcekmjtoetdcw4kmi7b3rtblvgx7544crnwaqtiewemdliqsokq:3:10:5"
|
||||
file3_rwcap = b"URI:CHK:cmtcxq7hwxvfxan34yiev6ivhy:qvcekmjtoetdcw4kmi7b3rtblvgx7544crnwaqtiewemdliqsokq:3:10:5"
|
||||
file3_metadata = {'ctime': 1246663897.4336269, 'tahoe': {'linkmotime': 1246663897.4336269, 'linkcrtime': 1246663897.4336269}, 'mtime': 1246663897.4336269}
|
||||
self.failUnlessEqual(file3_metadata, children[u'file3'][1])
|
||||
self.failUnlessReallyEqual(file3_rocap,
|
||||
@ -1432,8 +1443,8 @@ class Packing(testutil.ReallyEqualMixin, unittest.TestCase):
|
||||
children[u'file3'][0].get_uri())
|
||||
|
||||
# Are the metadata for child 2 right?
|
||||
file2_rocap = "URI:CHK:apegrpehshwugkbh3jlt5ei6hq:5oougnemcl5xgx4ijgiumtdojlipibctjkbwvyygdymdphib2fvq:3:10:4"
|
||||
file2_rwcap = "URI:CHK:apegrpehshwugkbh3jlt5ei6hq:5oougnemcl5xgx4ijgiumtdojlipibctjkbwvyygdymdphib2fvq:3:10:4"
|
||||
file2_rocap = b"URI:CHK:apegrpehshwugkbh3jlt5ei6hq:5oougnemcl5xgx4ijgiumtdojlipibctjkbwvyygdymdphib2fvq:3:10:4"
|
||||
file2_rwcap = b"URI:CHK:apegrpehshwugkbh3jlt5ei6hq:5oougnemcl5xgx4ijgiumtdojlipibctjkbwvyygdymdphib2fvq:3:10:4"
|
||||
file2_metadata = {'ctime': 1246663897.430218, 'tahoe': {'linkmotime': 1246663897.430218, 'linkcrtime': 1246663897.430218}, 'mtime': 1246663897.430218}
|
||||
self.failUnlessEqual(file2_metadata, children[u'file2'][1])
|
||||
self.failUnlessReallyEqual(file2_rocap,
|
||||
@ -1442,8 +1453,8 @@ class Packing(testutil.ReallyEqualMixin, unittest.TestCase):
|
||||
children[u'file2'][0].get_uri())
|
||||
|
||||
# Are the metadata for child 1 right?
|
||||
file1_rocap = "URI:CHK:olxtimympo7f27jvhtgqlnbtn4:emzdnhk2um4seixozlkw3qx2nfijvdkx3ky7i7izl47yedl6e64a:3:10:10"
|
||||
file1_rwcap = "URI:CHK:olxtimympo7f27jvhtgqlnbtn4:emzdnhk2um4seixozlkw3qx2nfijvdkx3ky7i7izl47yedl6e64a:3:10:10"
|
||||
file1_rocap = b"URI:CHK:olxtimympo7f27jvhtgqlnbtn4:emzdnhk2um4seixozlkw3qx2nfijvdkx3ky7i7izl47yedl6e64a:3:10:10"
|
||||
file1_rwcap = b"URI:CHK:olxtimympo7f27jvhtgqlnbtn4:emzdnhk2um4seixozlkw3qx2nfijvdkx3ky7i7izl47yedl6e64a:3:10:10"
|
||||
file1_metadata = {'ctime': 1246663897.4275661, 'tahoe': {'linkmotime': 1246663897.4275661, 'linkcrtime': 1246663897.4275661}, 'mtime': 1246663897.4275661}
|
||||
self.failUnlessEqual(file1_metadata, children[u'file1'][1])
|
||||
self.failUnlessReallyEqual(file1_rocap,
|
||||
@ -1452,18 +1463,42 @@ class Packing(testutil.ReallyEqualMixin, unittest.TestCase):
|
||||
children[u'file1'][0].get_uri())
|
||||
|
||||
def _make_kids(self, nm, which):
|
||||
caps = {"imm": "URI:CHK:n7r3m6wmomelk4sep3kw5cvduq:os7ijw5c3maek7pg65e5254k2fzjflavtpejjyhshpsxuqzhcwwq:3:20:14861",
|
||||
"lit": "URI:LIT:n5xgk", # LIT for "one"
|
||||
"write": "URI:SSK:vfvcbdfbszyrsaxchgevhmmlii:euw4iw7bbnkrrwpzuburbhppuxhc3gwxv26f6imekhz7zyw2ojnq",
|
||||
"read": "URI:SSK-RO:e3mdrzfwhoq42hy5ubcz6rp3o4:ybyibhnp3vvwuq2vaw2ckjmesgkklfs6ghxleztqidihjyofgw7q",
|
||||
"dirwrite": "URI:DIR2:n6x24zd3seu725yluj75q5boaa:mm6yoqjhl6ueh7iereldqxue4nene4wl7rqfjfybqrehdqmqskvq",
|
||||
"dirread": "URI:DIR2-RO:b7sr5qsifnicca7cbk3rhrhbvq:mm6yoqjhl6ueh7iereldqxue4nene4wl7rqfjfybqrehdqmqskvq",
|
||||
caps = {"imm": b"URI:CHK:n7r3m6wmomelk4sep3kw5cvduq:os7ijw5c3maek7pg65e5254k2fzjflavtpejjyhshpsxuqzhcwwq:3:20:14861",
|
||||
"lit": b"URI:LIT:n5xgk", # LIT for "one"
|
||||
"write": b"URI:SSK:vfvcbdfbszyrsaxchgevhmmlii:euw4iw7bbnkrrwpzuburbhppuxhc3gwxv26f6imekhz7zyw2ojnq",
|
||||
"read": b"URI:SSK-RO:e3mdrzfwhoq42hy5ubcz6rp3o4:ybyibhnp3vvwuq2vaw2ckjmesgkklfs6ghxleztqidihjyofgw7q",
|
||||
"dirwrite": b"URI:DIR2:n6x24zd3seu725yluj75q5boaa:mm6yoqjhl6ueh7iereldqxue4nene4wl7rqfjfybqrehdqmqskvq",
|
||||
"dirread": b"URI:DIR2-RO:b7sr5qsifnicca7cbk3rhrhbvq:mm6yoqjhl6ueh7iereldqxue4nene4wl7rqfjfybqrehdqmqskvq",
|
||||
}
|
||||
kids = {}
|
||||
for name in which:
|
||||
kids[unicode(name)] = (nm.create_from_cap(caps[name]), {})
|
||||
kids[str(name)] = (nm.create_from_cap(caps[name]), {})
|
||||
return kids
|
||||
|
||||
def test_pack_unpack_unknown(self):
|
||||
"""
|
||||
Minimal testing for roundtripping unknown URIs.
|
||||
"""
|
||||
nm = NodeMaker(None, None, None, None, None, {"k": 3, "n": 10}, None, None)
|
||||
fn = MinimalFakeMutableFile()
|
||||
# UnknownNode has massively complex rules about when it's an error.
|
||||
# Just force it not to be an error.
|
||||
unknown_rw = UnknownNode(b"whatevs://write", None)
|
||||
unknown_rw.error = None
|
||||
unknown_ro = UnknownNode(None, b"whatevs://readonly")
|
||||
unknown_ro.error = None
|
||||
kids = {
|
||||
"unknown_rw": (unknown_rw, {}),
|
||||
"unknown_ro": (unknown_ro, {})
|
||||
}
|
||||
packed = dirnode.pack_children(kids, fn.get_writekey(), deep_immutable=False)
|
||||
|
||||
write_uri = b"URI:SSK-RO:e3mdrzfwhoq42hy5ubcz6rp3o4:ybyibhnp3vvwuq2vaw2ckjmesgkklfs6ghxleztqidihjyofgw7q"
|
||||
filenode = nm.create_from_cap(write_uri)
|
||||
dn = dirnode.DirectoryNode(filenode, nm, None)
|
||||
unkids = dn._unpack_contents(packed)
|
||||
self.assertEqual(kids, unkids)
|
||||
|
||||
@given(text(min_size=1, max_size=20))
|
||||
def test_pack_unpack_unicode_hypothesis(self, name):
|
||||
"""
|
||||
@ -1485,7 +1520,7 @@ class Packing(testutil.ReallyEqualMixin, unittest.TestCase):
|
||||
name: (LiteralFileNode(uri.from_string(one_uri)), {}),
|
||||
}
|
||||
packed = dirnode.pack_children(kids, fn.get_writekey(), deep_immutable=False)
|
||||
write_uri = "URI:SSK-RO:e3mdrzfwhoq42hy5ubcz6rp3o4:ybyibhnp3vvwuq2vaw2ckjmesgkklfs6ghxleztqidihjyofgw7q"
|
||||
write_uri = b"URI:SSK-RO:e3mdrzfwhoq42hy5ubcz6rp3o4:ybyibhnp3vvwuq2vaw2ckjmesgkklfs6ghxleztqidihjyofgw7q"
|
||||
filenode = nm.create_from_cap(write_uri)
|
||||
dn = dirnode.DirectoryNode(filenode, nm, None)
|
||||
unkids = dn._unpack_contents(packed)
|
||||
@ -1498,11 +1533,11 @@ class Packing(testutil.ReallyEqualMixin, unittest.TestCase):
|
||||
kids = self._make_kids(nm, ["imm", "lit", "write", "read",
|
||||
"dirwrite", "dirread"])
|
||||
packed = dirnode.pack_children(kids, fn.get_writekey(), deep_immutable=False)
|
||||
self.failUnlessIn("lit", packed)
|
||||
self.failUnlessIn(b"lit", packed)
|
||||
|
||||
kids = self._make_kids(nm, ["imm", "lit"])
|
||||
packed = dirnode.pack_children(kids, fn.get_writekey(), deep_immutable=True)
|
||||
self.failUnlessIn("lit", packed)
|
||||
self.failUnlessIn(b"lit", packed)
|
||||
|
||||
kids = self._make_kids(nm, ["imm", "lit", "write"])
|
||||
self.failUnlessRaises(dirnode.MustBeDeepImmutableError,
|
||||
@ -1528,22 +1563,22 @@ class Packing(testutil.ReallyEqualMixin, unittest.TestCase):
|
||||
@implementer(IMutableFileNode)
|
||||
class FakeMutableFile(object):
|
||||
counter = 0
|
||||
def __init__(self, initial_contents=""):
|
||||
def __init__(self, initial_contents=b""):
|
||||
data = self._get_initial_contents(initial_contents)
|
||||
self.data = data.read(data.get_size())
|
||||
self.data = "".join(self.data)
|
||||
self.data = b"".join(self.data)
|
||||
|
||||
counter = FakeMutableFile.counter
|
||||
FakeMutableFile.counter += 1
|
||||
writekey = hashutil.ssk_writekey_hash(str(counter))
|
||||
fingerprint = hashutil.ssk_pubkey_fingerprint_hash(str(counter))
|
||||
writekey = hashutil.ssk_writekey_hash(b"%d" % counter)
|
||||
fingerprint = hashutil.ssk_pubkey_fingerprint_hash(b"%d" % counter)
|
||||
self.uri = uri.WriteableSSKFileURI(writekey, fingerprint)
|
||||
|
||||
def _get_initial_contents(self, contents):
|
||||
if isinstance(contents, str):
|
||||
if isinstance(contents, bytes):
|
||||
return contents
|
||||
if contents is None:
|
||||
return ""
|
||||
return b""
|
||||
assert callable(contents), "%s should be callable, not %s" % \
|
||||
(contents, type(contents))
|
||||
return contents(self)
|
||||
@ -1561,7 +1596,7 @@ class FakeMutableFile(object):
|
||||
return defer.succeed(self.data)
|
||||
|
||||
def get_writekey(self):
|
||||
return "writekey"
|
||||
return b"writekey"
|
||||
|
||||
def is_readonly(self):
|
||||
return False
|
||||
@ -1584,7 +1619,7 @@ class FakeMutableFile(object):
|
||||
return defer.succeed(None)
|
||||
|
||||
class FakeNodeMaker(NodeMaker):
|
||||
def create_mutable_file(self, contents="", keysize=None, version=None):
|
||||
def create_mutable_file(self, contents=b"", keysize=None, version=None):
|
||||
return defer.succeed(FakeMutableFile(contents))
|
||||
|
||||
class FakeClient2(_Client):
|
||||
@ -1631,9 +1666,9 @@ class Dirnode2(testutil.ReallyEqualMixin, testutil.ShouldFailMixin, unittest.Tes
|
||||
# and to add an URI prefixed with "ro." or "imm." when it is given in a
|
||||
# write slot (or URL parameter).
|
||||
d.addCallback(lambda ign: self._node.set_uri(u"add-ro",
|
||||
"ro." + future_read_uri, None))
|
||||
b"ro." + future_read_uri, None))
|
||||
d.addCallback(lambda ign: self._node.set_uri(u"add-imm",
|
||||
"imm." + future_imm_uri, None))
|
||||
b"imm." + future_imm_uri, None))
|
||||
|
||||
d.addCallback(lambda ign: self._node.list())
|
||||
def _check(children):
|
||||
@ -1642,25 +1677,25 @@ class Dirnode2(testutil.ReallyEqualMixin, testutil.ShouldFailMixin, unittest.Tes
|
||||
self.failUnless(isinstance(fn, UnknownNode), fn)
|
||||
self.failUnlessReallyEqual(fn.get_uri(), future_write_uri)
|
||||
self.failUnlessReallyEqual(fn.get_write_uri(), future_write_uri)
|
||||
self.failUnlessReallyEqual(fn.get_readonly_uri(), "ro." + future_read_uri)
|
||||
self.failUnlessReallyEqual(fn.get_readonly_uri(), b"ro." + future_read_uri)
|
||||
|
||||
(fn2, metadata2) = children[u"add-pair"]
|
||||
self.failUnless(isinstance(fn2, UnknownNode), fn2)
|
||||
self.failUnlessReallyEqual(fn2.get_uri(), future_write_uri)
|
||||
self.failUnlessReallyEqual(fn2.get_write_uri(), future_write_uri)
|
||||
self.failUnlessReallyEqual(fn2.get_readonly_uri(), "ro." + future_read_uri)
|
||||
self.failUnlessReallyEqual(fn2.get_readonly_uri(), b"ro." + future_read_uri)
|
||||
|
||||
(fn3, metadata3) = children[u"add-ro"]
|
||||
self.failUnless(isinstance(fn3, UnknownNode), fn3)
|
||||
self.failUnlessReallyEqual(fn3.get_uri(), "ro." + future_read_uri)
|
||||
self.failUnlessReallyEqual(fn3.get_uri(), b"ro." + future_read_uri)
|
||||
self.failUnlessReallyEqual(fn3.get_write_uri(), None)
|
||||
self.failUnlessReallyEqual(fn3.get_readonly_uri(), "ro." + future_read_uri)
|
||||
self.failUnlessReallyEqual(fn3.get_readonly_uri(), b"ro." + future_read_uri)
|
||||
|
||||
(fn4, metadata4) = children[u"add-imm"]
|
||||
self.failUnless(isinstance(fn4, UnknownNode), fn4)
|
||||
self.failUnlessReallyEqual(fn4.get_uri(), "imm." + future_imm_uri)
|
||||
self.failUnlessReallyEqual(fn4.get_uri(), b"imm." + future_imm_uri)
|
||||
self.failUnlessReallyEqual(fn4.get_write_uri(), None)
|
||||
self.failUnlessReallyEqual(fn4.get_readonly_uri(), "imm." + future_imm_uri)
|
||||
self.failUnlessReallyEqual(fn4.get_readonly_uri(), b"imm." + future_imm_uri)
|
||||
|
||||
# We should also be allowed to copy the "future" UnknownNode, because
|
||||
# it contains all the information that was in the original directory
|
||||
@ -1675,17 +1710,17 @@ class Dirnode2(testutil.ReallyEqualMixin, testutil.ShouldFailMixin, unittest.Tes
|
||||
self.failUnless(isinstance(fn, UnknownNode), fn)
|
||||
self.failUnlessReallyEqual(fn.get_uri(), future_write_uri)
|
||||
self.failUnlessReallyEqual(fn.get_write_uri(), future_write_uri)
|
||||
self.failUnlessReallyEqual(fn.get_readonly_uri(), "ro." + future_read_uri)
|
||||
self.failUnlessReallyEqual(fn.get_readonly_uri(), b"ro." + future_read_uri)
|
||||
d.addCallback(_check2)
|
||||
return d
|
||||
|
||||
def test_unknown_strip_prefix_for_ro(self):
|
||||
self.failUnlessReallyEqual(strip_prefix_for_ro("foo", False), "foo")
|
||||
self.failUnlessReallyEqual(strip_prefix_for_ro("ro.foo", False), "foo")
|
||||
self.failUnlessReallyEqual(strip_prefix_for_ro("imm.foo", False), "imm.foo")
|
||||
self.failUnlessReallyEqual(strip_prefix_for_ro("foo", True), "foo")
|
||||
self.failUnlessReallyEqual(strip_prefix_for_ro("ro.foo", True), "foo")
|
||||
self.failUnlessReallyEqual(strip_prefix_for_ro("imm.foo", True), "foo")
|
||||
self.failUnlessReallyEqual(strip_prefix_for_ro(b"foo", False), b"foo")
|
||||
self.failUnlessReallyEqual(strip_prefix_for_ro(b"ro.foo", False), b"foo")
|
||||
self.failUnlessReallyEqual(strip_prefix_for_ro(b"imm.foo", False), b"imm.foo")
|
||||
self.failUnlessReallyEqual(strip_prefix_for_ro(b"foo", True), b"foo")
|
||||
self.failUnlessReallyEqual(strip_prefix_for_ro(b"ro.foo", True), b"foo")
|
||||
self.failUnlessReallyEqual(strip_prefix_for_ro(b"imm.foo", True), b"foo")
|
||||
|
||||
def test_unknownnode(self):
|
||||
lit_uri = one_uri
|
||||
@ -1697,58 +1732,58 @@ class Dirnode2(testutil.ReallyEqualMixin, testutil.ShouldFailMixin, unittest.Tes
|
||||
]
|
||||
unknown_rw = [# These are errors because we're only given a rw_uri, and we can't
|
||||
# diminish it.
|
||||
( 2, UnknownNode("foo", None)),
|
||||
( 3, UnknownNode("foo", None, deep_immutable=True)),
|
||||
( 4, UnknownNode("ro.foo", None, deep_immutable=True)),
|
||||
( 5, UnknownNode("ro." + mut_read_uri, None, deep_immutable=True)),
|
||||
( 5.1, UnknownNode("ro." + mdmf_read_uri, None, deep_immutable=True)),
|
||||
( 6, UnknownNode("URI:SSK-RO:foo", None, deep_immutable=True)),
|
||||
( 7, UnknownNode("URI:SSK:foo", None)),
|
||||
( 2, UnknownNode(b"foo", None)),
|
||||
( 3, UnknownNode(b"foo", None, deep_immutable=True)),
|
||||
( 4, UnknownNode(b"ro.foo", None, deep_immutable=True)),
|
||||
( 5, UnknownNode(b"ro." + mut_read_uri, None, deep_immutable=True)),
|
||||
( 5.1, UnknownNode(b"ro." + mdmf_read_uri, None, deep_immutable=True)),
|
||||
( 6, UnknownNode(b"URI:SSK-RO:foo", None, deep_immutable=True)),
|
||||
( 7, UnknownNode(b"URI:SSK:foo", None)),
|
||||
]
|
||||
must_be_ro = [# These are errors because a readonly constraint is not met.
|
||||
( 8, UnknownNode("ro." + mut_write_uri, None)),
|
||||
( 8.1, UnknownNode("ro." + mdmf_write_uri, None)),
|
||||
( 9, UnknownNode(None, "ro." + mut_write_uri)),
|
||||
( 9.1, UnknownNode(None, "ro." + mdmf_write_uri)),
|
||||
( 8, UnknownNode(b"ro." + mut_write_uri, None)),
|
||||
( 8.1, UnknownNode(b"ro." + mdmf_write_uri, None)),
|
||||
( 9, UnknownNode(None, b"ro." + mut_write_uri)),
|
||||
( 9.1, UnknownNode(None, b"ro." + mdmf_write_uri)),
|
||||
]
|
||||
must_be_imm = [# These are errors because an immutable constraint is not met.
|
||||
(10, UnknownNode(None, "ro.URI:SSK-RO:foo", deep_immutable=True)),
|
||||
(11, UnknownNode(None, "imm.URI:SSK:foo")),
|
||||
(12, UnknownNode(None, "imm.URI:SSK-RO:foo")),
|
||||
(13, UnknownNode("bar", "ro.foo", deep_immutable=True)),
|
||||
(14, UnknownNode("bar", "imm.foo", deep_immutable=True)),
|
||||
(15, UnknownNode("bar", "imm." + lit_uri, deep_immutable=True)),
|
||||
(16, UnknownNode("imm." + mut_write_uri, None)),
|
||||
(16.1, UnknownNode("imm." + mdmf_write_uri, None)),
|
||||
(17, UnknownNode("imm." + mut_read_uri, None)),
|
||||
(17.1, UnknownNode("imm." + mdmf_read_uri, None)),
|
||||
(18, UnknownNode("bar", "imm.foo")),
|
||||
(10, UnknownNode(None, b"ro.URI:SSK-RO:foo", deep_immutable=True)),
|
||||
(11, UnknownNode(None, b"imm.URI:SSK:foo")),
|
||||
(12, UnknownNode(None, b"imm.URI:SSK-RO:foo")),
|
||||
(13, UnknownNode(b"bar", b"ro.foo", deep_immutable=True)),
|
||||
(14, UnknownNode(b"bar", b"imm.foo", deep_immutable=True)),
|
||||
(15, UnknownNode(b"bar", b"imm." + lit_uri, deep_immutable=True)),
|
||||
(16, UnknownNode(b"imm." + mut_write_uri, None)),
|
||||
(16.1, UnknownNode(b"imm." + mdmf_write_uri, None)),
|
||||
(17, UnknownNode(b"imm." + mut_read_uri, None)),
|
||||
(17.1, UnknownNode(b"imm." + mdmf_read_uri, None)),
|
||||
(18, UnknownNode(b"bar", b"imm.foo")),
|
||||
]
|
||||
bad_uri = [# These are errors because the URI is bad once we've stripped the prefix.
|
||||
(19, UnknownNode("ro.URI:SSK-RO:foo", None)),
|
||||
(20, UnknownNode("imm.URI:CHK:foo", None, deep_immutable=True)),
|
||||
(21, UnknownNode(None, "URI:CHK:foo")),
|
||||
(22, UnknownNode(None, "URI:CHK:foo", deep_immutable=True)),
|
||||
(19, UnknownNode(b"ro.URI:SSK-RO:foo", None)),
|
||||
(20, UnknownNode(b"imm.URI:CHK:foo", None, deep_immutable=True)),
|
||||
(21, UnknownNode(None, b"URI:CHK:foo")),
|
||||
(22, UnknownNode(None, b"URI:CHK:foo", deep_immutable=True)),
|
||||
]
|
||||
ro_prefixed = [# These are valid, and the readcap should end up with a ro. prefix.
|
||||
(23, UnknownNode(None, "foo")),
|
||||
(24, UnknownNode(None, "ro.foo")),
|
||||
(25, UnknownNode(None, "ro." + lit_uri)),
|
||||
(26, UnknownNode("bar", "foo")),
|
||||
(27, UnknownNode("bar", "ro.foo")),
|
||||
(28, UnknownNode("bar", "ro." + lit_uri)),
|
||||
(29, UnknownNode("ro.foo", None)),
|
||||
(30, UnknownNode("ro." + lit_uri, None)),
|
||||
(23, UnknownNode(None, b"foo")),
|
||||
(24, UnknownNode(None, b"ro.foo")),
|
||||
(25, UnknownNode(None, b"ro." + lit_uri)),
|
||||
(26, UnknownNode(b"bar", b"foo")),
|
||||
(27, UnknownNode(b"bar", b"ro.foo")),
|
||||
(28, UnknownNode(b"bar", b"ro." + lit_uri)),
|
||||
(29, UnknownNode(b"ro.foo", None)),
|
||||
(30, UnknownNode(b"ro." + lit_uri, None)),
|
||||
]
|
||||
imm_prefixed = [# These are valid, and the readcap should end up with an imm. prefix.
|
||||
(31, UnknownNode(None, "foo", deep_immutable=True)),
|
||||
(32, UnknownNode(None, "ro.foo", deep_immutable=True)),
|
||||
(33, UnknownNode(None, "imm.foo")),
|
||||
(34, UnknownNode(None, "imm.foo", deep_immutable=True)),
|
||||
(35, UnknownNode("imm." + lit_uri, None)),
|
||||
(36, UnknownNode("imm." + lit_uri, None, deep_immutable=True)),
|
||||
(37, UnknownNode(None, "imm." + lit_uri)),
|
||||
(38, UnknownNode(None, "imm." + lit_uri, deep_immutable=True)),
|
||||
(31, UnknownNode(None, b"foo", deep_immutable=True)),
|
||||
(32, UnknownNode(None, b"ro.foo", deep_immutable=True)),
|
||||
(33, UnknownNode(None, b"imm.foo")),
|
||||
(34, UnknownNode(None, b"imm.foo", deep_immutable=True)),
|
||||
(35, UnknownNode(b"imm." + lit_uri, None)),
|
||||
(36, UnknownNode(b"imm." + lit_uri, None, deep_immutable=True)),
|
||||
(37, UnknownNode(None, b"imm." + lit_uri)),
|
||||
(38, UnknownNode(None, b"imm." + lit_uri, deep_immutable=True)),
|
||||
]
|
||||
error = unknown_rw + must_be_ro + must_be_imm + bad_uri
|
||||
ok = ro_prefixed + imm_prefixed
|
||||
@ -1780,10 +1815,10 @@ class Dirnode2(testutil.ReallyEqualMixin, testutil.ShouldFailMixin, unittest.Tes
|
||||
self.failIf(n.get_readonly_uri() is None, i)
|
||||
|
||||
for (i, n) in ro_prefixed:
|
||||
self.failUnless(n.get_readonly_uri().startswith("ro."), i)
|
||||
self.failUnless(n.get_readonly_uri().startswith(b"ro."), i)
|
||||
|
||||
for (i, n) in imm_prefixed:
|
||||
self.failUnless(n.get_readonly_uri().startswith("imm."), i)
|
||||
self.failUnless(n.get_readonly_uri().startswith(b"imm."), i)
|
||||
|
||||
|
||||
|
||||
@ -1867,7 +1902,7 @@ class Deleter(GridTestMixin, testutil.ReallyEqualMixin, unittest.TestCase):
|
||||
self.set_up_grid(oneshare=True)
|
||||
c0 = self.g.clients[0]
|
||||
d = c0.create_dirnode()
|
||||
small = upload.Data("Small enough for a LIT", None)
|
||||
small = upload.Data(b"Small enough for a LIT", None)
|
||||
def _created_dir(dn):
|
||||
self.root = dn
|
||||
self.root_uri = dn.get_uri()
|
||||
@ -1909,10 +1944,10 @@ class Adder(GridTestMixin, unittest.TestCase, testutil.ShouldFailMixin):
|
||||
# root/file1
|
||||
# root/file2
|
||||
# root/dir1
|
||||
d = root_node.add_file(u'file1', upload.Data("Important Things",
|
||||
d = root_node.add_file(u'file1', upload.Data(b"Important Things",
|
||||
None))
|
||||
d.addCallback(lambda res:
|
||||
root_node.add_file(u'file2', upload.Data("Sekrit Codes", None)))
|
||||
root_node.add_file(u'file2', upload.Data(b"Sekrit Codes", None)))
|
||||
d.addCallback(lambda res:
|
||||
root_node.create_subdirectory(u"dir1"))
|
||||
d.addCallback(lambda res: root_node)
|
||||
|
@ -31,8 +31,8 @@ class UnknownNode(object):
|
||||
|
||||
def __init__(self, given_rw_uri, given_ro_uri, deep_immutable=False,
|
||||
name=u"<unknown name>"):
|
||||
assert given_rw_uri is None or isinstance(given_rw_uri, str)
|
||||
assert given_ro_uri is None or isinstance(given_ro_uri, str)
|
||||
assert given_rw_uri is None or isinstance(given_rw_uri, bytes)
|
||||
assert given_ro_uri is None or isinstance(given_ro_uri, bytes)
|
||||
given_rw_uri = given_rw_uri or None
|
||||
given_ro_uri = given_ro_uri or None
|
||||
|
||||
@ -182,3 +182,11 @@ class UnknownNode(object):
|
||||
|
||||
def check_and_repair(self, monitor, verify, add_lease):
|
||||
return defer.succeed(None)
|
||||
|
||||
def __eq__(self, other):
|
||||
if not isinstance(other, UnknownNode):
|
||||
return False
|
||||
return other.ro_uri == self.ro_uri and other.rw_uri == self.rw_uri
|
||||
|
||||
def __ne__(self, other):
|
||||
return not (self == other)
|
||||
|
@ -34,6 +34,7 @@ PORTED_MODULES = [
|
||||
"allmydata.crypto.error",
|
||||
"allmydata.crypto.rsa",
|
||||
"allmydata.crypto.util",
|
||||
"allmydata.dirnode",
|
||||
"allmydata.hashtree",
|
||||
"allmydata.immutable.checker",
|
||||
"allmydata.immutable.downloader",
|
||||
@ -67,6 +68,7 @@ PORTED_MODULES = [
|
||||
"allmydata.mutable.retrieve",
|
||||
"allmydata.mutable.servermap",
|
||||
"allmydata.node",
|
||||
"allmydata.nodemaker",
|
||||
"allmydata.storage_client",
|
||||
"allmydata.storage.common",
|
||||
"allmydata.storage.crawler",
|
||||
@ -136,6 +138,7 @@ PORTED_TEST_MODULES = [
|
||||
"allmydata.test.test_crypto",
|
||||
"allmydata.test.test_deferredutil",
|
||||
"allmydata.test.test_dictutil",
|
||||
"allmydata.test.test_dirnode",
|
||||
"allmydata.test.test_download",
|
||||
"allmydata.test.test_encode",
|
||||
"allmydata.test.test_encodingutil",
|
||||
|
Loading…
Reference in New Issue
Block a user