mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2024-12-19 04:57:54 +00:00
Take care with str vs bytes in the implementation
Also replace the intentional BAD_REQUEST with GONE for this case.
This commit is contained in:
parent
d7fe25f7c7
commit
02aeb68f17
@ -6,22 +6,13 @@
|
||||
# This file is part of Tahoe-LAFS.
|
||||
#
|
||||
# See the docs/about.rst file for licensing information.
|
||||
"""Test-helpers for clients that use the WebUI.
|
||||
|
||||
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
|
||||
|
||||
Test-helpers for clients that use the WebUI.
|
||||
"""
|
||||
|
||||
import hashlib
|
||||
from typing import Dict
|
||||
|
||||
import attr
|
||||
|
||||
@ -147,7 +138,7 @@ class _FakeTahoeUriHandler(Resource, object):
|
||||
|
||||
isLeaf = True
|
||||
|
||||
data = attr.ib(default=attr.Factory(dict))
|
||||
data: Dict[bytes, bytes] = attr.ib(default=attr.Factory(dict))
|
||||
capability_generators = attr.ib(default=attr.Factory(dict))
|
||||
|
||||
def _generate_capability(self, kind):
|
||||
@ -209,7 +200,7 @@ class _FakeTahoeUriHandler(Resource, object):
|
||||
capability = None
|
||||
for arg, value in uri.query:
|
||||
if arg == u"uri":
|
||||
capability = value
|
||||
capability = value.encode("utf-8")
|
||||
# it's legal to use the form "/uri/<capability>"
|
||||
if capability is None and request.postpath and request.postpath[0]:
|
||||
capability = request.postpath[0]
|
||||
@ -221,10 +212,9 @@ class _FakeTahoeUriHandler(Resource, object):
|
||||
|
||||
# the user gave us a capability; if our Grid doesn't have any
|
||||
# data for it, that's an error.
|
||||
capability = capability.encode('ascii')
|
||||
if capability not in self.data:
|
||||
request.setResponseCode(http.BAD_REQUEST)
|
||||
return u"No data for '{}'".format(capability.decode('ascii'))
|
||||
request.setResponseCode(http.GONE)
|
||||
return u"No data for '{}'".format(capability.decode('ascii')).encode("utf-8")
|
||||
|
||||
return self.data[capability]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user