From 5500e03a1279c0708e6b892e562d4ecebcf44104 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 14 Apr 2019 15:27:06 +0530 Subject: [PATCH] py3: Start work on porting the server --- src/calibre/srv/loop.py | 4 ++-- src/calibre/srv/routes.py | 6 +++++- src/calibre/srv/tests/base.py | 6 +++++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/calibre/srv/loop.py b/src/calibre/srv/loop.py index 3c84587d64..88e1ce9063 100644 --- a/src/calibre/srv/loop.py +++ b/src/calibre/srv/loop.py @@ -24,11 +24,11 @@ from calibre.utils.socket_inheritance import set_socket_inherit from calibre.utils.logging import ThreadSafeLog from calibre.utils.monotonic import monotonic 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 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) diff --git a/src/calibre/srv/routes.py b/src/calibre/srv/routes.py index 12698c5921..ca3bb68166 100644 --- a/src/calibre/srv/routes.py +++ b/src/calibre/srv/routes.py @@ -9,6 +9,7 @@ __copyright__ = '2015, Kovid Goyal ' import sys, inspect, re, time, numbers, json as jsonlib, textwrap from operator import attrgetter +from calibre.constants import ispy3 from calibre.srv.errors import HTTPSimpleResponse, HTTPNotFound, RouteError from calibre.srv.utils import http_date 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.all_names = frozenset(self.names) 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 ()): raise route_error('Function must take %d non-default arguments' % (len(self.names) + 2)) if argspec.args[2:len(self.names)+2] != self.names: diff --git a/src/calibre/srv/tests/base.py b/src/calibre/srv/tests/base.py index 165aa2e0c5..3f66ebf6b9 100644 --- a/src/calibre/srv/tests/base.py +++ b/src/calibre/srv/tests/base.py @@ -13,6 +13,7 @@ from functools import partial from threading import Thread from calibre.srv.utils import ServerLog +from calibre.constants import ispy3 from polyglot import http_client rmtree = partial(shutil.rmtree, ignore_errors=True) @@ -121,7 +122,10 @@ class TestServer(Thread): timeout = self.loop.opts.timeout if interface is None: 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): from calibre.srv.http_response import create_http_handler