py3: Start work on porting the server

This commit is contained in:
Kovid Goyal 2019-04-14 15:27:06 +05:30
parent 1f86d92f7a
commit 5500e03a12
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 12 additions and 4 deletions

View File

@ -24,11 +24,11 @@ from calibre.utils.socket_inheritance import set_socket_inherit
from calibre.utils.logging import ThreadSafeLog from calibre.utils.logging import ThreadSafeLog
from calibre.utils.monotonic import monotonic from calibre.utils.monotonic import monotonic
from calibre.utils.mdns import get_external_ip from calibre.utils.mdns import get_external_ip
from polyglot.builtins import iteritems, range from polyglot.builtins import iteritems
from polyglot.queue import Empty, Full from polyglot.queue import Empty, Full
READ, WRITE, RDWR, WAIT = 'READ', 'WRITE', 'RDWR', 'WAIT' READ, WRITE, RDWR, WAIT = 'READ', 'WRITE', 'RDWR', 'WAIT'
WAKEUP, JOB_DONE = bytes(bytearray(range(2))) WAKEUP, JOB_DONE = b'\0', b'\x01'
IPPROTO_IPV6 = getattr(socket, "IPPROTO_IPV6", 41) IPPROTO_IPV6 = getattr(socket, "IPPROTO_IPV6", 41)

View File

@ -9,6 +9,7 @@ __copyright__ = '2015, Kovid Goyal <kovid at kovidgoyal.net>'
import sys, inspect, re, time, numbers, json as jsonlib, textwrap import sys, inspect, re, time, numbers, json as jsonlib, textwrap
from operator import attrgetter from operator import attrgetter
from calibre.constants import ispy3
from calibre.srv.errors import HTTPSimpleResponse, HTTPNotFound, RouteError from calibre.srv.errors import HTTPSimpleResponse, HTTPNotFound, RouteError
from calibre.srv.utils import http_date from calibre.srv.utils import http_date
from calibre.utils.serialize import msgpack_dumps, json_dumps, MSGPACK_MIME from calibre.utils.serialize import msgpack_dumps, json_dumps, MSGPACK_MIME
@ -158,7 +159,10 @@ class Route(object):
self.names = [n for n, m in matchers if n is not None] self.names = [n for n, m in matchers if n is not None]
self.all_names = frozenset(self.names) self.all_names = frozenset(self.names)
self.required_names = self.all_names - frozenset(self.defaults) self.required_names = self.all_names - frozenset(self.defaults)
argspec = inspect.getargspec(self.endpoint) if ispy3:
argspec = inspect.getfullargspec(self.endpoint)
else:
argspec = inspect.getargspec(self.endpoint)
if len(self.names) + 2 != len(argspec.args) - len(argspec.defaults or ()): if len(self.names) + 2 != len(argspec.args) - len(argspec.defaults or ()):
raise route_error('Function must take %d non-default arguments' % (len(self.names) + 2)) raise route_error('Function must take %d non-default arguments' % (len(self.names) + 2))
if argspec.args[2:len(self.names)+2] != self.names: if argspec.args[2:len(self.names)+2] != self.names:

View File

@ -13,6 +13,7 @@ from functools import partial
from threading import Thread from threading import Thread
from calibre.srv.utils import ServerLog from calibre.srv.utils import ServerLog
from calibre.constants import ispy3
from polyglot import http_client from polyglot import http_client
rmtree = partial(shutil.rmtree, ignore_errors=True) rmtree = partial(shutil.rmtree, ignore_errors=True)
@ -121,7 +122,10 @@ class TestServer(Thread):
timeout = self.loop.opts.timeout timeout = self.loop.opts.timeout
if interface is None: if interface is None:
interface = self.address[0] interface = self.address[0]
return http_client.HTTPConnection(interface, self.address[1], strict=True, timeout=timeout) if ispy3:
return http_client.HTTPConnection(interface, self.address[1], timeout=timeout)
else:
return http_client.HTTPConnection(interface, self.address[1], strict=True, timeout=timeout)
def change_handler(self, handler): def change_handler(self, handler):
from calibre.srv.http_response import create_http_handler from calibre.srv.http_response import create_http_handler