mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-02-20 17:52:50 +00:00
More tests passing on Python 3.
This commit is contained in:
parent
2007323baa
commit
e5a7ea97c7
@ -2817,7 +2817,7 @@ class Web(WebMixin, WebErrorMixin, testutil.StallMixin, testutil.ReallyEqualMixi
|
||||
else:
|
||||
# for immutable, it returns an "upload results page", and
|
||||
# the filecap is buried inside
|
||||
line = [l for l in results.split("\n") if "URI: " in l][0]
|
||||
line = [l for l in results.split(b"\n") if b"URI: " in l][0]
|
||||
mo = re.search(r'<span>([^<]+)</span>', line)
|
||||
filecap = mo.group(1)
|
||||
self.failUnless(filecap.startswith(uri_prefix),
|
||||
@ -2868,10 +2868,10 @@ class Web(WebMixin, WebErrorMixin, testutil.StallMixin, testutil.ReallyEqualMixi
|
||||
return d
|
||||
|
||||
d = defer.succeed(None)
|
||||
d.addCallback(_check_upload, "chk", "URI:CHK")
|
||||
d.addCallback(_check_upload, "sdmf", "URI:SSK", self._foo_node)
|
||||
d.addCallback(_check_upload, "mdmf", "URI:MDMF")
|
||||
d.addCallback(_check_upload, "MDMF", "URI:MDMF")
|
||||
d.addCallback(_check_upload, "chk", b"URI:CHK")
|
||||
d.addCallback(_check_upload, "sdmf", b"URI:SSK", self._foo_node)
|
||||
d.addCallback(_check_upload, "mdmf", b"URI:MDMF")
|
||||
d.addCallback(_check_upload, "MDMF", b"URI:MDMF")
|
||||
return d
|
||||
|
||||
@inlineCallbacks
|
||||
@ -3776,7 +3776,7 @@ class Web(WebMixin, WebErrorMixin, testutil.StallMixin, testutil.ReallyEqualMixi
|
||||
contents10, n10, newuri10 = self.makefile(10)
|
||||
contents11, n11, newuri11 = self.makefile(11)
|
||||
|
||||
reqbody = """{
|
||||
reqbody = b"""{
|
||||
"atomic_added_1": [ "filenode", { "rw_uri": "%s",
|
||||
"size": 0,
|
||||
"metadata": {
|
||||
|
@ -1,3 +1,11 @@
|
||||
"""
|
||||
TODO: When porting to Python 3, the filename handling logic seems wrong. On
|
||||
Python 3 filename will _already_ be correctly decoded. So only decode if it's
|
||||
bytes.
|
||||
|
||||
Also there's a lot of code duplication I think.
|
||||
"""
|
||||
|
||||
from past.builtins import unicode
|
||||
|
||||
from urllib.parse import quote as url_quote
|
||||
@ -364,7 +372,7 @@ class DirectoryNodeHandler(ReplaceMeMixin, Resource, object):
|
||||
return d
|
||||
|
||||
def _POST_upload(self, req):
|
||||
charset = unicode(get_arg(req, "_charset", b"utf-8"))
|
||||
charset = unicode(get_arg(req, "_charset", b"utf-8"), "utf-8")
|
||||
contents = req.fields["file"]
|
||||
assert contents.filename is None or isinstance(contents.filename, str)
|
||||
name = get_arg(req, "name")
|
||||
@ -374,8 +382,8 @@ class DirectoryNodeHandler(ReplaceMeMixin, Resource, object):
|
||||
if not name:
|
||||
# this prohibts empty, missing, and all-whitespace filenames
|
||||
raise WebError("upload requires a name")
|
||||
assert isinstance(name, str)
|
||||
name = name.decode(charset)
|
||||
if isinstance(name, bytes):
|
||||
name = name.decode(charset)
|
||||
if "/" in name:
|
||||
raise WebError("name= may not contain a slash", http.BAD_REQUEST)
|
||||
assert isinstance(name, unicode)
|
||||
@ -624,14 +632,14 @@ class DirectoryNodeHandler(ReplaceMeMixin, Resource, object):
|
||||
# TODO test handling of bad JSON
|
||||
raise
|
||||
cs = {}
|
||||
for name, (file_or_dir, mddict) in children.iteritems():
|
||||
for name, (file_or_dir, mddict) in children.items():
|
||||
name = unicode(name) # json returns str *or* unicode
|
||||
writecap = mddict.get('rw_uri')
|
||||
if writecap is not None:
|
||||
writecap = str(writecap)
|
||||
writecap = writecap.encode("utf-8")
|
||||
readcap = mddict.get('ro_uri')
|
||||
if readcap is not None:
|
||||
readcap = str(readcap)
|
||||
readcap = readcap.encode("utf-8")
|
||||
cs[name] = (writecap, readcap, mddict.get('metadata'))
|
||||
d = self.node.set_children(cs, replace)
|
||||
d.addCallback(lambda res: "Okay so I did it.")
|
||||
|
@ -1,3 +1,4 @@
|
||||
from past.builtins import unicode
|
||||
|
||||
from urllib.parse import quote as urlquote
|
||||
|
||||
@ -118,8 +119,8 @@ class UploadResultsElement(status.UploadResultsRendererMixin):
|
||||
def download_link(self, req, tag):
|
||||
d = self.upload_results()
|
||||
d.addCallback(lambda res:
|
||||
tags.a("/uri/" + res.get_uri(),
|
||||
href="/uri/" + urlquote(res.get_uri())))
|
||||
tags.a("/uri/" + unicode(res.get_uri(), "utf-8"),
|
||||
href="/uri/" + urlquote(unicode(res.get_uri(), "utf-8"))))
|
||||
return d
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user