Use six to fix imports on Python 3

Get configparser, queue, http_client modules from six.moves.

Patch generated by the six_moves operation of the sixer tool:
https://pypi.python.org/pypi/sixer

Change-Id: I666241ab50101b8cc6f992dd80134ce27327bd7d
This commit is contained in:
Victor Stinner 2015-05-25 18:26:38 +02:00
parent 8a2f2edf1c
commit e24d7c36fa
15 changed files with 46 additions and 33 deletions

View File

@ -17,7 +17,8 @@ import os
import urllib import urllib
import time import time
from urllib import unquote from urllib import unquote
from ConfigParser import ConfigParser, NoSectionError, NoOptionError
from six.moves.configparser import ConfigParser, NoSectionError, NoOptionError
from swift.common import utils, exceptions from swift.common import utils, exceptions
from swift.common.swob import HTTPBadRequest, HTTPLengthRequired, \ from swift.common.swob import HTTPBadRequest, HTTPLengthRequired, \

View File

@ -13,13 +13,14 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import ConfigParser
import errno import errno
import hashlib import hashlib
import hmac import hmac
import os import os
import time import time
from six.moves import configparser
from swift import gettext_ as _ from swift import gettext_ as _
from swift.common.utils import get_valid_utf8_str from swift.common.utils import get_valid_utf8_str
@ -61,9 +62,9 @@ class ContainerSyncRealms(object):
if mtime != self.conf_path_mtime: if mtime != self.conf_path_mtime:
self.conf_path_mtime = mtime self.conf_path_mtime = mtime
try: try:
conf = ConfigParser.SafeConfigParser() conf = configparser.SafeConfigParser()
conf.read(self.conf_path) conf.read(self.conf_path)
except ConfigParser.ParsingError as err: except configparser.ParsingError as err:
self.logger.error( self.logger.error(
_('Could not load %r: %s'), self.conf_path, err) _('Could not load %r: %s'), self.conf_path, err)
else: else:
@ -72,11 +73,11 @@ class ContainerSyncRealms(object):
'DEFAULT', 'mtime_check_interval') 'DEFAULT', 'mtime_check_interval')
self.next_mtime_check = \ self.next_mtime_check = \
now + self.mtime_check_interval now + self.mtime_check_interval
except ConfigParser.NoOptionError: except configparser.NoOptionError:
self.mtime_check_interval = 300 self.mtime_check_interval = 300
self.next_mtime_check = \ self.next_mtime_check = \
now + self.mtime_check_interval now + self.mtime_check_interval
except (ConfigParser.ParsingError, ValueError) as err: except (configparser.ParsingError, ValueError) as err:
self.logger.error( self.logger.error(
_('Error in %r with mtime_check_interval: %s'), _('Error in %r with mtime_check_interval: %s'),
self.conf_path, err) self.conf_path, err)

View File

@ -20,10 +20,10 @@ through the proxy.
import os import os
import socket import socket
from httplib import HTTPException
from time import time from time import time
from eventlet import sleep, Timeout from eventlet import sleep, Timeout
from six.moves.http_client import HTTPException
from swift.common.bufferedhttp import http_connect from swift.common.bufferedhttp import http_connect
from swift.common.exceptions import ClientException from swift.common.exceptions import ClientException

View File

@ -14,7 +14,9 @@
# limitations under the License. # limitations under the License.
import os import os
from ConfigParser import ConfigParser, NoSectionError, NoOptionError
from six.moves.configparser import ConfigParser, NoSectionError, NoOptionError
from hashlib import md5 from hashlib import md5
from swift.common import constraints from swift.common import constraints
from swift.common.exceptions import ListingIterError, SegmentError from swift.common.exceptions import ListingIterError, SegmentError

View File

@ -14,7 +14,8 @@
# limitations under the License. # limitations under the License.
import os import os
from ConfigParser import ConfigParser, NoSectionError, NoOptionError
from six.moves.configparser import ConfigParser, NoSectionError, NoOptionError
from swift.common.memcached import (MemcacheRing, CONN_TIMEOUT, POOL_TIMEOUT, from swift.common.memcached import (MemcacheRing, CONN_TIMEOUT, POOL_TIMEOUT,
IO_TIMEOUT, TRY_COUNT) IO_TIMEOUT, TRY_COUNT)

View File

