[#2875][Web] Fix: WebUI Json dumps Error

This commit is contained in:
bendikro 2016-10-19 10:09:22 +02:00
parent cfdddc4469
commit 37baf3de3c
3 changed files with 55 additions and 0 deletions

View File

@ -0,0 +1,2 @@
d13:creation datei1476342472e4:infod5:filesld4:ed2k16:2M<32>Ž2Õ³&šïXE †18:filehash20:f»4^S96PâöÕ<C3B6>RãÑ“6:lengthi54e4:pathl8:tull.txteed4:ed2k16:à_Gà ÂLŸ@”8:filehash20:º<>vê¤æXä™dÓ/§n1Þ¸36:lengthi54e4:pathl56:é„在一å€äººç„¡è<C2A1>Šå—Ž~é„ä¸<C3A4>趕緊上來è<E280A0>Šå¤©ç¾Ž.txteee4:name16:torrent_filehash12:piece lengthi32768e6:pieces20:G@g\˜&\ fB© Ž
<17>µØee

View File

@ -0,0 +1,51 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2016 bendikro <bro.devel+deluge@gmail.com>
#
# This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with
# the additional special exception to link portions of this program with the OpenSSL library.
# See LICENSE for more details.
#
import json as json_lib
from StringIO import StringIO
import twisted.web.client
from twisted.internet import defer, reactor
from twisted.web.client import Agent, FileBodyProducer
from twisted.web.http_headers import Headers
from . import common
from .common import get_test_data_file
from .common_web import WebServerMockBase, WebServerTestBase
common.disable_new_release_check()
class WebServerTestCase(WebServerTestBase, WebServerMockBase):
@defer.inlineCallbacks
def test_get_torrent_info(self):
"""
"""
agent = Agent(reactor)
self.mock_authentication_ignore(self.deluge_web.auth)
self.mock_compress_body()
# This torrent file contains an uncommon field 'filehash' which must be hex
# encoded to allow dumping the torrent info to json. Otherwise it will fail with:
# UnicodeDecodeError: 'utf8' codec can't decode byte 0xe5 in position 0: invalid continuation byte
filename = get_test_data_file("filehash_field.torrent")
d = yield agent.request(
'POST',
'http://127.0.0.1:%s/json' % self.webserver_listen_port,
Headers({'User-Agent': ['Twisted Web Client Example'],
'Content-Type': ['application/json']}),
FileBodyProducer(StringIO('{"params": ["%s"], "method": "web.get_torrent_info", "id": 22}' % filename)))
body = yield twisted.web.client.readBody(d)
json = json_lib.loads(body)
self.assertEqual(None, json["error"])

View File

@ -117,6 +117,8 @@ class TorrentInfo(object):
f["sha1"] = f["sha1"].encode('hex') f["sha1"] = f["sha1"].encode('hex')
if "ed2k" in f and len(f["ed2k"]) == 16: if "ed2k" in f and len(f["ed2k"]) == 16:
f["ed2k"] = f["ed2k"].encode('hex') f["ed2k"] = f["ed2k"].encode('hex')
if "filehash" in f and len(f["filehash"]) == 20:
f["filehash"] = f["filehash"].encode('hex')
paths[path] = f paths[path] = f
dirname = os.path.dirname(path) dirname = os.path.dirname(path)
while dirname: while dirname: