py3: More misc fixes only 4 failing tests left in the srv module

This commit is contained in:
Kovid Goyal 2019-04-15 11:23:38 +05:30
parent 15c4080567
commit e5b32b2c2f
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
7 changed files with 10 additions and 9 deletions

View File

@ -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))

View File

@ -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:

View File

@ -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__ = {

View File

@ -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)

View File

@ -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')

View File

@ -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:

View File

@ -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):