@ -11,12 +11,14 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from ConfigParser import ConfigParser
import os import os
import string import string
import textwrap import textwrap
import six import six
from six.moves.configparser import ConfigParser
from swift.common.utils import ( from swift.common.utils import (
config_true_value, SWIFT_CONF_FILE, whataremyips) config_true_value, SWIFT_CONF_FILE, whataremyips)
from swift.common.ring import Ring, RingData from swift.common.ring import Ring, RingData

View File

@ -38,10 +38,8 @@ from urllib import quote as _quote
from contextlib import contextmanager, closing from contextlib import contextmanager, closing
import ctypes import ctypes
import ctypes.util import ctypes.util
from ConfigParser import ConfigParser, NoSectionError, NoOptionError, \
RawConfigParser
from optparse import OptionParser from optparse import OptionParser
from Queue import Queue, Empty
from tempfile import mkstemp, NamedTemporaryFile from tempfile import mkstemp, NamedTemporaryFile
try: try:
import simplejson as json import simplejson as json
@ -64,6 +62,9 @@ import netifaces
import codecs import codecs
utf8_decoder = codecs.getdecoder('utf-8') utf8_decoder = codecs.getdecoder('utf-8')
utf8_encoder = codecs.getencoder('utf-8') utf8_encoder = codecs.getencoder('utf-8')
from six.moves.configparser import ConfigParser, NoSectionError, \
NoOptionError, RawConfigParser
from six.moves.queue import Queue, Empty
from six.moves import range from six.moves import range
from swift import gettext_ as _ from swift import gettext_ as _

View File

@ -13,7 +13,6 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import httplib
import mock import mock
import os import os
import sys import sys
@ -24,15 +23,19 @@ import eventlet
import eventlet.debug import eventlet.debug
import functools import functools
import random import random
from ConfigParser import ConfigParser, NoSectionError
from time import time, sleep from time import time, sleep
from httplib import HTTPException
from urlparse import urlparse from urlparse import urlparse
from nose import SkipTest from nose import SkipTest
from contextlib import closing from contextlib import closing
from gzip import GzipFile from gzip import GzipFile
from shutil import rmtree from shutil import rmtree
from tempfile import mkdtemp from tempfile import mkdtemp
from six.moves.configparser import ConfigParser, NoSectionError
from six.moves import http_client
from six.moves.http_client import HTTPException
from swift.common.middleware.memcache import MemcacheMiddleware from swift.common.middleware.memcache import MemcacheMiddleware
from swift.common.storage_policy import parse_storage_policies, PolicyError from swift.common.storage_policy import parse_storage_policies, PolicyError
@ -53,7 +56,7 @@ from swift.container import server as container_server
from swift.obj import server as object_server, mem_server as mem_object_server from swift.obj import server as object_server, mem_server as mem_object_server
import swift.proxy.controllers.obj import swift.proxy.controllers.obj
httplib._MAXHEADERS = constraints.MAX_HEADER_COUNT http_client._MAXHEADERS = constraints.MAX_HEADER_COUNT
DEBUG = True DEBUG = True
# In order to get the proper blocking behavior of sockets without using # In order to get the proper blocking behavior of sockets without using

View File

@ -14,7 +14,6 @@
# limitations under the License. # limitations under the License.
import hashlib import hashlib
import httplib
import os import os
import random import random
import socket import socket
@ -22,11 +21,11 @@ import time
import urllib import urllib
import simplejson as json import simplejson as json
from nose import SkipTest from nose import SkipTest
from xml.dom import minidom from xml.dom import minidom
import six import six
from six.moves import http_client
from swiftclient import get_auth from swiftclient import get_auth
from swift.common import constraints from swift.common import constraints
@ -34,7 +33,7 @@ from swift.common.utils import config_true_value
from test import safe_repr from test import safe_repr
httplib._MAXHEADERS = constraints.MAX_HEADER_COUNT http_client._MAXHEADERS = constraints.MAX_HEADER_COUNT
class AuthenticationFailed(Exception): class AuthenticationFailed(Exception):
@ -166,10 +165,10 @@ class Connection(object):
x = storage_url.split('/') x = storage_url.split('/')
if x[0] == 'http:': if x[0] == 'http:':
self.conn_class = httplib.HTTPConnection self.conn_class = http_client.HTTPConnection
self.storage_port = 80 self.storage_port = 80
elif x[0] == 'https:': elif x[0] == 'https:':
self.conn_class = httplib.HTTPSConnection self.conn_class = http_client.HTTPSConnection
self.storage_port = 443 self.storage_port = 443
else: else:
raise ValueError('unexpected protocol %s' % (x[0])) raise ValueError('unexpected protocol %s' % (x[0]))
@ -283,7 +282,7 @@ class Connection(object):
try: try:
self.response = try_request() self.response = try_request()
except httplib.HTTPException as e: except http_client.HTTPException as e:
fail_messages.append(safe_repr(e)) fail_messages.append(safe_repr(e))
continue continue

