mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
py3: More misc fixes only 4 failing tests left in the srv module
This commit is contained in:
parent
15c4080567
commit
e5b32b2c2f
@ -291,7 +291,7 @@ class HTMLInput(InputFormatPlugin):
|
|||||||
# file, therefore we quote it here.
|
# file, therefore we quote it here.
|
||||||
if isinstance(bhref, unicode_type):
|
if isinstance(bhref, unicode_type):
|
||||||
bhref = bhref.encode('utf-8')
|
bhref = bhref.encode('utf-8')
|
||||||
item.html_input_href = quote(bhref).decode('utf-8')
|
item.html_input_href = unicode_type(quote(bhref))
|
||||||
if guessed in self.OEB_STYLES:
|
if guessed in self.OEB_STYLES:
|
||||||
item.override_css_fetch = partial(
|
item.override_css_fetch = partial(
|
||||||
self.css_import_handler, os.path.dirname(link))
|
self.css_import_handler, os.path.dirname(link))
|
||||||
|
@ -554,7 +554,7 @@ def urls_from_identifiers(identifiers): # {{{
|
|||||||
formatter = EvalFormatter()
|
formatter = EvalFormatter()
|
||||||
for k, val in iteritems(identifiers):
|
for k, val in iteritems(identifiers):
|
||||||
val = val.replace('|', ',')
|
val = val.replace('|', ',')
|
||||||
vals = {'id':quote(val if isinstance(val, bytes) else val.encode('utf-8')).decode('ascii')}
|
vals = {'id':unicode_type(quote(val if isinstance(val, bytes) else val.encode('utf-8')))}
|
||||||
items = rules.get(k) or ()
|
items = rules.get(k) or ()
|
||||||
for name, template in items:
|
for name, template in items:
|
||||||
try:
|
try:
|
||||||
|
@ -89,7 +89,7 @@ def endpoint(route,
|
|||||||
f.ok_code = ok_code
|
f.ok_code = ok_code
|
||||||
f.is_endpoint = True
|
f.is_endpoint = True
|
||||||
f.needs_db_write = needs_db_write
|
f.needs_db_write = needs_db_write
|
||||||
argspec = inspect.getargspec(f)
|
argspec = inspect.getfullargspec(f) if ispy3 else inspect.getargspec(f)
|
||||||
if len(argspec.args) < 2:
|
if len(argspec.args) < 2:
|
||||||
raise TypeError('The endpoint %r must take at least two arguments' % f.route)
|
raise TypeError('The endpoint %r must take at least two arguments' % f.route)
|
||||||
f.__annotations__ = {
|
f.__annotations__ = {
|
||||||
|
@ -111,8 +111,8 @@ class ContentTest(LibraryBaseTest):
|
|||||||
r, data = make_request(conn, path, username='12', password='test', prefix='', method=method)
|
r, data = make_request(conn, path, username='12', password='test', prefix='', method=method)
|
||||||
ae(status, r.status)
|
ae(status, r.status)
|
||||||
if status == NOT_FOUND:
|
if status == NOT_FOUND:
|
||||||
p = data.partition(':')[0]
|
p = data.partition(b':')[0]
|
||||||
ae(p, 'No book with id')
|
ae(p, b'No book with id')
|
||||||
return data
|
return data
|
||||||
ok = r
|
ok = r
|
||||||
nf = partial(r, status=NOT_FOUND)
|
nf = partial(r, status=NOT_FOUND)
|
||||||
|
@ -134,7 +134,7 @@ class LoopTest(BaseTest):
|
|||||||
|
|
||||||
def test_dual_stack(self):
|
def test_dual_stack(self):
|
||||||
from calibre.srv.loop import IPPROTO_IPV6
|
from calibre.srv.loop import IPPROTO_IPV6
|
||||||
with TestServer(lambda data:(data.path[0] + data.read()), listen_on='::') as server:
|
with TestServer(lambda data:(data.path[0] + data.read().decode('utf-8')), listen_on='::') as server:
|
||||||
self.ae(server.address[0], '::')
|
self.ae(server.address[0], '::')
|
||||||
self.ae(server.loop.socket.getsockopt(IPPROTO_IPV6, socket.IPV6_V6ONLY), 0)
|
self.ae(server.loop.socket.getsockopt(IPPROTO_IPV6, socket.IPV6_V6ONLY), 0)
|
||||||
conn = server.connect(interface='127.0.0.1')
|
conn = server.connect(interface='127.0.0.1')
|
||||||
|
@ -64,9 +64,10 @@ class WSClient(object):
|
|||||||
if rl != b'HTTP/1.1 101 Switching Protocols\r\n':
|
if rl != b'HTTP/1.1 101 Switching Protocols\r\n':
|
||||||
raise ValueError('Server did not respond with correct switching protocols line')
|
raise ValueError('Server did not respond with correct switching protocols line')
|
||||||
headers = read_headers(partial(next, lines))
|
headers = read_headers(partial(next, lines))
|
||||||
key = as_base64_unicode(sha1(self.key + GUID_STR).digest())
|
key = as_base64_unicode(sha1(self.key + GUID_STR.encode('ascii')).digest())
|
||||||
if headers.get('Sec-WebSocket-Accept') != key:
|
if headers.get('Sec-WebSocket-Accept') != key:
|
||||||
raise ValueError('Server did not respond with correct key in Sec-WebSocket-Accept')
|
raise ValueError('Server did not respond with correct key in Sec-WebSocket-Accept: {} != {}'.format(
|
||||||
|
key, headers.get('Sec-WebSocket-Accept')))
|
||||||
|
|
||||||
def recv(self, max_amt):
|
def recv(self, max_amt):
|
||||||
if self.read_buf:
|
if self.read_buf:
|
||||||
|
@ -42,7 +42,7 @@ TOPDIR_FALLBACK = '.Trash-%s'%uid
|
|||||||
def uniquote(raw):
|
def uniquote(raw):
|
||||||
if isinstance(raw, unicode_type):
|
if isinstance(raw, unicode_type):
|
||||||
raw = raw.encode('utf-8')
|
raw = raw.encode('utf-8')
|
||||||
return quote(raw).decode('utf-8')
|
return unicode_type(quote(raw))
|
||||||
|
|
||||||
|
|
||||||
def is_parent(parent, path):
|
def is_parent(parent, path):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user