All tests pass on Python 3.
This commit is contained in:
parent
cc176342d4
commit
07b58e3619
|
@ -5,7 +5,8 @@ from past.builtins import unicode
|
||||||
import os.path
|
import os.path
|
||||||
from urllib.parse import quote as url_quote
|
from urllib.parse import quote as url_quote
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from six.moves import cStringIO as StringIO
|
from io import BytesIO
|
||||||
|
|
||||||
from twisted.python.failure import Failure
|
from twisted.python.failure import Failure
|
||||||
from allmydata.scripts.common import get_alias, escape_path, \
|
from allmydata.scripts.common import get_alias, escape_path, \
|
||||||
DefaultAliasMarker, TahoeError
|
DefaultAliasMarker, TahoeError
|
||||||
|
@ -200,13 +201,21 @@ class TahoeFileSource(object):
|
||||||
|
|
||||||
def open(self, caps_only):
|
def open(self, caps_only):
|
||||||
if caps_only:
|
if caps_only:
|
||||||
return StringIO(self.readcap)
|
return BytesIO(self.readcap)
|
||||||
url = self.nodeurl + "uri/" + url_quote(self.readcap)
|
url = self.nodeurl + "uri/" + url_quote(self.readcap)
|
||||||
return GET_to_file(url)
|
return GET_to_file(url)
|
||||||
|
|
||||||
def bestcap(self):
|
def bestcap(self):
|
||||||
return self.writecap or self.readcap
|
return self.writecap or self.readcap
|
||||||
|
|
||||||
|
|
||||||
|
def seekable(file_like):
|
||||||
|
"""Return whether the file-like object is seekable."""
|
||||||
|
return hasattr(file_like, "seek") and (
|
||||||
|
not hasattr(file_like, "seekable") or file_like.seekable()
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class TahoeFileTarget(object):
|
class TahoeFileTarget(object):
|
||||||
def __init__(self, nodeurl, mutable, writecap, readcap, url):
|
def __init__(self, nodeurl, mutable, writecap, readcap, url):
|
||||||
self.nodeurl = nodeurl
|
self.nodeurl = nodeurl
|
||||||
|
@ -220,7 +229,7 @@ class TahoeFileTarget(object):
|
||||||
assert self.url
|
assert self.url
|
||||||
# our do_http() call currently requires a string or a filehandle with
|
# our do_http() call currently requires a string or a filehandle with
|
||||||
# a real .seek
|
# a real .seek
|
||||||
if not hasattr(inf, "seek"):
|
if not seekable(inf):
|
||||||
inf = inf.read()
|
inf = inf.read()
|
||||||
PUT(self.url, inf)
|
PUT(self.url, inf)
|
||||||
# TODO: this always creates immutable files. We might want an option
|
# TODO: this always creates immutable files. We might want an option
|
||||||
|
@ -306,7 +315,7 @@ class TahoeMissingTarget(object):
|
||||||
|
|
||||||
def put_file(self, inf):
|
def put_file(self, inf):
|
||||||
# We want to replace this object in-place.
|
# We want to replace this object in-place.
|
||||||
if not hasattr(inf, "seek"):
|
if not seekable(inf):
|
||||||
inf = inf.read()
|
inf = inf.read()
|
||||||
PUT(self.url, inf)
|
PUT(self.url, inf)
|
||||||
# TODO: this always creates immutable files. We might want an option
|
# TODO: this always creates immutable files. We might want an option
|
||||||
|
@ -417,7 +426,7 @@ class TahoeDirectoryTarget(object):
|
||||||
def put_file(self, name, inf):
|
def put_file(self, name, inf):
|
||||||
precondition(isinstance(name, unicode), name)
|
precondition(isinstance(name, unicode), name)
|
||||||
url = self.nodeurl + "uri"
|
url = self.nodeurl + "uri"
|
||||||
if not hasattr(inf, "seek"):
|
if not seekable(inf):
|
||||||
inf = inf.read()
|
inf = inf.read()
|
||||||
|
|
||||||
if self.children is None:
|
if self.children is None:
|
||||||
|
|
|
@ -2579,7 +2579,7 @@ class SystemTest(SystemTestMixin, RunBinTahoeMixin, unittest.TestCase):
|
||||||
(out, err) = out_and_err
|
(out, err) = out_and_err
|
||||||
x = open(os.path.join(dn_copy2, "dir1", "subdir2", "rfile4")).read()
|
x = open(os.path.join(dn_copy2, "dir1", "subdir2", "rfile4")).read()
|
||||||
y = uri.from_string_filenode(x)
|
y = uri.from_string_filenode(x)
|
||||||
self.failUnlessEqual(y.data, "rfile4")
|
self.failUnlessEqual(y.data, b"rfile4")
|
||||||
d.addCallback(_check_capsonly)
|
d.addCallback(_check_capsonly)
|
||||||
|
|
||||||
# and tahoe-to-tahoe
|
# and tahoe-to-tahoe
|
||||||
|
|
Loading…
Reference in New Issue