diff --git a/src/calibre/ebooks/conversion/plugins/html_input.py b/src/calibre/ebooks/conversion/plugins/html_input.py index 9f257516d9..c1ee9ffd9e 100644 --- a/src/calibre/ebooks/conversion/plugins/html_input.py +++ b/src/calibre/ebooks/conversion/plugins/html_input.py @@ -291,7 +291,7 @@ class HTMLInput(InputFormatPlugin): # file, therefore we quote it here. if isinstance(bhref, unicode_type): 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: item.override_css_fetch = partial( self.css_import_handler, os.path.dirname(link)) diff --git a/src/calibre/ebooks/metadata/sources/identify.py b/src/calibre/ebooks/metadata/sources/identify.py index 57d032cb92..2259d80567 100644 --- a/src/calibre/ebooks/metadata/sources/identify.py +++ b/src/calibre/ebooks/metadata/sources/identify.py @@ -554,7 +554,7 @@ def urls_from_identifiers(identifiers): # {{{ formatter = EvalFormatter() for k, val in iteritems(identifiers): 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 () for name, template in items: try: diff --git a/src/calibre/srv/routes.py b/src/calibre/srv/routes.py index ca3bb68166..1e092a9d1d 100644 --- a/src/calibre/srv/routes.py +++ b/src/calibre/srv/routes.py @@ -89,7 +89,7 @@ def endpoint(route, f.ok_code = ok_code f.is_endpoint = True 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: raise TypeError('The endpoint %r must take at least two arguments' % f.route) f.__annotations__ = { diff --git a/src/calibre/srv/tests/ajax.py b/src/calibre/srv/tests/ajax.py index 36c343adc9..915eae11de 100644 --- a/src/calibre/srv/tests/ajax.py +++ b/src/calibre/srv/tests/ajax.py @@ -111,8 +111,8 @@ class ContentTest(LibraryBaseTest): r, data = make_request(conn, path, username='12', password='test', prefix='', method=method) ae(status, r.status) if status == NOT_FOUND: - p = data.partition(':')[0] - ae(p, 'No book with id') + p = data.partition(b':')[0] + ae(p, b'No book with id') return data ok = r nf = partial(r, status=NOT_FOUND) diff --git a/src/calibre/srv/tests/loop.py b/src/calibre/srv/tests/loop.py index 9543678d77..bf59cf7537 100644 --- a/src/calibre/srv/tests/loop.py +++ b/src/calibre/srv/tests/loop.py @@ -134,7 +134,7 @@ class LoopTest(BaseTest): def test_dual_stack(self): 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.loop.socket.getsockopt(IPPROTO_IPV6, socket.IPV6_V6ONLY), 0) conn = server.connect(interface='127.0.0.1') diff --git a/src/calibre/srv/tests/web_sockets.py b/src/calibre/srv/tests/web_sockets.py index 062b2cfcff..63a733511a 100644 --- a/src/calibre/srv/tests/web_sockets.py +++ b/src/calibre/srv/tests/web_sockets.py @@ -64,9 +64,10 @@ class WSClient(object): if rl != b'HTTP/1.1 101 Switching Protocols\r\n': raise ValueError('Server did not respond with correct switching protocols line') 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: - 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): if self.read_buf: diff --git a/src/calibre/utils/linux_trash.py b/src/calibre/utils/linux_trash.py index 8ab56eaa5f..32a4ac30e8 100644 --- a/src/calibre/utils/linux_trash.py +++ b/src/calibre/utils/linux_trash.py @@ -42,7 +42,7 @@ TOPDIR_FALLBACK = '.Trash-%s'%uid def uniquote(raw): if isinstance(raw, unicode_type): raw = raw.encode('utf-8') - return quote(raw).decode('utf-8') + return unicode_type(quote(raw)) def is_parent(parent, path):