Commit 38bca977 authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

fixup! py2/py3: import from six.moves.

parent 92f2197f
......@@ -26,10 +26,11 @@
#
##############################################################################
import time
import urlparse
import ssl
import httplib
import json
from six.moves.http_client import HTTPSConnection
from six.moves.urllib.parse import urlparse
from six import string_types as basestring
from Products.ERP5Type.Timeout import getTimeLeft
from contextlib import contextmanager
from Products.ERP5Type.XMLObject import XMLObject
......@@ -105,7 +106,7 @@ class RESTAPIClientConnectorMixin(XMLObject):
header_dict['content-type'] = 'application/json'
body = json.dumps(body)
plain_url = self.getBaseUrl().rstrip('/') + '/' + path.lstrip('/')
parsed_url = urlparse.urlparse(plain_url)
parsed_url = urlparse(plain_url)
ssl_context = ssl.create_default_context(
cadata=self.getCaCertificatePem(),
)
......@@ -115,7 +116,7 @@ class RESTAPIClientConnectorMixin(XMLObject):
if bind_address:
bind_address = (bind_address, 0)
time_left_before_timeout = getTimeLeft()
http_connection = httplib.HTTPSConnection(
http_connection = HTTPSConnection(
host=parsed_url.hostname,
port=parsed_url.port,
strict=True,
......@@ -184,7 +185,7 @@ class RESTAPIClientConnectorMixin(XMLObject):
with time_tracker('call'), Deadline(timeout):
# Limit numbers of retries, in case the authentication API succeeds
# but the token is not usable.
for _ in xrange(2):
for _ in range(2):
with time_tracker('token'):
access_token = self._getAccessToken()
if access_token is not None:
......
......@@ -2,7 +2,7 @@
# Copyright (c) 2002-2015 Nexedi SA and Contributors. All Rights Reserved.
from json import dumps
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from httplib import HTTPSConnection
from six.moves.http_client import HTTPSConnection
from erp5.component.mixin.RESTAPIClientConnectorMixin import RESTAPIClientConnectorMixin
from ssl import SSLError
from Products.ERP5Type.Timeout import TimeoutReachedError
......@@ -71,11 +71,11 @@ class TestRESTAPIClientConnector(ERP5TypeTestCase):
with mock.patch(
'ssl.create_default_context',
) as mock_ssl_create_default_context, mock.patch(
'httplib.HTTPSConnection.request',
'six.moves.http_client.HTTPSConnection.request',
) as mock_https_connection_request, mock.patch(
'httplib.HTTPSConnection.getresponse',
'six.moves.http_client.HTTPSConnection.getresponse',
return_value=HTTPResponse_getresponse()
), mock.patch('httplib.HTTPSConnection', return_value=HTTPSConnection) as mock_https_connection:
), mock.patch('six.moves.http_client.HTTPSConnection', return_value=HTTPSConnection) as mock_https_connection:
header_dict, body_dict, status = self.rest_api_client_connection.call(
archive_resource=None,
method='POST',
......@@ -145,9 +145,9 @@ class TestRESTAPIClientConnector(ERP5TypeTestCase):
with mock.patch(
'ssl.create_default_context',
), mock.patch(
'httplib.HTTPSConnection.request',
'six.moves.http_client.HTTPSConnection.request',
), mock.patch(
'httplib.HTTPSConnection.getresponse',
'six.moves.http_client.HTTPSConnection.getresponse',
return_value=HTTPResponse_getresponse(498)
):
with self.assertRaises(RESTAPIError) as error:
......@@ -175,9 +175,9 @@ class TestRESTAPIClientConnector(ERP5TypeTestCase):
with mock.patch(
'ssl.create_default_context',
), mock.patch(
'httplib.HTTPSConnection.request',
'six.moves.http_client.HTTPSConnection.request',
), mock.patch(
'httplib.HTTPSConnection.getresponse',
'six.moves.http_client.HTTPSConnection.getresponse',
) as mock_https_connection_getresponse:
mock_https_connection_getresponse.side_effect = SSLError('The read operation timed out')
self.assertRaises(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment