[Py2to3] More fixes for web ui
This commit is contained in:
parent
0fd3c25684
commit
d4023e7dde
|
@ -57,3 +57,4 @@ class WebServerTestCase(WebServerTestBase, WebServerMockBase):
|
|||
|
||||
json = json_lib.loads(body)
|
||||
self.assertEqual(None, json['error'])
|
||||
self.assertEqual('torrent_filehash', json['result']['name'])
|
||||
|
|
|
@ -16,7 +16,7 @@ from deluge import common
|
|||
|
||||
|
||||
def _(text):
|
||||
return gettext.gettext(text).decode('utf-8')
|
||||
return gettext.gettext(text)
|
||||
|
||||
|
||||
def escape(text):
|
||||
|
@ -58,7 +58,7 @@ try:
|
|||
def render(self, *args, **data):
|
||||
data.update(self.builtins)
|
||||
rendered = MakoTemplate.render_unicode(self, *args, **data)
|
||||
return rendered.encode('utf-8', 'replace')
|
||||
return rendered.encode('utf-8')
|
||||
except ImportError:
|
||||
import warnings
|
||||
warnings.warn(
|
||||
|
|
|
@ -134,16 +134,17 @@ class JSON(resource.Resource, component.Component):
|
|||
procedure calls and the request id.
|
||||
"""
|
||||
try:
|
||||
request.json = json.loads(request.json)
|
||||
request_data = json.loads(request.json.decode())
|
||||
except (ValueError, TypeError):
|
||||
raise JSONException('JSON not decodable')
|
||||
|
||||
try:
|
||||
method = request.json['method']
|
||||
params = request.json['params']
|
||||
request_id = request.json['id']
|
||||
method = request_data['method']
|
||||
params = request_data['params']
|
||||
request_id = request_data['id']
|
||||
except KeyError as ex:
|
||||
message = 'Invalid JSON request, missing param %s in %s' % (ex, request.json)
|
||||
message = 'Invalid JSON request, missing param %s in %s' % (
|
||||
ex, request_data)
|
||||
raise JSONException(message)
|
||||
|
||||
result = None
|
||||
|
@ -185,7 +186,7 @@ class JSON(resource.Resource, component.Component):
|
|||
Handler to take the json data as a string and pass it on to the
|
||||
_handle_request method for further processing.
|
||||
"""
|
||||
if request.getHeader('content-type') != 'application/json':
|
||||
if request.getHeader(b'content-type') != b'application/json':
|
||||
message = 'Invalid JSON request content-type: %s' % request.getHeader('content-type')
|
||||
raise JSONException(message)
|
||||
|
||||
|
@ -220,7 +221,7 @@ class JSON(resource.Resource, component.Component):
|
|||
return ''
|
||||
response = json.dumps(response)
|
||||
request.setHeader(b'content-type', b'application/x-json')
|
||||
request.write(compress(response, request))
|
||||
request.write(compress(response.encode(), request))
|
||||
request.finish()
|
||||
return server.NOT_DONE_YET
|
||||
|
||||
|
@ -228,7 +229,7 @@ class JSON(resource.Resource, component.Component):
|
|||
"""
|
||||
Handles all the POST requests made to the /json controller.
|
||||
"""
|
||||
if request.method != 'POST':
|
||||
if request.method != b'POST':
|
||||
request.setResponseCode(http.NOT_ALLOWED)
|
||||
request.finish()
|
||||
return server.NOT_DONE_YET
|
||||
|
|
|
@ -107,11 +107,12 @@ class Upload(resource.Resource):
|
|||
"""
|
||||
|
||||
# Block all other HTTP methods.
|
||||
if request.method != 'POST':
|
||||
if request.method != b'POST':
|
||||
request.setResponseCode(http.NOT_ALLOWED)
|
||||
return ''
|
||||
|
||||
if 'file' not in request.args:
|
||||
print(request.args)
|
||||
if b'file' not in request.args:
|
||||
request.setResponseCode(http.OK)
|
||||
return json.dumps({
|
||||
'success': True,
|
||||
|
@ -150,19 +151,21 @@ class Render(resource.Resource):
|
|||
return self
|
||||
|
||||
def render(self, request):
|
||||
log.debug('Render template file: %s', request.render_file)
|
||||
if not hasattr(request, 'render_file'):
|
||||
request.setResponseCode(http.INTERNAL_SERVER_ERROR)
|
||||
return ''
|
||||
|
||||
if request.render_file in self.template_files:
|
||||
request.setHeader(b'content-type', b'text/html')
|
||||
|
||||
tpl_file = request.render_file.decode()
|
||||
if tpl_file in self.template_files:
|
||||
request.setResponseCode(http.OK)
|
||||
filename = os.path.join('render', request.render_file)
|
||||
else:
|
||||
request.setResponseCode(http.NOT_FOUND)
|
||||
filename = os.path.join('render', '404.html')
|
||||
tpl_file = '404.html'
|
||||
|
||||
request.setHeader(b'content-type', b'text/html')
|
||||
template = Template(filename=rpath(filename))
|
||||
template = Template(filename=rpath(os.path.join('render', tpl_file)))
|
||||
return compress(template.render(), request)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue