Merge "Python3: Add support for httplib, urlparse"
This commit is contained in:
commit
b68f3e700f
|
@ -19,13 +19,13 @@ Module dedicated functions/classes dealing with rate limiting requests.
|
||||||
|
|
||||||
import collections
|
import collections
|
||||||
import copy
|
import copy
|
||||||
import httplib
|
|
||||||
import math
|
import math
|
||||||
import re
|
import re
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from oslo_serialization import jsonutils
|
from oslo_serialization import jsonutils
|
||||||
from oslo_utils import importutils
|
from oslo_utils import importutils
|
||||||
|
from six.moves import http_client
|
||||||
import webob.dec
|
import webob.dec
|
||||||
import webob.exc
|
import webob.exc
|
||||||
|
|
||||||
|
@ -399,7 +399,7 @@ class WsgiLimiterProxy(object):
|
||||||
body = jsonutils.dumps({"verb": verb, "path": path})
|
body = jsonutils.dumps({"verb": verb, "path": path})
|
||||||
headers = {"Content-Type": "application/json"}
|
headers = {"Content-Type": "application/json"}
|
||||||
|
|
||||||
conn = httplib.HTTPConnection(self.limiter_address)
|
conn = http_client.HTTPConnection(self.limiter_address)
|
||||||
|
|
||||||
if username:
|
if username:
|
||||||
conn.request("POST", "/%s" % (username), body, headers)
|
conn.request("POST", "/%s" % (username), body, headers)
|
||||||
|
|
|
@ -12,9 +12,10 @@
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
from six.moves.urllib.parse import unquote
|
||||||
|
|
||||||
from trove.common import exception
|
from trove.common import exception
|
||||||
from trove.guestagent.db import models as guest_models
|
from trove.guestagent.db import models as guest_models
|
||||||
from urllib import unquote
|
|
||||||
|
|
||||||
|
|
||||||
def populate_validated_databases(dbs):
|
def populate_validated_databases(dbs):
|
||||||
|
|
|
@ -16,9 +16,9 @@ import json
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import time
|
import time
|
||||||
from urlparse import urlparse
|
|
||||||
|
|
||||||
from proboscis.asserts import fail
|
from proboscis.asserts import fail
|
||||||
|
from six.moves.urllib.parse import urlparse
|
||||||
from troveclient.compat.client import TroveHTTPClient
|
from troveclient.compat.client import TroveHTTPClient
|
||||||
|
|
||||||
from trove.tests.config import CONFIG
|
from trove.tests.config import CONFIG
|
||||||
|
|
|
@ -15,7 +15,6 @@
|
||||||
|
|
||||||
from hashlib import md5
|
from hashlib import md5
|
||||||
from mock import MagicMock, patch
|
from mock import MagicMock, patch
|
||||||
import httplib
|
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import socket
|
import socket
|
||||||
|
@ -24,6 +23,7 @@ import swiftclient.client as swift_client
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
|
from six.moves import http_client
|
||||||
from swiftclient import client as swift
|
from swiftclient import client as swift
|
||||||
|
|
||||||
from trove.common.i18n import _ # noqa
|
from trove.common.i18n import _ # noqa
|
||||||
|
@ -77,10 +77,10 @@ class FakeSwiftConnection(object):
|
||||||
LOG.debug("fake head_container(%s)" % container)
|
LOG.debug("fake head_container(%s)" % container)
|
||||||
if container == 'missing_container':
|
if container == 'missing_container':
|
||||||
raise swift.ClientException('fake exception',
|
raise swift.ClientException('fake exception',
|
||||||
http_status=httplib.NOT_FOUND)
|
http_status=http_client.NOT_FOUND)
|
||||||
elif container == 'unauthorized_container':
|
elif container == 'unauthorized_container':
|
||||||
raise swift.ClientException('fake exception',
|
raise swift.ClientException('fake exception',
|
||||||
http_status=httplib.UNAUTHORIZED)
|
http_status=http_client.UNAUTHORIZED)
|
||||||
elif container == 'socket_error_on_head':
|
elif container == 'socket_error_on_head':
|
||||||
raise socket.error(111, 'ECONNREFUSED')
|
raise socket.error(111, 'ECONNREFUSED')
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -17,12 +17,11 @@
|
||||||
Tests dealing with HTTP rate-limiting.
|
Tests dealing with HTTP rate-limiting.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import httplib
|
|
||||||
|
|
||||||
|
|
||||||
from mock import Mock, MagicMock, patch
|
from mock import Mock, MagicMock, patch
|
||||||
from oslo_serialization import jsonutils
|
from oslo_serialization import jsonutils
|
||||||
import six
|
import six
|
||||||
|
from six.moves import http_client
|
||||||
import webob
|
import webob
|
||||||
|
|
||||||
from trove.common import limits
|
from trove.common import limits
|
||||||
|
@ -557,7 +556,7 @@ class WsgiLimiterTest(BaseLimitTestSuite):
|
||||||
|
|
||||||
class FakeHttplibSocket(object):
|
class FakeHttplibSocket(object):
|
||||||
"""
|
"""
|
||||||
Fake `httplib.HTTPResponse` replacement.
|
Fake `http_client.HTTPResponse` replacement.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, response_string):
|
def __init__(self, response_string):
|
||||||
|
@ -571,7 +570,7 @@ class FakeHttplibSocket(object):
|
||||||
|
|
||||||
class FakeHttplibConnection(object):
|
class FakeHttplibConnection(object):
|
||||||
"""
|
"""
|
||||||
Fake `httplib.HTTPConnection`.
|
Fake `http_client.HTTPConnection`.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, app, host):
|
def __init__(self, app, host):
|
||||||
|
@ -585,7 +584,7 @@ class FakeHttplibConnection(object):
|
||||||
"""
|
"""
|
||||||
Requests made via this connection actually get translated and routed
|
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
|
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:
|
if not headers:
|
||||||
headers = {}
|
headers = {}
|
||||||
|
@ -599,7 +598,7 @@ class FakeHttplibConnection(object):
|
||||||
resp = str(req.get_response(self.app))
|
resp = str(req.get_response(self.app))
|
||||||
resp = "HTTP/1.0 %s" % resp
|
resp = "HTTP/1.0 %s" % resp
|
||||||
sock = FakeHttplibSocket(resp)
|
sock = FakeHttplibSocket(resp)
|
||||||
self.http_response = httplib.HTTPResponse(sock)
|
self.http_response = http_client.HTTPResponse(sock)
|
||||||
self.http_response.begin()
|
self.http_response.begin()
|
||||||
|
|
||||||
def getresponse(self):
|
def getresponse(self):
|
||||||
|
@ -613,7 +612,7 @@ def wire_HTTPConnection_to_WSGI(host, app):
|
||||||
|
|
||||||
After calling this method, when any code calls
|
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
|
the connection object will be a fake. Its requests will be sent directly
|
||||||
to the given WSGI app rather than through a socket.
|
to the given WSGI app rather than through a socket.
|
||||||
|
@ -641,8 +640,9 @@ def wire_HTTPConnection_to_WSGI(host, app):
|
||||||
else:
|
else:
|
||||||
return self.wrapped(connection_host, *args, **kwargs)
|
return self.wrapped(connection_host, *args, **kwargs)
|
||||||
|
|
||||||
oldHTTPConnection = httplib.HTTPConnection
|
oldHTTPConnection = http_client.HTTPConnection
|
||||||
httplib.HTTPConnection = HTTPConnectionDecorator(httplib.HTTPConnection)
|
http_client.HTTPConnection = HTTPConnectionDecorator(
|
||||||
|
http_client.HTTPConnection)
|
||||||
return oldHTTPConnection
|
return oldHTTPConnection
|
||||||
|
|
||||||
|
|
||||||
|
@ -654,7 +654,7 @@ class WsgiLimiterProxyTest(BaseLimitTestSuite):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""
|
"""
|
||||||
Do some nifty HTTP/WSGI magic which allows for WSGI to be called
|
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()
|
super(WsgiLimiterProxyTest, self).setUp()
|
||||||
self.app = limits.WsgiLimiter(TEST_LIMITS)
|
self.app = limits.WsgiLimiter(TEST_LIMITS)
|
||||||
|
@ -681,7 +681,7 @@ class WsgiLimiterProxyTest(BaseLimitTestSuite):
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
# restore original HTTPConnection object
|
# restore original HTTPConnection object
|
||||||
httplib.HTTPConnection = self.oldHTTPConnection
|
http_client.HTTPConnection = self.oldHTTPConnection
|
||||||
super(WsgiLimiterProxyTest, self).tearDown()
|
super(WsgiLimiterProxyTest, self).tearDown()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -23,8 +23,6 @@
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import subprocess
|
import subprocess
|
||||||
from urllib import unquote
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
EVENT_AVAILABLE = True
|
EVENT_AVAILABLE = True
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
@ -34,6 +32,7 @@ from proboscis.asserts import assert_true
|
||||||
from proboscis.asserts import Check
|
from proboscis.asserts import Check
|
||||||
from proboscis.asserts import fail
|
from proboscis.asserts import fail
|
||||||
from proboscis import SkipTest
|
from proboscis import SkipTest
|
||||||
|
from six.moves.urllib.parse import unquote
|
||||||
from sqlalchemy import create_engine
|
from sqlalchemy import create_engine
|
||||||
from troveclient.compat import Dbaas
|
from troveclient.compat import Dbaas
|
||||||
from troveclient.compat import exceptions
|
from troveclient.compat import exceptions
|
||||||
|
|
Loading…
Reference in New Issue