From c0af385173658fa149bddf155aeb1ae0bbd4eb7e Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Thu, 8 Oct 2015 15:03:52 +0200 Subject: [PATCH] py3: Replace urllib imports with six.moves.urllib The urllib, urllib2 and urlparse modules of Python 2 were reorganized into a new urllib namespace on Python 3. Replace urllib, urllib2 and urlparse imports with six.moves.urllib to make the modified code compatible with Python 2 and Python 3. The initial patch was generated by the urllib operation of the sixer tool on: bin/* swift/ test/. Change-Id: I61a8c7fb7972eabc7da8dad3b3d34bceee5c5d93 --- bin/swift-account-audit | 2 +- swift/cli/info.py | 7 ++++--- swift/cli/recon.py | 2 +- swift/common/bufferedhttp.py | 2 +- swift/common/constraints.py | 6 +++--- swift/common/internal_client.py | 4 ++-- swift/common/middleware/bulk.py | 2 +- swift/common/middleware/dlo.py | 2 +- swift/common/middleware/formpost.py | 2 +- swift/common/middleware/list_endpoints.py | 3 ++- swift/common/middleware/name_check.py | 3 ++- swift/common/middleware/proxy_logging.py | 2 +- swift/common/middleware/tempauth.py | 2 +- swift/common/middleware/tempurl.py | 5 +++-- swift/common/middleware/versioned_writes.py | 2 +- swift/common/request_helpers.py | 2 +- swift/common/wsgi.py | 2 +- swift/obj/expirer.py | 5 +++-- swift/obj/ssync_receiver.py | 9 +++++---- swift/obj/ssync_sender.py | 11 +++++++---- swift/proxy/controllers/account.py | 3 ++- swift/proxy/controllers/base.py | 3 ++- swift/proxy/controllers/container.py | 2 +- swift/proxy/controllers/obj.py | 3 ++- test/functional/__init__.py | 2 +- test/functional/swift_test_client.py | 14 +++++++------- test/functional/tests.py | 10 +++++----- test/probe/brain.py | 2 +- .../probe/test_account_get_fake_responses_match.py | 2 +- test/probe/test_container_sync.py | 2 +- test/unit/cli/test_recon.py | 4 ++-- test/unit/common/middleware/test_bulk.py | 11 ++++++----- test/unit/common/middleware/test_proxy_logging.py | 2 +- test/unit/common/test_direct_client.py | 8 ++++---- test/unit/common/test_internal_client.py | 2 +- test/unit/common/test_swob.py | 2 +- test/unit/common/test_wsgi.py | 2 +- test/unit/container/test_reconciler.py | 8 ++++---- test/unit/obj/test_expirer.py | 4 ++-- test/unit/obj/test_ssync_sender.py | 7 ++++--- test/unit/proxy/test_server.py | 3 ++- test/unit/proxy/test_sysmeta.py | 4 +++- 42 files changed, 96 insertions(+), 79 deletions(-) diff --git a/bin/swift-account-audit b/bin/swift-account-audit index aa3bce4770..93c8c8c044 100755 --- a/bin/swift-account-audit +++ b/bin/swift-account-audit @@ -16,7 +16,6 @@ import os import sys -from urllib import quote from hashlib import md5 import getopt from itertools import chain @@ -24,6 +23,7 @@ from itertools import chain import simplejson from eventlet.greenpool import GreenPool from eventlet.event import Event +from six.moves.urllib.parse import quote from swift.common.ring import Ring from swift.common.utils import split_path diff --git a/swift/cli/info.py b/swift/cli/info.py index eed4dea164..ba02cfd25a 100644 --- a/swift/cli/info.py +++ b/swift/cli/info.py @@ -14,9 +14,10 @@ from __future__ import print_function import itertools import os import sqlite3 -import urllib from hashlib import md5 +from six.moves import urllib + from swift.common.utils import hash_path, storage_directory, \ Timestamp from swift.common.ring import Ring @@ -100,7 +101,7 @@ def print_ring_locations(ring, datadir, account, container=None, obj=None, for node in primary_nodes: cmd = 'curl -I -XHEAD "http://%s:%s/%s/%s/%s"' \ % (node['ip'], node['port'], node['device'], part, - urllib.quote(target)) + urllib.parse.quote(target)) if policy_index is not None: cmd += ' -H "%s: %s"' % ('X-Backend-Storage-Policy-Index', policy_index) @@ -108,7 +109,7 @@ def print_ring_locations(ring, datadir, account, container=None, obj=None, for node in handoff_nodes: cmd = 'curl -I -XHEAD "http://%s:%s/%s/%s/%s"' \ % (node['ip'], node['port'], node['device'], part, - urllib.quote(target)) + urllib.parse.quote(target)) if policy_index is not None: cmd += ' -H "%s: %s"' % ('X-Backend-Storage-Policy-Index', policy_index) diff --git a/swift/cli/recon.py b/swift/cli/recon.py index 6c5894a5ae..f77a00ff09 100644 --- a/swift/cli/recon.py +++ b/swift/cli/recon.py @@ -19,9 +19,9 @@ from __future__ import print_function from eventlet.green import urllib2 +from six.moves.urllib.parse import urlparse from swift.common.utils import SWIFT_CONF_FILE from swift.common.ring import Ring -from urlparse import urlparse from hashlib import md5 import eventlet import json diff --git a/swift/common/bufferedhttp.py b/swift/common/bufferedhttp.py index d5c149ad93..2db36b155f 100644 --- a/swift/common/bufferedhttp.py +++ b/swift/common/bufferedhttp.py @@ -28,7 +28,6 @@ BufferedHTTPResponse. from swift import gettext_ as _ from swift.common import constraints -from urllib import quote import logging import time import socket @@ -36,6 +35,7 @@ import socket import eventlet from eventlet.green.httplib import CONTINUE, HTTPConnection, HTTPMessage, \ HTTPResponse, HTTPSConnection, _UNKNOWN +from six.moves.urllib.parse import quote import six httplib = eventlet.import_patched('httplib') diff --git a/swift/common/constraints.py b/swift/common/constraints.py index f36edb6f83..b72ed42c01 100644 --- a/swift/common/constraints.py +++ b/swift/common/constraints.py @@ -15,12 +15,12 @@ import functools import os -import urllib import time -from urllib import unquote import six from six.moves.configparser import ConfigParser, NoSectionError, NoOptionError +from six.moves import urllib +from six.moves.urllib.parse import unquote from swift.common import utils, exceptions from swift.common.swob import HTTPBadRequest, HTTPLengthRequired, \ @@ -246,7 +246,7 @@ def check_mount(root, drive): :param drive: drive name to be checked :returns: True if it is a valid mounted device, False otherwise """ - if not (urllib.quote_plus(drive) == drive): + if not (urllib.parse.quote_plus(drive) == drive): return False path = os.path.join(root, drive) return utils.ismount(path) diff --git a/swift/common/internal_client.py b/swift/common/internal_client.py index 2c9cc67e86..6e829b7b68 100644 --- a/swift/common/internal_client.py +++ b/swift/common/internal_client.py @@ -17,12 +17,12 @@ from eventlet import sleep, Timeout from eventlet.green import httplib, socket, urllib2 import json from six.moves import range +from six.moves import urllib import struct from sys import exc_info import zlib from swift import gettext_ as _ from time import gmtime, strftime, time -import urlparse from zlib import compressobj from swift.common.utils import quote @@ -760,7 +760,7 @@ class SimpleClient(object): req = urllib2.Request(url, headers=headers, data=contents) if proxy: - proxy = urlparse.urlparse(proxy) + proxy = urllib.parse.urlparse(proxy) req.set_proxy(proxy.netloc, proxy.scheme) req.get_method = lambda: method conn = urllib2.urlopen(req, timeout=timeout) diff --git a/swift/common/middleware/bulk.py b/swift/common/middleware/bulk.py index d363068385..1d4199b083 100644 --- a/swift/common/middleware/bulk.py +++ b/swift/common/middleware/bulk.py @@ -13,8 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +from six.moves.urllib.parse import quote, unquote import tarfile -from urllib import quote, unquote from xml.sax import saxutils from time import time from eventlet import sleep diff --git a/swift/common/middleware/dlo.py b/swift/common/middleware/dlo.py index eed0b566a5..2cf8f2fc98 100644 --- a/swift/common/middleware/dlo.py +++ b/swift/common/middleware/dlo.py @@ -17,6 +17,7 @@ import os import six from six.moves.configparser import ConfigParser, NoSectionError, NoOptionError +from six.moves.urllib.parse import unquote from hashlib import md5 from swift.common import constraints @@ -29,7 +30,6 @@ from swift.common.utils import get_logger, json, \ closing_if_possible from swift.common.request_helpers import SegmentedIterable from swift.common.wsgi import WSGIContext, make_subrequest -from urllib import unquote class GetContext(WSGIContext): diff --git a/swift/common/middleware/formpost.py b/swift/common/middleware/formpost.py index a30fa1a2f7..e283478a96 100644 --- a/swift/common/middleware/formpost.py +++ b/swift/common/middleware/formpost.py @@ -115,8 +115,8 @@ __all__ = ['FormPost', 'filter_factory', 'READ_CHUNK_SIZE', 'MAX_VALUE_LENGTH'] import hmac from hashlib import sha1 from time import time -from urllib import quote +from six.moves.urllib.parse import quote from swift.common.exceptions import MimeInvalid from swift.common.middleware.tempurl import get_tempurl_keys_from_metadata from swift.common.utils import streq_const_time, register_swift_info, \ diff --git a/swift/common/middleware/list_endpoints.py b/swift/common/middleware/list_endpoints.py index 37594b3b3f..fb41bb6dd3 100644 --- a/swift/common/middleware/list_endpoints.py +++ b/swift/common/middleware/list_endpoints.py @@ -78,7 +78,8 @@ with this middleware enabled should not be open to an untrusted environment (everyone can query the locality data using this middleware). """ -from urllib import quote, unquote + +from six.moves.urllib.parse import quote, unquote from swift.common.ring import Ring from swift.common.utils import json, get_logger, split_path diff --git a/swift/common/middleware/name_check.py b/swift/common/middleware/name_check.py index d9431a75cd..c2ddbbaf0f 100644 --- a/swift/common/middleware/name_check.py +++ b/swift/common/middleware/name_check.py @@ -40,9 +40,10 @@ The filter returns HTTPBadRequest if path is invalid. @author: eamonn-otoole ''' +from six.moves.urllib.parse import unquote + import re from swift.common.utils import get_logger -from urllib2 import unquote from swift.common.swob import Request, HTTPBadRequest diff --git a/swift/common/middleware/proxy_logging.py b/swift/common/middleware/proxy_logging.py index 79a4ed967e..70c77fb155 100644 --- a/swift/common/middleware/proxy_logging.py +++ b/swift/common/middleware/proxy_logging.py @@ -73,8 +73,8 @@ bandwidth usage will want to only sum up logs with no swift.source. import sys import time -from urllib import quote, unquote +from six.moves.urllib.parse import quote, unquote from swift.common.swob import Request from swift.common.utils import (get_logger, get_remote_client, get_valid_utf8_str, config_true_value, diff --git a/swift/common/middleware/tempauth.py b/swift/common/middleware/tempauth.py index 2b517ac9ae..4a3b2b0ec8 100644 --- a/swift/common/middleware/tempauth.py +++ b/swift/common/middleware/tempauth.py @@ -17,13 +17,13 @@ from __future__ import print_function from time import time from traceback import format_exc -from urllib import unquote from uuid import uuid4 from hashlib import sha1 import hmac import base64 from eventlet import Timeout +from six.moves.urllib.parse import unquote from swift.common.swob import Response, Request from swift.common.swob import HTTPBadRequest, HTTPForbidden, HTTPNotFound, \ HTTPUnauthorized diff --git a/swift/common/middleware/tempurl.py b/swift/common/middleware/tempurl.py index 10278bf7b5..59d9d44277 100644 --- a/swift/common/middleware/tempurl.py +++ b/swift/common/middleware/tempurl.py @@ -118,8 +118,9 @@ __all__ = ['TempURL', 'filter_factory', from os.path import basename from time import time -from urllib import urlencode -from urlparse import parse_qs + +from six.moves.urllib.parse import parse_qs +from six.moves.urllib.parse import urlencode from swift.proxy.controllers.base import get_account_info, get_container_info from swift.common.swob import HeaderKeyDict, HTTPUnauthorized, HTTPBadRequest diff --git a/swift/common/middleware/versioned_writes.py b/swift/common/middleware/versioned_writes.py index bac923312c..4c2f8a7d31 100644 --- a/swift/common/middleware/versioned_writes.py +++ b/swift/common/middleware/versioned_writes.py @@ -114,8 +114,8 @@ Disable versioning from a container (x is any value except empty):: """ import six +from six.moves.urllib.parse import quote, unquote import time -from urllib import quote, unquote from swift.common.utils import get_logger, Timestamp, json, \ register_swift_info, config_true_value from swift.common.request_helpers import get_sys_meta_prefix diff --git a/swift/common/request_helpers.py b/swift/common/request_helpers.py index 6d02463e63..e30ce94eb1 100644 --- a/swift/common/request_helpers.py +++ b/swift/common/request_helpers.py @@ -24,9 +24,9 @@ import hashlib import itertools import sys import time -from urllib import unquote import six +from six.moves.urllib.parse import unquote from swift import gettext_ as _ from swift.common.storage_policy import POLICIES diff --git a/swift/common/wsgi.py b/swift/common/wsgi.py index e7504355b6..5d8ded023a 100644 --- a/swift/common/wsgi.py +++ b/swift/common/wsgi.py @@ -33,7 +33,7 @@ from paste.deploy import loadwsgi from eventlet.green import socket, ssl, os as green_os from six import BytesIO from six import StringIO -from urllib import unquote +from six.moves.urllib.parse import unquote from swift.common import utils, constraints from swift.common.storage_policy import BindPortsCache diff --git a/swift/obj/expirer.py b/swift/obj/expirer.py index d9b124d49c..7f26f129c3 100644 --- a/swift/obj/expirer.py +++ b/swift/obj/expirer.py @@ -13,7 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -import urllib +from six.moves import urllib + from random import random from time import time from os.path import join @@ -290,7 +291,7 @@ class ObjectExpirer(Daemon): :param timestamp: The timestamp the X-Delete-At value must match to perform the actual delete. """ - path = '/v1/' + urllib.quote(actual_obj.lstrip('/')) + path = '/v1/' + urllib.parse.quote(actual_obj.lstrip('/')) self.swift.make_request('DELETE', path, {'X-If-Delete-At': str(timestamp)}, (2, HTTP_PRECONDITION_FAILED)) diff --git a/swift/obj/ssync_receiver.py b/swift/obj/ssync_receiver.py index 7e00e8451c..5f6b7d3b0f 100644 --- a/swift/obj/ssync_receiver.py +++ b/swift/obj/ssync_receiver.py @@ -13,11 +13,11 @@ # See the License for the specific language governing permissions and # limitations under the License. -import urllib import eventlet import eventlet.wsgi import eventlet.greenio +from six.moves import urllib from swift.common import exceptions from swift.common import http @@ -38,11 +38,12 @@ def decode_missing(line): """ result = {} parts = line.split() - result['object_hash'], t_data = (urllib.unquote(v) for v in parts[:2]) + result['object_hash'] = urllib.parse.unquote(parts[0]) + t_data = urllib.parse.unquote(parts[1]) result['ts_data'] = result['ts_meta'] = Timestamp(t_data) if len(parts) > 2: # allow for a comma separated list of k:v pairs to future-proof - subparts = urllib.unquote(parts[2]).split(',') + subparts = urllib.parse.unquote(parts[2]).split(',') for item in [subpart for subpart in subparts if ':' in subpart]: k, v = item.split(':') if k == 'm': @@ -78,7 +79,7 @@ def encode_wanted(remote, local): # this is the inverse of _decode_wanted's key_map key_map = dict(data='d', meta='m') parts = ''.join(v for k, v in sorted(key_map.items()) if want.get(k)) - return '%s %s' % (urllib.quote(remote['object_hash']), parts) + return '%s %s' % (urllib.parse.quote(remote['object_hash']), parts) return None diff --git a/swift/obj/ssync_sender.py b/swift/obj/ssync_sender.py index 82a1ae4b13..0003a0c05d 100644 --- a/swift/obj/ssync_sender.py +++ b/swift/obj/ssync_sender.py @@ -13,7 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -import urllib +from six.moves import urllib + from itertools import ifilter from swift.common import bufferedhttp from swift.common import exceptions @@ -29,7 +30,9 @@ def encode_missing(object_hash, ts_data, ts_meta=None): The decoder for this line is :py:func:`~swift.obj.ssync_receiver.decode_missing` """ - msg = '%s %s' % (urllib.quote(object_hash), urllib.quote(ts_data.internal)) + msg = ('%s %s' + % (urllib.parse.quote(object_hash), + urllib.parse.quote(ts_data.internal))) if ts_meta and ts_meta != ts_data: delta = ts_meta.raw - ts_data.raw msg = '%s m:%x' % (msg, delta) @@ -318,14 +321,14 @@ class Sender(object): msg = ':UPDATES: START\r\n' self.connection.send('%x\r\n%s\r\n' % (len(msg), msg)) for object_hash, want in self.send_map.items(): - object_hash = urllib.unquote(object_hash) + object_hash = urllib.parse.unquote(object_hash) try: df = self.df_mgr.get_diskfile_from_hash( self.job['device'], self.job['partition'], object_hash, self.job['policy'], frag_index=self.job.get('frag_index')) except exceptions.DiskFileNotExist: continue - url_path = urllib.quote( + url_path = urllib.parse.quote( '/%s/%s/%s' % (df.account, df.container, df.obj)) try: df.open() diff --git a/swift/proxy/controllers/account.py b/swift/proxy/controllers/account.py index 915e1c481c..25cbc62187 100644 --- a/swift/proxy/controllers/account.py +++ b/swift/proxy/controllers/account.py @@ -13,8 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. +from six.moves.urllib.parse import unquote + from swift import gettext_ as _ -from urllib import unquote from swift.account.utils import account_listing_response from swift.common.request_helpers import get_listing_content_type diff --git a/swift/proxy/controllers/base.py b/swift/proxy/controllers/base.py index 72842a433c..0213f41e58 100644 --- a/swift/proxy/controllers/base.py +++ b/swift/proxy/controllers/base.py @@ -24,6 +24,8 @@ # These shenanigans are to ensure all related objects can be garbage # collected. We've seen objects hang around forever otherwise. +from six.moves.urllib.parse import quote + import os import time import functools @@ -32,7 +34,6 @@ import itertools import operator from sys import exc_info from swift import gettext_ as _ -from urllib import quote from eventlet import sleep from eventlet.timeout import Timeout diff --git a/swift/proxy/controllers/container.py b/swift/proxy/controllers/container.py index 3e4a2bb031..d5e52618c2 100644 --- a/swift/proxy/controllers/container.py +++ b/swift/proxy/controllers/container.py @@ -14,9 +14,9 @@ # limitations under the License. from swift import gettext_ as _ -from urllib import unquote import time +from six.moves.urllib.parse import unquote from swift.common.utils import public, csv_append, Timestamp from swift.common.constraints import check_metadata from swift.common import constraints diff --git a/swift/proxy/controllers/obj.py b/swift/proxy/controllers/obj.py index bdb2028f36..5a8f3163de 100644 --- a/swift/proxy/controllers/obj.py +++ b/swift/proxy/controllers/obj.py @@ -24,6 +24,8 @@ # These shenanigans are to ensure all related objects can be garbage # collected. We've seen objects hang around forever otherwise. +from six.moves.urllib.parse import unquote, quote + import collections import itertools import mimetypes @@ -32,7 +34,6 @@ import math import random from hashlib import md5 from swift import gettext_ as _ -from urllib import unquote, quote from greenlet import GreenletExit from eventlet import GreenPile diff --git a/test/functional/__init__.py b/test/functional/__init__.py index f07d162691..242a4667a9 100644 --- a/test/functional/__init__.py +++ b/test/functional/__init__.py @@ -16,6 +16,7 @@ from __future__ import print_function import mock import os +from six.moves.urllib.parse import urlparse import sys import pickle import socket @@ -26,7 +27,6 @@ import functools import random from time import time, sleep -from urlparse import urlparse from nose import SkipTest from contextlib import closing from gzip import GzipFile diff --git a/test/functional/swift_test_client.py b/test/functional/swift_test_client.py index 0148ba7b33..68dcbea017 100644 --- a/test/functional/swift_test_client.py +++ b/test/functional/swift_test_client.py @@ -18,7 +18,6 @@ import os import random import socket import time -import urllib import simplejson as json from nose import SkipTest @@ -26,6 +25,7 @@ from xml.dom import minidom import six from six.moves import http_client +from six.moves import urllib from swiftclient import get_auth from swift.common import constraints @@ -220,7 +220,7 @@ class Connection(object): return '/' + self.storage_url.split('/')[1] if path: - quote = urllib.quote + quote = urllib.parse.quote if cfg.get('no_quote') or cfg.get('no_path_quote'): quote = lambda x: x return '%s/%s' % (self.storage_url, @@ -260,7 +260,7 @@ class Connection(object): path = self.make_path(path, cfg=cfg) headers = self.make_headers(hdrs, cfg=cfg) if isinstance(parms, dict) and parms: - quote = urllib.quote + quote = urllib.parse.quote if cfg.get('no_quote') or cfg.get('no_parms_quote'): quote = lambda x: x query_args = ['%s=%s' % (quote(x), quote(str(y))) @@ -328,7 +328,7 @@ class Connection(object): headers.pop('Content-Length', None) if isinstance(parms, dict) and parms: - quote = urllib.quote + quote = urllib.parse.quote if cfg.get('no_quote') or cfg.get('no_parms_quote'): quote = lambda x: x query_args = ['%s=%s' % (quote(x), quote(str(y))) @@ -698,7 +698,7 @@ class File(Base): headers.update(hdrs) if 'Destination' in headers: - headers['Destination'] = urllib.quote(headers['Destination']) + headers['Destination'] = urllib.parse.quote(headers['Destination']) return self.conn.make_request('COPY', self.path, hdrs=headers, parms=parms) == 201 @@ -722,9 +722,9 @@ class File(Base): if 'Destination-Account' in headers: headers['Destination-Account'] = \ - urllib.quote(headers['Destination-Account']) + urllib.parse.quote(headers['Destination-Account']) if 'Destination' in headers: - headers['Destination'] = urllib.quote(headers['Destination']) + headers['Destination'] = urllib.parse.quote(headers['Destination']) return self.conn.make_request('COPY', self.path, hdrs=headers, parms=parms) == 201 diff --git a/test/functional/tests.py b/test/functional/tests.py index 7fa3ceb45e..dd92827a4f 100644 --- a/test/functional/tests.py +++ b/test/functional/tests.py @@ -22,9 +22,9 @@ import json import locale import random import six +from six.moves import urllib import time import unittest -import urllib import uuid from copy import deepcopy import eventlet @@ -281,7 +281,7 @@ class TestAccount(Base): inserted_html = 'Hello World' hax = 'AUTH_haxx"\nContent-Length: %d\n\n%s' % (len(inserted_html), inserted_html) - quoted_hax = urllib.quote(hax) + quoted_hax = urllib.parse.quote(hax) conn.connection.request('GET', '/v1/' + quoted_hax, None, {}) resp = conn.connection.getresponse() resp_headers = dict(resp.getheaders()) @@ -3152,7 +3152,7 @@ class TestTempurl(Base): def tempurl_sig(self, method, expires, path, key): return hmac.new( key, - '%s\n%s\n%s' % (method, expires, urllib.unquote(path)), + '%s\n%s\n%s' % (method, expires, urllib.parse.unquote(path)), hashlib.sha1).hexdigest() def test_GET(self): @@ -3441,7 +3441,7 @@ class TestContainerTempurl(Base): def tempurl_sig(self, method, expires, path, key): return hmac.new( key, - '%s\n%s\n%s' % (method, expires, urllib.unquote(path)), + '%s\n%s\n%s' % (method, expires, urllib.parse.unquote(path)), hashlib.sha1).hexdigest() def test_GET(self): @@ -3706,7 +3706,7 @@ class TestSloTempurl(Base): def tempurl_sig(self, method, expires, path, key): return hmac.new( key, - '%s\n%s\n%s' % (method, expires, urllib.unquote(path)), + '%s\n%s\n%s' % (method, expires, urllib.parse.unquote(path)), hashlib.sha1).hexdigest() def test_GET(self): diff --git a/test/probe/brain.py b/test/probe/brain.py index 9ec907c0a2..ea5c2cc5ee 100644 --- a/test/probe/brain.py +++ b/test/probe/brain.py @@ -16,10 +16,10 @@ import sys import itertools import uuid from optparse import OptionParser -from urlparse import urlparse import random import six +from six.moves.urllib.parse import urlparse from swift.common.manager import Manager from swift.common import utils, ring diff --git a/test/probe/test_account_get_fake_responses_match.py b/test/probe/test_account_get_fake_responses_match.py index 46ddb16de0..bd159300ea 100755 --- a/test/probe/test_account_get_fake_responses_match.py +++ b/test/probe/test_account_get_fake_responses_match.py @@ -18,9 +18,9 @@ import re import unittest from six.moves import http_client +from six.moves.urllib.parse import urlparse from swiftclient import get_auth from test.probe.common import ReplProbeTest -from urlparse import urlparse class TestAccountGetFakeResponsesMatch(ReplProbeTest): diff --git a/test/probe/test_container_sync.py b/test/probe/test_container_sync.py index 19ba231186..4288dd4644 100644 --- a/test/probe/test_container_sync.py +++ b/test/probe/test_container_sync.py @@ -13,11 +13,11 @@ # limitations under the License. import uuid -from urlparse import urlparse import random from nose import SkipTest import unittest +from six.moves.urllib.parse import urlparse from swiftclient import client from swift.common.manager import Manager diff --git a/test/unit/cli/test_recon.py b/test/unit/cli/test_recon.py index 3b0d11f889..6fef1d3332 100644 --- a/test/unit/cli/test_recon.py +++ b/test/unit/cli/test_recon.py @@ -23,10 +23,10 @@ import string import tempfile import time import unittest -import urlparse from eventlet.green import urllib2 from six import StringIO +from six.moves import urllib from swift.cli import recon from swift.common import utils @@ -342,7 +342,7 @@ class TestReconCommands(unittest.TestCase): def mock_responses(self, resps): def fake_urlopen(url, timeout): - scheme, netloc, path, _, _, _ = urlparse.urlparse(url) + scheme, netloc, path, _, _, _ = urllib.parse.urlparse(url) self.assertEqual(scheme, 'http') # can't handle anything else self.assertTrue(path.startswith('/recon/')) diff --git a/test/unit/common/middleware/test_bulk.py b/test/unit/common/middleware/test_bulk.py index c961b04e19..a3982887c9 100644 --- a/test/unit/common/middleware/test_bulk.py +++ b/test/unit/common/middleware/test_bulk.py @@ -15,10 +15,10 @@ # limitations under the License. import numbers +from six.moves import urllib import unittest import os import tarfile -import urllib import zlib import mock import six @@ -763,10 +763,11 @@ class TestDelete(unittest.TestCase): resp_data = utils.json.loads(resp_body) self.assertEquals(resp_data['Number Deleted'], 1) self.assertEquals(len(resp_data['Errors']), 2) - self.assertEquals( - resp_data['Errors'], - [[urllib.quote('c/ objbadutf8'), '412 Precondition Failed'], - [urllib.quote('/c/f\xdebadutf8'), '412 Precondition Failed']]) + self.assertEquals(resp_data['Errors'], + [[urllib.parse.quote('c/ objbadutf8'), + '412 Precondition Failed'], + [urllib.parse.quote('/c/f\xdebadutf8'), + '412 Precondition Failed']]) def test_bulk_delete_no_body(self): req = Request.blank('/unauth/AUTH_acc/') diff --git a/test/unit/common/middleware/test_proxy_logging.py b/test/unit/common/middleware/test_proxy_logging.py index c24f1c48b2..d7d22aaae4 100644 --- a/test/unit/common/middleware/test_proxy_logging.py +++ b/test/unit/common/middleware/test_proxy_logging.py @@ -14,11 +14,11 @@ # limitations under the License. import unittest -from urllib import unquote from logging.handlers import SysLogHandler import mock from six import BytesIO +from six.moves.urllib.parse import unquote from test.unit import FakeLogger from swift.common.utils import get_logger, split_path diff --git a/test/unit/common/test_direct_client.py b/test/unit/common/test_direct_client.py index 38accd014d..fe89f57693 100644 --- a/test/unit/common/test_direct_client.py +++ b/test/unit/common/test_direct_client.py @@ -16,13 +16,13 @@ import json import unittest import os -import urllib from contextlib import contextmanager from hashlib import md5 import time import mock import six +from six.moves import urllib from swift.common import direct_client from swift.common.exceptions import ClientException @@ -97,13 +97,13 @@ class TestDirectClient(unittest.TestCase): self.account = u'\u062a account' self.container = u'\u062a container' self.obj = u'\u062a obj/name' - self.account_path = '/sda/0/%s' % urllib.quote( + self.account_path = '/sda/0/%s' % urllib.parse.quote( self.account.encode('utf-8')) self.container_path = '/sda/0/%s/%s' % tuple( - urllib.quote(p.encode('utf-8')) for p in ( + urllib.parse.quote(p.encode('utf-8')) for p in ( self.account, self.container)) self.obj_path = '/sda/0/%s/%s/%s' % tuple( - urllib.quote(p.encode('utf-8')) for p in ( + urllib.parse.quote(p.encode('utf-8')) for p in ( self.account, self.container, self.obj)) self.user_agent = 'direct-client %s' % os.getpid() diff --git a/test/unit/common/test_internal_client.py b/test/unit/common/test_internal_client.py index 3c817fbc9b..66c9d04a22 100644 --- a/test/unit/common/test_internal_client.py +++ b/test/unit/common/test_internal_client.py @@ -16,7 +16,6 @@ import json import mock import unittest -from urllib import quote import zlib from textwrap import dedent import os @@ -24,6 +23,7 @@ import os import six from six import StringIO from six.moves import range +from six.moves.urllib.parse import quote from test.unit import FakeLogger from eventlet.green import urllib2 from swift.common import internal_client diff --git a/test/unit/common/test_swob.py b/test/unit/common/test_swob.py index 6257d63c84..f57eabdf1f 100644 --- a/test/unit/common/test_swob.py +++ b/test/unit/common/test_swob.py @@ -19,9 +19,9 @@ import datetime import unittest import re import time -from urllib import quote from six import BytesIO +from six.moves.urllib.parse import quote import swift.common.swob from swift.common import utils, exceptions diff --git a/test/unit/common/test_wsgi.py b/test/unit/common/test_wsgi.py index 1e786e273c..e2b3a8c3a5 100644 --- a/test/unit/common/test_wsgi.py +++ b/test/unit/common/test_wsgi.py @@ -24,11 +24,11 @@ import os from textwrap import dedent from contextlib import nested from collections import defaultdict -from urllib import quote from eventlet import listen from six import BytesIO from six import StringIO +from six.moves.urllib.parse import quote import mock diff --git a/test/unit/container/test_reconciler.py b/test/unit/container/test_reconciler.py index 1b41227608..e962136140 100644 --- a/test/unit/container/test_reconciler.py +++ b/test/unit/container/test_reconciler.py @@ -17,7 +17,6 @@ import mock import operator import time import unittest -import urllib import socket import os import errno @@ -26,6 +25,7 @@ import random from collections import defaultdict from datetime import datetime +from six.moves import urllib from swift.container import reconciler from swift.container.server import gen_resp_headers from swift.common.direct_client import ClientException @@ -153,7 +153,7 @@ class FakeInternalClient(reconciler.InternalClient): obj_name = container_listing_data[-1]['name'] # client should quote and encode marker end_qry_string = '?format=json&marker=%s&end_marker=' % ( - urllib.quote(obj_name.encode('utf-8'))) + urllib.parse.quote(obj_name.encode('utf-8'))) self.app.register('GET', container_path + end_qry_string, swob.HTTPOk, container_headers, json.dumps([])) @@ -170,7 +170,7 @@ class FakeInternalClient(reconciler.InternalClient): swob.HTTPOk, account_headers, json.dumps(account_listing_data)) end_qry_string = '?format=json&marker=%s&end_marker=' % ( - urllib.quote(account_listing_data[-1]['name'])) + urllib.parse.quote(account_listing_data[-1]['name'])) self.app.register('GET', account_path + end_qry_string, swob.HTTPOk, account_headers, json.dumps([])) @@ -685,7 +685,7 @@ class TestReconcilerUtils(unittest.TestCase): def listing_qs(marker): return "?format=json&marker=%s&end_marker=" % \ - urllib.quote(marker.encode('utf-8')) + urllib.parse.quote(marker.encode('utf-8')) class TestReconciler(unittest.TestCase): diff --git a/test/unit/obj/test_expirer.py b/test/unit/obj/test_expirer.py index 0aa3091efb..17fddf174d 100644 --- a/test/unit/obj/test_expirer.py +++ b/test/unit/obj/test_expirer.py @@ -13,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -import urllib from time import time from unittest import main, TestCase from test.unit import FakeRing, mocked_http_conn, debug_logger @@ -23,6 +22,7 @@ from shutil import rmtree import mock import six +from six.moves import urllib from swift.common import internal_client, utils from swift.obj import expirer @@ -746,7 +746,7 @@ class TestObjectExpirer(TestCase): x.delete_actual_object(name, timestamp) self.assertEqual(x.swift.make_request.call_count, 1) self.assertEqual(x.swift.make_request.call_args[0][1], - '/v1/' + urllib.quote(name)) + '/v1/' + urllib.parse.quote(name)) def test_pop_queue(self): class InternalClient(object): diff --git a/test/unit/obj/test_ssync_sender.py b/test/unit/obj/test_ssync_sender.py index e9edafd4f5..8d049fadc7 100644 --- a/test/unit/obj/test_ssync_sender.py +++ b/test/unit/obj/test_ssync_sender.py @@ -20,12 +20,12 @@ import shutil import tempfile import time import unittest -import urllib import eventlet import itertools import mock import six +from six.moves import urllib from swift.common import exceptions, utils from swift.common.storage_policy import POLICIES @@ -2368,7 +2368,8 @@ class TestSsyncReplication(TestBaseSsync): def _legacy_check_missing(self, line): # reproduces behavior of 'legacy' ssync receiver missing_checks() parts = line.split() - object_hash, timestamp = [urllib.unquote(v) for v in parts[:2]] + object_hash = urllib.parse.unquote(parts[0]) + timestamp = urllib.parse.unquote(parts[1]) want = False try: df = self.diskfile_mgr.get_diskfile_from_hash( @@ -2386,7 +2387,7 @@ class TestSsyncReplication(TestBaseSsync): else: want = df.timestamp < timestamp if want: - return urllib.quote(object_hash) + return urllib.parse.quote(object_hash) return None # run the sync protocol... diff --git a/test/unit/proxy/test_server.py b/test/unit/proxy/test_server.py index 1c8d346dd7..baa8762376 100644 --- a/test/unit/proxy/test_server.py +++ b/test/unit/proxy/test_server.py @@ -28,7 +28,6 @@ from shutil import rmtree import gc import time from textwrap import dedent -from urllib import quote from hashlib import md5 from pyeclib.ec_iface import ECDriverError from tempfile import mkdtemp, NamedTemporaryFile @@ -46,6 +45,8 @@ from eventlet.green import httplib from six import BytesIO from six import StringIO from six.moves import range +from six.moves.urllib.parse import quote + from swift.common.utils import hash_path, json, storage_directory, \ parse_content_type, parse_mime_headers, \ iter_multipart_mime_documents, public diff --git a/test/unit/proxy/test_sysmeta.py b/test/unit/proxy/test_sysmeta.py index 98e9a76e9c..3b3f8ddfd9 100644 --- a/test/unit/proxy/test_sysmeta.py +++ b/test/unit/proxy/test_sysmeta.py @@ -12,10 +12,12 @@ # implied. # See the License for the specific language governing permissions and # limitations under the License. + +from six.moves.urllib.parse import quote + import unittest import os from tempfile import mkdtemp -from urllib import quote import shutil from swift.common.storage_policy import StoragePolicy from swift.common.swob import Request