From 73daf1783dbb966f42fb14f6f66434f930ba547b Mon Sep 17 00:00:00 2001 From: abhishekkekane Date: Sun, 31 Jan 2016 02:55:13 -0800 Subject: [PATCH] Python3: Add support for httplib, urlparse Replaced urlparse to use from six.moves.urllib2.urlparse.urlparse Replaced httplib to use from six.moves.http_client This patch is generated by the following tool using 'six_moves' options. https://github.com/haypo/sixer Command: python sixer.py -w 'six_moves' trove/ Partially implements: blueprint trove-python3 Change-Id: I2cb3fad36522295fdd5144f55aa8e60b4e073455 --- trove/common/limits.py | 4 ++-- trove/extensions/mysql/common.py | 3 ++- trove/tests/examples/client.py | 2 +- trove/tests/fakes/swift.py | 6 ++--- .../tests/unittests/api/common/test_limits.py | 22 +++++++++---------- trove/tests/util/__init__.py | 3 +-- 6 files changed, 20 insertions(+), 20 deletions(-) diff --git a/trove/common/limits.py b/trove/common/limits.py index 1785a085f5..cb15b66f57 100644 --- a/trove/common/limits.py +++ b/trove/common/limits.py @@ -19,13 +19,13 @@ Module dedicated functions/classes dealing with rate limiting requests. import collections import copy -import httplib import math import re import time from oslo_serialization import jsonutils from oslo_utils import importutils +from six.moves import http_client import webob.dec import webob.exc @@ -399,7 +399,7 @@ class WsgiLimiterProxy(object): body = jsonutils.dumps({"verb": verb, "path": path}) headers = {"Content-Type": "application/json"} - conn = httplib.HTTPConnection(self.limiter_address) + conn = http_client.HTTPConnection(self.limiter_address) if username: conn.request("POST", "/%s" % (username), body, headers) diff --git a/trove/extensions/mysql/common.py b/trove/extensions/mysql/common.py index e306eb9ff9..67740ce356 100644 --- a/trove/extensions/mysql/common.py +++ b/trove/extensions/mysql/common.py @@ -12,9 +12,10 @@ # License for the specific language governing permissions and limitations # under the License. +from six.moves.urllib.parse import unquote + from trove.common import exception from trove.guestagent.db import models as guest_models -from urllib import unquote def populate_validated_databases(dbs): diff --git a/trove/tests/examples/client.py b/trove/tests/examples/client.py index 9852237927..f8a56d6ee7 100644 --- a/trove/tests/examples/client.py +++ b/trove/tests/examples/client.py @@ -16,9 +16,9 @@ import json import os import re import time -from urlparse import urlparse from proboscis.asserts import fail +from six.moves.urllib.parse import urlparse from troveclient.compat.client import TroveHTTPClient from trove.tests.config import CONFIG diff --git a/trove/tests/fakes/swift.py b/trove/tests/fakes/swift.py index 4dcf209ee3..bb48d8384b 100644 --- a/trove/tests/fakes/swift.py +++ b/trove/tests/fakes/swift.py @@ -15,7 +15,6 @@ from hashlib import md5 from mock import MagicMock, patch -import httplib import json import os import socket @@ -24,6 +23,7 @@ import swiftclient.client as swift_client import uuid from oslo_log import log as logging +from six.moves import http_client from swiftclient import client as swift from trove.common.i18n import _ # noqa @@ -77,10 +77,10 @@ class FakeSwiftConnection(object): LOG.debug("fake head_container(%s)" % container) if container == 'missing_container': raise swift.ClientException('fake exception', - http_status=httplib.NOT_FOUND) + http_status=http_client.NOT_FOUND) elif container == 'unauthorized_container': raise swift.ClientException('fake exception', - http_status=httplib.UNAUTHORIZED) + http_status=http_client.UNAUTHORIZED) elif container == 'socket_error_on_head': raise socket.error(111, 'ECONNREFUSED') pass diff --git a/trove/tests/unittests/api/common/test_limits.py b/trove/tests/unittests/api/common/test_limits.py index bbb72c915a..985503efae 100644 --- a/trove/tests/unittests/api/common/test_limits.py +++ b/trove/tests/unittests/api/common/test_limits.py @@ -17,12 +17,11 @@ Tests dealing with HTTP rate-limiting. """ -import httplib - from mock import Mock, MagicMock, patch from oslo_serialization import jsonutils import six +from six.moves import http_client import webob from trove.common import limits @@ -557,7 +556,7 @@ class WsgiLimiterTest(BaseLimitTestSuite): class FakeHttplibSocket(object): """ - Fake `httplib.HTTPResponse` replacement. + Fake `http_client.HTTPResponse` replacement. """ def __init__(self, response_string): @@ -571,7 +570,7 @@ class FakeHttplibSocket(object): class FakeHttplibConnection(object): """ - Fake `httplib.HTTPConnection`. + Fake `http_client.HTTPConnection`. """ def __init__(self, app, host): @@ -585,7 +584,7 @@ class FakeHttplibConnection(object): """ Requests made via this connection actually get translated and routed into our WSGI app, we then wait for the response and turn it back into - an `httplib.HTTPResponse`. + an `http_client.HTTPResponse`. """ if not headers: headers = {} @@ -599,7 +598,7 @@ class FakeHttplibConnection(object): resp = str(req.get_response(self.app)) resp = "HTTP/1.0 %s" % resp sock = FakeHttplibSocket(resp) - self.http_response = httplib.HTTPResponse(sock) + self.http_response = http_client.HTTPResponse(sock) self.http_response.begin() def getresponse(self): @@ -613,7 +612,7 @@ def wire_HTTPConnection_to_WSGI(host, app): After calling this method, when any code calls - httplib.HTTPConnection(host) + http_client.HTTPConnection(host) the connection object will be a fake. Its requests will be sent directly to the given WSGI app rather than through a socket. @@ -641,8 +640,9 @@ def wire_HTTPConnection_to_WSGI(host, app): else: return self.wrapped(connection_host, *args, **kwargs) - oldHTTPConnection = httplib.HTTPConnection - httplib.HTTPConnection = HTTPConnectionDecorator(httplib.HTTPConnection) + oldHTTPConnection = http_client.HTTPConnection + http_client.HTTPConnection = HTTPConnectionDecorator( + http_client.HTTPConnection) return oldHTTPConnection @@ -654,7 +654,7 @@ class WsgiLimiterProxyTest(BaseLimitTestSuite): def setUp(self): """ Do some nifty HTTP/WSGI magic which allows for WSGI to be called - directly by something like the `httplib` library. + directly by something like the `http_client` library. """ super(WsgiLimiterProxyTest, self).setUp() self.app = limits.WsgiLimiter(TEST_LIMITS) @@ -681,7 +681,7 @@ class WsgiLimiterProxyTest(BaseLimitTestSuite): def tearDown(self): # restore original HTTPConnection object - httplib.HTTPConnection = self.oldHTTPConnection + http_client.HTTPConnection = self.oldHTTPConnection super(WsgiLimiterProxyTest, self).tearDown() diff --git a/trove/tests/util/__init__.py b/trove/tests/util/__init__.py index 2827a44ea6..934f1f090a 100644 --- a/trove/tests/util/__init__.py +++ b/trove/tests/util/__init__.py @@ -23,8 +23,6 @@ """ import subprocess -from urllib import unquote - try: EVENT_AVAILABLE = True except ImportError: @@ -34,6 +32,7 @@ from proboscis.asserts import assert_true from proboscis.asserts import Check from proboscis.asserts import fail from proboscis import SkipTest +from six.moves.urllib.parse import unquote from sqlalchemy import create_engine from troveclient.compat import Dbaas from troveclient.compat import exceptions