View File

@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from httplib import HTTPConnection
import os import os
from subprocess import Popen, PIPE from subprocess import Popen, PIPE
import sys import sys
@ -22,8 +22,9 @@ from collections import defaultdict
import unittest import unittest
from nose import SkipTest from nose import SkipTest
from swiftclient import get_auth, head_account from six.moves.http_client import HTTPConnection
from swiftclient import get_auth, head_account
from swift.obj.diskfile import get_data_dir from swift.obj.diskfile import get_data_dir
from swift.common.ring import Ring from swift.common.ring import Ring
from swift.common.utils import readconf, renamer from swift.common.utils import readconf, renamer

View File

@ -14,10 +14,10 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import httplib
import re import re
import unittest import unittest
from six.moves import http_client
from swiftclient import get_auth from swiftclient import get_auth
from test.probe.common import ReplProbeTest from test.probe.common import ReplProbeTest
from urlparse import urlparse from urlparse import urlparse
@ -49,7 +49,7 @@ class TestAccountGetFakeResponsesMatch(ReplProbeTest):
host, port = netloc.split(':') host, port = netloc.split(':')
port = int(port) port = int(port)
conn = httplib.HTTPConnection(host, port) conn = http_client.HTTPConnection(host, port)
conn.request(method, self._account_path(account), headers=headers) conn.request(method, self._account_path(account), headers=headers)
resp = conn.getresponse() resp = conn.getresponse()
if resp.status // 100 != 2: if resp.status // 100 != 2:

View File

@ -37,7 +37,8 @@ from swift.common import swob, utils
from swift.common.ring import Ring, RingData from swift.common.ring import Ring, RingData
from hashlib import md5 from hashlib import md5
import logging.handlers import logging.handlers
from httplib import HTTPException
from six.moves.http_client import HTTPException
from swift.common import storage_policy from swift.common import storage_policy
from swift.common.storage_policy import StoragePolicy, ECStoragePolicy from swift.common.storage_policy import StoragePolicy, ECStoragePolicy
import functools import functools

View File

@ -16,9 +16,9 @@
import os import os
from textwrap import dedent from textwrap import dedent
import unittest import unittest
from ConfigParser import NoSectionError, NoOptionError
import mock import mock
from six.moves.configparser import NoSectionError, NoOptionError
from swift.common.middleware import memcache from swift.common.middleware import memcache
from swift.common.memcached import MemcacheRing from swift.common.memcached import MemcacheRing

View File

@ -14,10 +14,11 @@
""" Tests for swift.common.storage_policies """ """ Tests for swift.common.storage_policies """
import six import six
import unittest import unittest
from ConfigParser import ConfigParser
import os import os
import mock import mock
from functools import partial from functools import partial
from six.moves.configparser import ConfigParser
from tempfile import NamedTemporaryFile from tempfile import NamedTemporaryFile
from test.unit import patch_policies, FakeRing, temptree from test.unit import patch_policies, FakeRing, temptree
from swift.common.storage_policy import ( from swift.common.storage_policy import (

View File

@ -28,14 +28,15 @@ import os
import mock import mock
import random import random
import re import re
from six import StringIO
from six.moves import range
import socket import socket
import stat import stat
import sys import sys
import json import json
import math import math
from six import StringIO
from six.moves.queue import Queue, Empty
from six.moves import range
from textwrap import dedent from textwrap import dedent
import tempfile import tempfile
@ -47,7 +48,6 @@ import fcntl
import shutil import shutil
from contextlib import nested from contextlib import nested
from Queue import Queue, Empty
from getpass import getuser from getpass import getuser
from shutil import rmtree from shutil import rmtree
from functools import partial from functools import partial