diff --git a/kobo/django/xmlrpc/dispatcher.py b/kobo/django/xmlrpc/dispatcher.py index 3ad9bd53..7e9237bd 100644 --- a/kobo/django/xmlrpc/dispatcher.py +++ b/kobo/django/xmlrpc/dispatcher.py @@ -21,11 +21,7 @@ class DjangoXMLRPCDispatcher(SimpleXMLRPCDispatcher): def __init__(self, allow_none=True, encoding=None): - if sys.version_info[:2] == (2, 4): - # doesn't support extra args in python 2.4 - SimpleXMLRPCDispatcher.__init__(self) - else: - SimpleXMLRPCDispatcher.__init__(self, allow_none, encoding) + SimpleXMLRPCDispatcher.__init__(self, allow_none, encoding) self.allow_none = allow_none self.encoding = encoding diff --git a/kobo/hub/models.py b/kobo/hub/models.py index f64781ee..f3665588 100644 --- a/kobo/hub/models.py +++ b/kobo/hub/models.py @@ -396,12 +396,7 @@ def _open_log(self, name): return io.open(log_path, 'rb', LOG_BUFFER_SIZE) elif os.path.isfile(log_path + ".gz"): out = gzip.open(log_path + ".gz", "rb") - - # GZipFile was not usable with BufferedReader - # until 2.7 - if sys.version_info[0:2] >= (2, 7): - out = io.BufferedReader(out, LOG_BUFFER_SIZE) - + out = io.BufferedReader(out, LOG_BUFFER_SIZE) return out else: raise Exception('Cannot find log %s' % name) diff --git a/kobo/xmlrpc.py b/kobo/xmlrpc.py index 71b47181..5f403175 100644 --- a/kobo/xmlrpc.py +++ b/kobo/xmlrpc.py @@ -292,33 +292,21 @@ def make_connection(self, host): host_ = "%s:%s" % (host, TimeoutHTTPProxyConnection.default_port) if self.proxy_config["proxy"] and host not in self.no_proxy and host_ not in self.no_proxy: - if sys.version_info[:2] < (2, 7): - host, extra_headers, x509 = self.get_host_info(host) - conn = TimeoutProxyHTTP(host, **self.proxy_config) - conn.set_timeout(self.timeout) - return conn - else: - CONNECTION_LOCK.acquire() - host, extra_headers, x509 = self.get_host_info(host) - conn = TimeoutProxyHTTPS(host, **self.proxy_config) - conn.set_timeout(self.timeout) - CONNECTION_LOCK.release() - return conn - - if sys.version_info[:2] < (2, 7): + CONNECTION_LOCK.acquire() host, extra_headers, x509 = self.get_host_info(host) - conn = TimeoutHTTP(host) + conn = TimeoutProxyHTTPS(host, **self.proxy_config) conn.set_timeout(self.timeout) - return conn - else: - CONNECTION_LOCK.acquire() - self._connection = (None, None) # this disables connection caching which causes a race condition when running in threads - conn = xmlrpclib.Transport.make_connection(self, host) CONNECTION_LOCK.release() - if self.timeout: - conn.timeout = self.timeout return conn + CONNECTION_LOCK.acquire() + self._connection = (None, None) # this disables connection caching which causes a race condition when running in threads + conn = xmlrpclib.Transport.make_connection(self, host) + CONNECTION_LOCK.release() + if self.timeout: + conn.timeout = self.timeout + return conn + def send_cookies(self, connection, cookie_request): """Add cookies to the header.""" self.cookiejar.add_cookie_header(cookie_request) @@ -535,14 +523,7 @@ def _single_request3(self, host, handler, request_body, verbose=False): raise xmlrpclib.ProtocolError(host + handler, response.status, response.reason, response.msg) # override the appropriate request method - if sys.version_info[0] >= 3: single_request = _single_request3 - elif hasattr(xmlrpclib.Transport, "single_request"): - # python 2.7+ - single_request = _single_request - else: - # python 2.6- - request = _request def send_headers(self, connection, headers): headers.extend(self._cookie_headers) @@ -578,33 +559,21 @@ def make_connection(self, host): host_ = "%s:%s" % (host, TimeoutHTTPSProxyConnection.default_port) if self.proxy_config["proxy"] and host not in self.no_proxy and host_ not in self.no_proxy: - if sys.version_info[:2] < (2, 7): - host, extra_headers, x509 = self.get_host_info(host) - conn = TimeoutProxyHTTPS(host, **self.proxy_config) - conn.set_timeout(self.timeout) - return conn - else: - CONNECTION_LOCK.acquire() - host, extra_headers, x509 = self.get_host_info(host) - conn = TimeoutProxyHTTPS(host, **self.proxy_config) - conn.set_timeout(self.timeout) - CONNECTION_LOCK.release() - return conn - - if sys.version_info[:2] < (2, 7): + CONNECTION_LOCK.acquire() host, extra_headers, x509 = self.get_host_info(host) - conn = TimeoutHTTPS(host, None, **(x509 or {})) + conn = TimeoutProxyHTTPS(host, **self.proxy_config) conn.set_timeout(self.timeout) - return conn - else: - CONNECTION_LOCK.acquire() - self._connection = (None, None) # this disables connection caching which causes a race condition when running in threads - conn = xmlrpclib.SafeTransport.make_connection(self, host) - if self.timeout: - conn.timeout = self.timeout CONNECTION_LOCK.release() return conn + CONNECTION_LOCK.acquire() + self._connection = (None, None) # this disables connection caching which causes a race condition when running in threads + conn = xmlrpclib.SafeTransport.make_connection(self, host) + if self.timeout: + conn.timeout = self.timeout + CONNECTION_LOCK.release() + return conn + def __init__(self, *args, **kwargs): self.context = kwargs.pop('context', None) xmlrpclib.SafeTransport.__init__(self, *args, **kwargs) diff --git a/tests/test_hubproxy.py b/tests/test_hubproxy.py index 2f973f8c..4605a126 100644 --- a/tests/test_hubproxy.py +++ b/tests/test_hubproxy.py @@ -27,11 +27,7 @@ class FakeTransport(SafeCookieTransport): Subclasses the real SafeCookieTransport so we get a real CookieJar. """ def __init__(self, *args, **kwargs): - # note: py2 transport classes do not subclass object - if sys.version_info[0] < 3: - SafeCookieTransport.__init__(self, *args, **kwargs) - else: - super().__init__(*args, **kwargs) + super().__init__(*args, **kwargs) self.fake_transport_calls = []