More passing Python 3 tests.
This commit is contained in:
parent
59847edf9c
commit
58745fd373
|
@ -3,7 +3,6 @@ from __future__ import print_function
|
||||||
from past.builtins import unicode
|
from past.builtins import unicode
|
||||||
|
|
||||||
import os.path, re, time
|
import os.path, re, time
|
||||||
import json
|
|
||||||
import treq
|
import treq
|
||||||
from urllib.parse import quote as urlquote, unquote as urlunquote
|
from urllib.parse import quote as urlquote, unquote as urlunquote
|
||||||
|
|
||||||
|
@ -26,7 +25,7 @@ from allmydata.immutable.downloader.status import DownloadStatus
|
||||||
from allmydata.dirnode import DirectoryNode
|
from allmydata.dirnode import DirectoryNode
|
||||||
from allmydata.nodemaker import NodeMaker
|
from allmydata.nodemaker import NodeMaker
|
||||||
from allmydata.web.common import MultiFormatResource
|
from allmydata.web.common import MultiFormatResource
|
||||||
from allmydata.util import fileutil, base32, hashutil
|
from allmydata.util import fileutil, base32, hashutil, jsonbytes as json
|
||||||
from allmydata.util.consumer import download_to_data
|
from allmydata.util.consumer import download_to_data
|
||||||
from allmydata.util.encodingutil import to_bytes
|
from allmydata.util.encodingutil import to_bytes
|
||||||
from ...util.connection_status import ConnectionStatus
|
from ...util.connection_status import ConnectionStatus
|
||||||
|
@ -1465,19 +1464,19 @@ class Web(WebMixin, WebErrorMixin, testutil.StallMixin, testutil.ReallyEqualMixi
|
||||||
return d
|
return d
|
||||||
|
|
||||||
def test_GET_FILE_URI_mdmf_extensions(self):
|
def test_GET_FILE_URI_mdmf_extensions(self):
|
||||||
base = "/uri/%s" % urlquote("%s:RANDOMSTUFF" % self._quux_txt_uri)
|
base = "/uri/%s" % urlquote("%s:RANDOMSTUFF" % unicode(self._quux_txt_uri, "ascii"))
|
||||||
d = self.GET(base)
|
d = self.GET(base)
|
||||||
d.addCallback(self.failUnlessIsQuuxDotTxt)
|
d.addCallback(self.failUnlessIsQuuxDotTxt)
|
||||||
return d
|
return d
|
||||||
|
|
||||||
def test_GET_FILE_URI_mdmf_readonly(self):
|
def test_GET_FILE_URI_mdmf_readonly(self):
|
||||||
base = "/uri/%s" % urlquote(self._quux_txt_readonly_uri)
|
base = "/uri/%s" % urlquote(unicode(self._quux_txt_readonly_uri, "ascii"))
|
||||||
d = self.GET(base)
|
d = self.GET(base)
|
||||||
d.addCallback(self.failUnlessIsQuuxDotTxt)
|
d.addCallback(self.failUnlessIsQuuxDotTxt)
|
||||||
return d
|
return d
|
||||||
|
|
||||||
def test_GET_FILE_URI_badchild(self):
|
def test_GET_FILE_URI_badchild(self):
|
||||||
base = "/uri/%s/boguschild" % urlquote(self._bar_txt_uri)
|
base = "/uri/%s/boguschild" % urlquote(unicode(self._bar_txt_uri, "ascii"))
|
||||||
errmsg = "Files have no children named 'boguschild'"
|
errmsg = "Files have no children named 'boguschild'"
|
||||||
d = self.shouldFail2(error.Error, "test_GET_FILE_URI_badchild",
|
d = self.shouldFail2(error.Error, "test_GET_FILE_URI_badchild",
|
||||||
"400 Bad Request", errmsg,
|
"400 Bad Request", errmsg,
|
||||||
|
@ -1485,7 +1484,7 @@ class Web(WebMixin, WebErrorMixin, testutil.StallMixin, testutil.ReallyEqualMixi
|
||||||
return d
|
return d
|
||||||
|
|
||||||
def test_PUT_FILE_URI_badchild(self):
|
def test_PUT_FILE_URI_badchild(self):
|
||||||
base = "/uri/%s/boguschild" % urlquote(self._bar_txt_uri)
|
base = "/uri/%s/boguschild" % urlquote(unicode(self._bar_txt_uri, "ascii"))
|
||||||
errmsg = "Cannot create directory 'boguschild', because its parent is a file, not a directory"
|
errmsg = "Cannot create directory 'boguschild', because its parent is a file, not a directory"
|
||||||
d = self.shouldFail2(error.Error, "test_GET_FILE_URI_badchild",
|
d = self.shouldFail2(error.Error, "test_GET_FILE_URI_badchild",
|
||||||
"409 Conflict", errmsg,
|
"409 Conflict", errmsg,
|
||||||
|
@ -1493,7 +1492,7 @@ class Web(WebMixin, WebErrorMixin, testutil.StallMixin, testutil.ReallyEqualMixi
|
||||||
return d
|
return d
|
||||||
|
|
||||||
def test_PUT_FILE_URI_mdmf(self):
|
def test_PUT_FILE_URI_mdmf(self):
|
||||||
base = "/uri/%s" % urlquote(self._quux_txt_uri)
|
base = "/uri/%s" % urlquote(unicode(self._quux_txt_uri, "ascii"))
|
||||||
self._quux_new_contents = "new_contents"
|
self._quux_new_contents = "new_contents"
|
||||||
d = self.GET(base)
|
d = self.GET(base)
|
||||||
d.addCallback(lambda res:
|
d.addCallback(lambda res:
|
||||||
|
@ -1507,8 +1506,8 @@ class Web(WebMixin, WebErrorMixin, testutil.StallMixin, testutil.ReallyEqualMixi
|
||||||
return d
|
return d
|
||||||
|
|
||||||
def test_PUT_FILE_URI_mdmf_extensions(self):
|
def test_PUT_FILE_URI_mdmf_extensions(self):
|
||||||
base = "/uri/%s" % urlquote("%s:EXTENSIONSTUFF" % self._quux_txt_uri)
|
base = "/uri/%s" % urlquote("%s:EXTENSIONSTUFF" % unicode(self._quux_txt_uri, "ascii"))
|
||||||
self._quux_new_contents = "new_contents"
|
self._quux_new_contents = b"new_contents"
|
||||||
d = self.GET(base)
|
d = self.GET(base)
|
||||||
d.addCallback(lambda res: self.failUnlessIsQuuxDotTxt(res))
|
d.addCallback(lambda res: self.failUnlessIsQuuxDotTxt(res))
|
||||||
d.addCallback(lambda ignored: self.PUT(base, self._quux_new_contents))
|
d.addCallback(lambda ignored: self.PUT(base, self._quux_new_contents))
|
||||||
|
@ -1519,7 +1518,7 @@ class Web(WebMixin, WebErrorMixin, testutil.StallMixin, testutil.ReallyEqualMixi
|
||||||
|
|
||||||
def test_PUT_FILE_URI_mdmf_readonly(self):
|
def test_PUT_FILE_URI_mdmf_readonly(self):
|
||||||
# We're not allowed to PUT things to a readonly cap.
|
# We're not allowed to PUT things to a readonly cap.
|
||||||
base = "/uri/%s" % self._quux_txt_readonly_uri
|
base = "/uri/%s" % unicode(self._quux_txt_readonly_uri, "ascii")
|
||||||
d = self.GET(base)
|
d = self.GET(base)
|
||||||
d.addCallback(lambda res:
|
d.addCallback(lambda res:
|
||||||
self.failUnlessIsQuuxDotTxt(res))
|
self.failUnlessIsQuuxDotTxt(res))
|
||||||
|
@ -1532,7 +1531,7 @@ class Web(WebMixin, WebErrorMixin, testutil.StallMixin, testutil.ReallyEqualMixi
|
||||||
|
|
||||||
def test_PUT_FILE_URI_sdmf_readonly(self):
|
def test_PUT_FILE_URI_sdmf_readonly(self):
|
||||||
# We're not allowed to put things to a readonly cap.
|
# We're not allowed to put things to a readonly cap.
|
||||||
base = "/uri/%s" % self._baz_txt_readonly_uri
|
base = "/uri/%s" % unicode(self._baz_txt_readonly_uri, "ascii")
|
||||||
d = self.GET(base)
|
d = self.GET(base)
|
||||||
d.addCallback(lambda res:
|
d.addCallback(lambda res:
|
||||||
self.failUnlessIsBazDotTxt(res))
|
self.failUnlessIsBazDotTxt(res))
|
||||||
|
@ -1583,7 +1582,7 @@ class Web(WebMixin, WebErrorMixin, testutil.StallMixin, testutil.ReallyEqualMixi
|
||||||
|
|
||||||
# use the ETag on GET
|
# use the ETag on GET
|
||||||
def _check_match(ign):
|
def _check_match(ign):
|
||||||
uri = "/uri/%s" % self._bar_txt_uri
|
uri = "/uri/%s" % unicode(self._bar_txt_uri, "ascii")
|
||||||
d = self.GET(uri, return_response=True)
|
d = self.GET(uri, return_response=True)
|
||||||
# extract the ETag
|
# extract the ETag
|
||||||
d.addCallback(lambda data_code_headers:
|
d.addCallback(lambda data_code_headers:
|
||||||
|
@ -4265,12 +4264,12 @@ class Web(WebMixin, WebErrorMixin, testutil.StallMixin, testutil.ReallyEqualMixi
|
||||||
self.assertIn(response.code, codes)
|
self.assertIn(response.code, codes)
|
||||||
location = response.headers.getRawHeaders(b"location")[0]
|
location = response.headers.getRawHeaders(b"location")[0]
|
||||||
if target_location is not None:
|
if target_location is not None:
|
||||||
self.assertEquals(location, target_location)
|
self.assertEquals(unicode(location, "ascii"), target_location)
|
||||||
returnValue(location)
|
returnValue(location)
|
||||||
|
|
||||||
@inlineCallbacks
|
@inlineCallbacks
|
||||||
def test_GET_URI_form(self):
|
def test_GET_URI_form(self):
|
||||||
relbase = "/uri?uri=%s" % self._bar_txt_uri
|
relbase = "/uri?uri=%s" % unicode(self._bar_txt_uri, "ascii")
|
||||||
base = self.webish_url + relbase
|
base = self.webish_url + relbase
|
||||||
# this is supposed to give us a redirect to /uri/$URI, plus arguments
|
# this is supposed to give us a redirect to /uri/$URI, plus arguments
|
||||||
targetbase = self.webish_url + "/uri/%s" % urlquote(self._bar_txt_uri)
|
targetbase = self.webish_url + "/uri/%s" % urlquote(self._bar_txt_uri)
|
||||||
|
@ -4284,7 +4283,7 @@ class Web(WebMixin, WebErrorMixin, testutil.StallMixin, testutil.ReallyEqualMixi
|
||||||
data = yield self.GET(relbase, followRedirect=True)
|
data = yield self.GET(relbase, followRedirect=True)
|
||||||
self.failUnlessIsBarDotTxt(data)
|
self.failUnlessIsBarDotTxt(data)
|
||||||
self.log(None, "got file by uri, about to get dir by uri")
|
self.log(None, "got file by uri, about to get dir by uri")
|
||||||
data = yield self.GET("/uri?uri=%s&t=json" % self._foo_uri,
|
data = yield self.GET("/uri?uri=%s&t=json" % unicode(self._foo_uri, "ascii"),
|
||||||
followRedirect=True)
|
followRedirect=True)
|
||||||
self.failUnlessIsFooJSON(data)
|
self.failUnlessIsFooJSON(data)
|
||||||
self.log(None, "got dir by uri")
|
self.log(None, "got dir by uri")
|
||||||
|
@ -4318,7 +4317,7 @@ class Web(WebMixin, WebErrorMixin, testutil.StallMixin, testutil.ReallyEqualMixi
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def test_GET_URI_URL(self):
|
def test_GET_URI_URL(self):
|
||||||
base = "/uri/%s" % self._bar_txt_uri
|
base = "/uri/%s" % unicode(self._bar_txt_uri, "ascii")
|
||||||
d = self.GET(base)
|
d = self.GET(base)
|
||||||
d.addCallback(self.failUnlessIsBarDotTxt)
|
d.addCallback(self.failUnlessIsBarDotTxt)
|
||||||
d.addCallback(lambda res: self.GET(base+"?filename=bar.txt"))
|
d.addCallback(lambda res: self.GET(base+"?filename=bar.txt"))
|
||||||
|
@ -4328,14 +4327,14 @@ class Web(WebMixin, WebErrorMixin, testutil.StallMixin, testutil.ReallyEqualMixi
|
||||||
return d
|
return d
|
||||||
|
|
||||||
def test_GET_URI_URL_dir(self):
|
def test_GET_URI_URL_dir(self):
|
||||||
base = "/uri/%s?t=json" % self._foo_uri
|
base = "/uri/%s?t=json" % unicode(self._foo_uri, "ascii")
|
||||||
d = self.GET(base)
|
d = self.GET(base)
|
||||||
d.addCallback(self.failUnlessIsFooJSON)
|
d.addCallback(self.failUnlessIsFooJSON)
|
||||||
return d
|
return d
|
||||||
|
|
||||||
@inlineCallbacks
|
@inlineCallbacks
|
||||||
def test_GET_URI_URL_missing(self):
|
def test_GET_URI_URL_missing(self):
|
||||||
base = "/uri/%s" % self._bad_file_uri
|
base = "/uri/%s" % unicode(self._bad_file_uri, "ascii")
|
||||||
url = self.webish_url + base
|
url = self.webish_url + base
|
||||||
yield self.assertHTTPError(url, http.GONE, "NotEnoughSharesError")
|
yield self.assertHTTPError(url, http.GONE, "NotEnoughSharesError")
|
||||||
# TODO: how can we exercise both sides of WebDownloadTarget.fail
|
# TODO: how can we exercise both sides of WebDownloadTarget.fail
|
||||||
|
|
|
@ -439,7 +439,7 @@ class FileDownloader(Resource, object):
|
||||||
# bytes we were given in the URL. See the comment in
|
# bytes we were given in the URL. See the comment in
|
||||||
# FileNodeHandler.render_GET for the sad details.
|
# FileNodeHandler.render_GET for the sad details.
|
||||||
req.setHeader("content-disposition",
|
req.setHeader("content-disposition",
|
||||||
'attachment; filename="%s"' % self.filename)
|
b'attachment; filename="%s"' % self.filename)
|
||||||
|
|
||||||
filesize = self.filenode.get_size()
|
filesize = self.filenode.get_size()
|
||||||
assert isinstance(filesize, (int,long)), filesize
|
assert isinstance(filesize, (int,long)), filesize
|
||||||
|
|
|
@ -121,7 +121,7 @@ class URIHandler(resource.Resource, object):
|
||||||
unlinked file or "POST /uri?t=mkdir" to create a
|
unlinked file or "POST /uri?t=mkdir" to create a
|
||||||
new directory
|
new directory
|
||||||
"""
|
"""
|
||||||
t = get_arg(req, "t", "").strip()
|
t = unicode(get_arg(req, "t", "").strip(), "ascii")
|
||||||
if t in ("", "upload"):
|
if t in ("", "upload"):
|
||||||
file_format = get_format(req)
|
file_format = get_format(req)
|
||||||
mutable_type = get_mutable_type(file_format)
|
mutable_type = get_mutable_type(file_format)
|
||||||
|
|
Loading…
Reference in New Issue