[tests] use python3 for authproxy.py

This commit is contained in:
John Newbery 2017-07-17 13:09:04 -04:00
parent 2c66cea2d1
commit fc0176d01e

View File

@ -33,20 +33,14 @@ ServiceProxy class:
- uses standard Python json lib - uses standard Python json lib
""" """
try:
import http.client as httplib
except ImportError:
import httplib
import base64 import base64
import decimal import decimal
import http.client
import json import json
import logging import logging
import socket import socket
import time import time
try: import urllib.parse
import urllib.parse as urlparse
except ImportError:
import urlparse
USER_AGENT = "AuthServiceProxy/0.1" USER_AGENT = "AuthServiceProxy/0.1"
@ -60,7 +54,7 @@ class JSONRPCException(Exception):
errmsg = '%(message)s (%(code)i)' % rpc_error errmsg = '%(message)s (%(code)i)' % rpc_error
except (KeyError, TypeError): except (KeyError, TypeError):
errmsg = '' errmsg = ''
Exception.__init__(self, errmsg) super().__init__(errmsg)
self.error = rpc_error self.error = rpc_error
@ -77,7 +71,7 @@ class AuthServiceProxy(object):
self.__service_url = service_url self.__service_url = service_url
self._service_name = service_name self._service_name = service_name
self.ensure_ascii = ensure_ascii # can be toggled on the fly by tests self.ensure_ascii = ensure_ascii # can be toggled on the fly by tests
self.__url = urlparse.urlparse(service_url) self.__url = urllib.parse.urlparse(service_url)
if self.__url.port is None: if self.__url.port is None:
port = 80 port = 80
else: else:
@ -98,10 +92,10 @@ class AuthServiceProxy(object):
# Callables re-use the connection of the original proxy # Callables re-use the connection of the original proxy
self.__conn = connection self.__conn = connection
elif self.__url.scheme == 'https': elif self.__url.scheme == 'https':
self.__conn = httplib.HTTPSConnection(self.__url.hostname, port, self.__conn = http.client.HTTPSConnection(self.__url.hostname, port,
timeout=timeout) timeout=timeout)
else: else:
self.__conn = httplib.HTTPConnection(self.__url.hostname, port, self.__conn = http.client.HTTPConnection(self.__url.hostname, port,
timeout=timeout) timeout=timeout)
def __getattr__(self, name): def __getattr__(self, name):
@ -124,7 +118,7 @@ class AuthServiceProxy(object):
try: try:
self.__conn.request(method, path, postdata, headers) self.__conn.request(method, path, postdata, headers)
return self._get_response() return self._get_response()
except httplib.BadStatusLine as e: except http.client.BadStatusLine as e:
if e.line == "''": # if connection was closed, try again if e.line == "''": # if connection was closed, try again
self.__conn.close() self.__conn.close()
self.__conn.request(method, path, postdata, headers) self.__conn.request(method, path, postdata, headers)