Replace xrange() with six.moves.range()

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

Manual changes:

* Fix indentation for pep8 checks
* Fix TestGreenthreadSafeIterator.test_access_is_serialized of
  test.unit.common.test_utils:
  replace range(1, 11) with list(range(1, 11))
* Fix UnsafeXrange docstring, revert change

Change-Id: Icb7e26135c5e57b5302b8bfe066b33cafe69fe4d
This commit is contained in:
Victor Stinner 2015-05-25 18:28:02 +02:00 committed by Christian Schwede
parent 0009a43eb4
commit e5c962a28c
35 changed files with 170 additions and 141 deletions

View File

@ -478,7 +478,7 @@ class AccountBroker(DatabaseBroker):
row = curs_row.fetchone() row = curs_row.fetchone()
if row: if row:
row = list(row) row = list(row)
for i in xrange(5): for i in range(5):
if record[i] is None and row[i] is not None: if record[i] is None and row[i] is not None:
record[i] = row[i] record[i] = row[i]
if row[1] > record[1]: # Keep newest put_timestamp if row[1] > record[1]: # Keep newest put_timestamp

View File

@ -16,6 +16,7 @@
from eventlet import sleep, Timeout from eventlet import sleep, Timeout
from eventlet.green import httplib, socket, urllib2 from eventlet.green import httplib, socket, urllib2
import json import json
from six.moves import range
import struct import struct
from sys import exc_info from sys import exc_info
import zlib import zlib
@ -171,7 +172,7 @@ class InternalClient(object):
headers = dict(headers) headers = dict(headers)
headers['user-agent'] = self.user_agent headers['user-agent'] = self.user_agent
resp = exc_type = exc_value = exc_traceback = None resp = exc_type = exc_value = exc_traceback = None
for attempt in xrange(self.request_tries): for attempt in range(self.request_tries):
req = Request.blank( req = Request.blank(
path, environ={'REQUEST_METHOD': method}, headers=headers) path, environ={'REQUEST_METHOD': method}, headers=headers)
if body_file is not None: if body_file is not None:

View File

@ -54,6 +54,7 @@ from hashlib import md5
from eventlet.green import socket from eventlet.green import socket
from eventlet.pools import Pool from eventlet.pools import Pool
from eventlet import Timeout from eventlet import Timeout
from six.moves import range
from swift.common.utils import json from swift.common.utils import json
@ -140,7 +141,7 @@ class MemcacheRing(object):
self._errors = dict(((serv, []) for serv in servers)) self._errors = dict(((serv, []) for serv in servers))
self._error_limited = dict(((serv, 0) for serv in servers)) self._error_limited = dict(((serv, 0) for serv in servers))
for server in sorted(servers): for server in sorted(servers):
for i in xrange(NODE_WEIGHT): for i in range(NODE_WEIGHT):
self._ring[md5hash('%s-%s' % (server, i))] = server self._ring[md5hash('%s-%s' % (server, i))] = server
self._tries = tries if tries <= len(servers) else len(servers) self._tries = tries if tries <= len(servers) else len(servers)
self._sorted = sorted(self._ring) self._sorted = sorted(self._ring)

View File

@ -27,6 +27,8 @@ maximum lookup depth. If a match is found, the environment's Host header is
rewritten and the request is passed further down the WSGI chain. rewritten and the request is passed further down the WSGI chain.
""" """
from six.moves import range
import socket import socket
from swift import gettext_ as _ from swift import gettext_ as _
@ -122,7 +124,7 @@ class CNAMELookupMiddleware(object):
if self.memcache is None: if self.memcache is None:
self.memcache = cache_from_env(env) self.memcache = cache_from_env(env)
error = True error = True
for tries in xrange(self.lookup_depth): for tries in range(self.lookup_depth):
found_domain = None found_domain = None
if self.memcache: if self.memcache:
memcache_key = ''.join(['cname-', a_domain]) memcache_key = ''.join(['cname-', a_domain])

View File

@ -146,6 +146,8 @@ the manifest and the segments it's referring to) in the container and account
metadata which can be used for stats purposes. metadata which can be used for stats purposes.
""" """
from six.moves import range
from cStringIO import StringIO from cStringIO import StringIO
from datetime import datetime from datetime import datetime
import mimetypes import mimetypes
@ -205,7 +207,7 @@ class SloPutContext(WSGIContext):
def handle_slo_put(self, req, start_response): def handle_slo_put(self, req, start_response):
app_resp = self._app_call(req.environ) app_resp = self._app_call(req.environ)
for i in xrange(len(self._response_headers)): for i in range(len(self._response_headers)):
if self._response_headers[i][0].lower() == 'etag': if self._response_headers[i][0].lower() == 'etag':
self._response_headers[i] = ('Etag', self.slo_etag) self._response_headers[i] = ('Etag', self.slo_etag)
break break

View File

@ -25,6 +25,7 @@ from copy import deepcopy
from array import array from array import array
from collections import defaultdict from collections import defaultdict
from six.moves import range
from time import time from time import time
from swift.common import exceptions from swift.common import exceptions
@ -534,7 +535,7 @@ class RingBuilder(object):
if stats: if stats:
# dev_usage[dev_id] will equal the number of partitions assigned to # dev_usage[dev_id] will equal the number of partitions assigned to
# that device. # that device.
dev_usage = array('I', (0 for _junk in xrange(dev_len))) dev_usage = array('I', (0 for _junk in range(dev_len)))
for part2dev in self._replica2part2dev: for part2dev in self._replica2part2dev:
for dev_id in part2dev: for dev_id in part2dev:
dev_usage[dev_id] += 1 dev_usage[dev_id] += 1
@ -607,7 +608,7 @@ class RingBuilder(object):
255 hours ago. This can be used to force a full rebalance on the next 255 hours ago. This can be used to force a full rebalance on the next
call to rebalance. call to rebalance.
""" """
for part in xrange(self.parts): for part in range(self.parts):
self._last_part_moves[part] = 0xff self._last_part_moves[part] = 0xff
def get_part_devices(self, part): def get_part_devices(self, part):
@ -713,12 +714,12 @@ class RingBuilder(object):
if len(part2dev) < desired_length: if len(part2dev) < desired_length:
# Not long enough: needs to be extended and the # Not long enough: needs to be extended and the
# newly-added pieces assigned to devices. # newly-added pieces assigned to devices.
for part in xrange(len(part2dev), desired_length): for part in range(len(part2dev), desired_length):
to_assign[part].append(replica) to_assign[part].append(replica)
part2dev.append(0) part2dev.append(0)
elif len(part2dev) > desired_length: elif len(part2dev) > desired_length:
# Too long: truncate this mapping. # Too long: truncate this mapping.
for part in xrange(desired_length, len(part2dev)): for part in range(desired_length, len(part2dev)):
dev_losing_part = self.devs[part2dev[part]] dev_losing_part = self.devs[part2dev[part]]
dev_losing_part['parts'] -= 1 dev_losing_part['parts'] -= 1
removed_replicas += 1 removed_replicas += 1
@ -726,10 +727,10 @@ class RingBuilder(object):
else: else:
# Mapping not present at all: make one up and assign # Mapping not present at all: make one up and assign
# all of it. # all of it.
for part in xrange(desired_length): for part in range(desired_length):
to_assign[part].append(replica) to_assign[part].append(replica)
self._replica2part2dev.append( self._replica2part2dev.append(
array('H', (0 for _junk in xrange(desired_length)))) array('H', (0 for _junk in range(desired_length))))
return (to_assign.items(), removed_replicas) return (to_assign.items(), removed_replicas)
@ -738,7 +739,7 @@ class RingBuilder(object):
Initial partition assignment is the same as rebalancing an Initial partition assignment is the same as rebalancing an
existing ring, but with some initial setup beforehand. existing ring, but with some initial setup beforehand.
""" """
self._last_part_moves = array('B', (0 for _junk in xrange(self.parts))) self._last_part_moves = array('B', (0 for _junk in range(self.parts)))
self._last_part_moves_epoch = int(time()) self._last_part_moves_epoch = int(time())
self._set_parts_wanted() self._set_parts_wanted()
@ -751,7 +752,7 @@ class RingBuilder(object):
more recently than min_part_hours. more recently than min_part_hours.
""" """
elapsed_hours = int(time() - self._last_part_moves_epoch) / 3600 elapsed_hours = int(time() - self._last_part_moves_epoch) / 3600
for part in xrange(self.parts): for part in range(self.parts):
# The "min(self._last_part_moves[part] + elapsed_hours, 0xff)" # The "min(self._last_part_moves[part] + elapsed_hours, 0xff)"
# which was here showed up in profiling, so it got inlined. # which was here showed up in profiling, so it got inlined.
last_plus_elapsed = self._last_part_moves[part] + elapsed_hours last_plus_elapsed = self._last_part_moves[part] + elapsed_hours
@ -830,7 +831,7 @@ class RingBuilder(object):
max_allowed_replicas = self._build_max_replicas_by_tier() max_allowed_replicas = self._build_max_replicas_by_tier()
wanted_parts_for_tier = self._get_available_parts() wanted_parts_for_tier = self._get_available_parts()
moved_parts = 0 moved_parts = 0
for part in xrange(self.parts): for part in range(self.parts):
# Only move one replica at a time if possible. # Only move one replica at a time if possible.
if part in removed_dev_parts: if part in removed_dev_parts:
continue continue
@ -922,8 +923,8 @@ class RingBuilder(object):
# pattern (but scaled down) on sequential runs. # pattern (but scaled down) on sequential runs.
this_start = int(float(start) * len(part2dev) / self.parts) this_start = int(float(start) * len(part2dev) / self.parts)
for part in itertools.chain(xrange(this_start, len(part2dev)), for part in itertools.chain(range(this_start, len(part2dev)),
xrange(0, this_start)): range(0, this_start)):
if self._last_part_moves[part] < self.min_part_hours: if self._last_part_moves[part] < self.min_part_hours:
continue continue
if part in removed_dev_parts or part in spread_out_parts: if part in removed_dev_parts or part in spread_out_parts:
@ -1270,7 +1271,7 @@ class RingBuilder(object):
Generator yielding every (partition, replica) pair in the ring. Generator yielding every (partition, replica) pair in the ring.
""" """
for replica, part2dev in enumerate(self._replica2part2dev): for replica, part2dev in enumerate(self._replica2part2dev):
for part in xrange(len(part2dev)): for part in range(len(part2dev)):
yield (part, replica) yield (part, replica)
@classmethod @classmethod

View File

@ -27,6 +27,8 @@ from hashlib import md5
from itertools import chain from itertools import chain
from tempfile import NamedTemporaryFile from tempfile import NamedTemporaryFile
from six.moves import range
from swift.common.utils import hash_path, validate_configuration, json from swift.common.utils import hash_path, validate_configuration, json
from swift.common.ring.utils import tiers_for_dev from swift.common.ring.utils import tiers_for_dev
@ -68,7 +70,7 @@ class RingData(object):
return ring_dict return ring_dict
partition_count = 1 << (32 - ring_dict['part_shift']) partition_count = 1 << (32 - ring_dict['part_shift'])
for x in xrange(ring_dict['replica_count']): for x in range(ring_dict['replica_count']):
ring_dict['replica2part2dev_id'].append( ring_dict['replica2part2dev_id'].append(
array.array('H', gz_file.read(2 * partition_count))) array.array('H', gz_file.read(2 * partition_count)))
return ring_dict return ring_dict
@ -361,8 +363,8 @@ class Ring(object):
# Multiple loops for execution speed; the checks and bookkeeping get # Multiple loops for execution speed; the checks and bookkeeping get
# simpler as you go along # simpler as you go along
hit_all_regions = len(same_regions) == self._num_regions hit_all_regions = len(same_regions) == self._num_regions
for handoff_part in chain(xrange(start, parts, inc), for handoff_part in chain(range(start, parts, inc),
xrange(inc - ((parts - start) % inc), range(inc - ((parts - start) % inc),
start, inc)): start, inc)):
if hit_all_regions: if hit_all_regions:
# At this point, there are no regions left untouched, so we # At this point, there are no regions left untouched, so we
@ -386,8 +388,8 @@ class Ring(object):
break break
hit_all_zones = len(same_zones) == self._num_zones hit_all_zones = len(same_zones) == self._num_zones
for handoff_part in chain(xrange(start, parts, inc), for handoff_part in chain(range(start, parts, inc),
xrange(inc - ((parts - start) % inc), range(inc - ((parts - start) % inc),
start, inc)): start, inc)):
if hit_all_zones: if hit_all_zones:
# Much like we stopped looking for fresh regions before, we # Much like we stopped looking for fresh regions before, we
@ -409,8 +411,8 @@ class Ring(object):
break break
hit_all_ips = len(same_ips) == self._num_ips hit_all_ips = len(same_ips) == self._num_ips
for handoff_part in chain(xrange(start, parts, inc), for handoff_part in chain(range(start, parts, inc),
xrange(inc - ((parts - start) % inc), range(inc - ((parts - start) % inc),
start, inc)): start, inc)):
if hit_all_ips: if hit_all_ips:
# We've exhausted the pool of unused backends, so stop # We've exhausted the pool of unused backends, so stop
@ -430,8 +432,8 @@ class Ring(object):
break break
hit_all_devs = len(used) == self._num_devs hit_all_devs = len(used) == self._num_devs
for handoff_part in chain(xrange(start, parts, inc), for handoff_part in chain(range(start, parts, inc),
xrange(inc - ((parts - start) % inc), range(inc - ((parts - start) % inc),
start, inc)): start, inc)):
if hit_all_devs: if hit_all_devs:
# We've used every device we have, so let's stop looking for # We've used every device we have, so let's stop looking for

View File

@ -64,6 +64,7 @@ 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 import range
from swift import gettext_ as _ from swift import gettext_ as _
import swift.common.exceptions import swift.common.exceptions
@ -2953,7 +2954,7 @@ class ThreadPool(object):
_raw_rpipe, self.wpipe = os.pipe() _raw_rpipe, self.wpipe = os.pipe()
self.rpipe = greenio.GreenPipe(_raw_rpipe, 'rb', bufsize=0) self.rpipe = greenio.GreenPipe(_raw_rpipe, 'rb', bufsize=0)
for _junk in xrange(nthreads): for _junk in range(nthreads):
thr = stdlib_threading.Thread( thr = stdlib_threading.Thread(
target=self._worker, target=self._worker,
args=(self._run_queue, self._result_queue)) args=(self._run_queue, self._result_queue))

View File

@ -21,6 +21,7 @@ from uuid import uuid4
import time import time
import cPickle as pickle import cPickle as pickle
from six.moves import range
import sqlite3 import sqlite3
from swift.common.utils import Timestamp from swift.common.utils import Timestamp
@ -698,7 +699,7 @@ class ContainerBroker(DatabaseBroker):
# Get created_at times for objects in item_list that already exist. # Get created_at times for objects in item_list that already exist.
# We must chunk it up to avoid sqlite's limit of 999 args. # We must chunk it up to avoid sqlite's limit of 999 args.
created_at = {} created_at = {}
for offset in xrange(0, len(item_list), SQLITE_ARG_LIMIT): for offset in range(0, len(item_list), SQLITE_ARG_LIMIT):
chunk = [rec['name'] for rec in chunk = [rec['name'] for rec in
item_list[offset:offset + SQLITE_ARG_LIMIT]] item_list[offset:offset + SQLITE_ARG_LIMIT]]
created_at.update( created_at.update(

View File

@ -68,7 +68,7 @@ class ResponseError(Exception):
def listing_empty(method): def listing_empty(method):
for i in xrange(6): for i in range(6):
if len(method()) == 0: if len(method()) == 0:
return True return True

View File

@ -21,6 +21,7 @@ from uuid import uuid4
from nose import SkipTest from nose import SkipTest
from string import letters from string import letters
from six.moves import range
from swift.common.middleware.acl import format_acl from swift.common.middleware.acl import format_acl
from test.functional import check_response, retry, requires_acls, \ from test.functional import check_response, retry, requires_acls, \
@ -790,13 +791,13 @@ class TestAccount(unittest.TestCase):
resp = retry(post, headers) resp = retry(post, headers)
headers = {} headers = {}
for x in xrange(self.max_meta_count): for x in range(self.max_meta_count):
headers['X-Account-Meta-%d' % x] = 'v' headers['X-Account-Meta-%d' % x] = 'v'
resp = retry(post, headers) resp = retry(post, headers)
resp.read() resp.read()
self.assertEqual(resp.status, 204) self.assertEqual(resp.status, 204)
headers = {} headers = {}
for x in xrange(self.max_meta_count + 1): for x in range(self.max_meta_count + 1):
headers['X-Account-Meta-%d' % x] = 'v' headers['X-Account-Meta-%d' % x] = 'v'
resp = retry(post, headers) resp = retry(post, headers)
resp.read() resp.read()

View File

@ -24,6 +24,8 @@ from test.functional import check_response, retry, requires_acls, \
load_constraint, requires_policies load_constraint, requires_policies
import test.functional as tf import test.functional as tf
from six.moves import range
class TestContainer(unittest.TestCase): class TestContainer(unittest.TestCase):
@ -319,7 +321,7 @@ class TestContainer(unittest.TestCase):
name = uuid4().hex name = uuid4().hex
headers = {} headers = {}
for x in xrange(self.max_meta_count): for x in range(self.max_meta_count):
headers['X-Container-Meta-%d' % x] = 'v' headers['X-Container-Meta-%d' % x] = 'v'
resp = retry(put, name, headers) resp = retry(put, name, headers)
resp.read() resp.read()
@ -329,7 +331,7 @@ class TestContainer(unittest.TestCase):
self.assertEqual(resp.status, 204) self.assertEqual(resp.status, 204)
name = uuid4().hex name = uuid4().hex
headers = {} headers = {}
for x in xrange(self.max_meta_count + 1): for x in range(self.max_meta_count + 1):
headers['X-Container-Meta-%d' % x] = 'v' headers['X-Container-Meta-%d' % x] = 'v'
resp = retry(put, name, headers) resp = retry(put, name, headers)
resp.read() resp.read()
@ -412,13 +414,13 @@ class TestContainer(unittest.TestCase):
return check_response(conn) return check_response(conn)
headers = {} headers = {}
for x in xrange(self.max_meta_count): for x in range(self.max_meta_count):
headers['X-Container-Meta-%d' % x] = 'v' headers['X-Container-Meta-%d' % x] = 'v'
resp = retry(post, headers) resp = retry(post, headers)
resp.read() resp.read()
self.assertEqual(resp.status, 204) self.assertEqual(resp.status, 204)
headers = {} headers = {}
for x in xrange(self.max_meta_count + 1): for x in range(self.max_meta_count + 1):
headers['X-Container-Meta-%d' % x] = 'v' headers['X-Container-Meta-%d' % x] = 'v'
resp = retry(post, headers) resp = retry(post, headers)
resp.read() resp.read()

View File

@ -20,6 +20,7 @@ import unittest
from nose import SkipTest from nose import SkipTest
from uuid import uuid4 from uuid import uuid4
from six.moves import range
from test.functional import check_response, retry, requires_acls, \ from test.functional import check_response, retry, requires_acls, \
requires_policies requires_policies
@ -746,7 +747,7 @@ class TestObject(unittest.TestCase):
parsed.path, self.container, str(objnum)), segments1[objnum], parsed.path, self.container, str(objnum)), segments1[objnum],
{'X-Auth-Token': token}) {'X-Auth-Token': token})
return check_response(conn) return check_response(conn)
for objnum in xrange(len(segments1)): for objnum in range(len(segments1)):
resp = retry(put, objnum) resp = retry(put, objnum)
resp.read() resp.read()
self.assertEqual(resp.status, 201) self.assertEqual(resp.status, 201)
@ -809,7 +810,7 @@ class TestObject(unittest.TestCase):
parsed.path, self.container, str(objnum)), segments2[objnum], parsed.path, self.container, str(objnum)), segments2[objnum],
{'X-Auth-Token': token}) {'X-Auth-Token': token})
return check_response(conn) return check_response(conn)
for objnum in xrange(len(segments2)): for objnum in range(len(segments2)):
resp = retry(put, objnum) resp = retry(put, objnum)
resp.read() resp.read()
self.assertEqual(resp.status, 201) self.assertEqual(resp.status, 201)
@ -891,7 +892,7 @@ class TestObject(unittest.TestCase):
parsed.path, acontainer, str(objnum)), segments3[objnum], parsed.path, acontainer, str(objnum)), segments3[objnum],
{'X-Auth-Token': token}) {'X-Auth-Token': token})
return check_response(conn) return check_response(conn)
for objnum in xrange(len(segments3)): for objnum in range(len(segments3)):
resp = retry(put, objnum) resp = retry(put, objnum)
resp.read() resp.read()
self.assertEqual(resp.status, 201) self.assertEqual(resp.status, 201)
@ -966,7 +967,7 @@ class TestObject(unittest.TestCase):
parsed.path, acontainer, str(objnum)), '', parsed.path, acontainer, str(objnum)), '',
{'X-Auth-Token': token}) {'X-Auth-Token': token})
return check_response(conn) return check_response(conn)
for objnum in xrange(len(segments3)): for objnum in range(len(segments3)):
resp = retry(delete, objnum) resp = retry(delete, objnum)
resp.read() resp.read()
self.assertEqual(resp.status, 204) self.assertEqual(resp.status, 204)
@ -977,7 +978,7 @@ class TestObject(unittest.TestCase):
parsed.path, self.container, str(objnum)), '', parsed.path, self.container, str(objnum)), '',
{'X-Auth-Token': token}) {'X-Auth-Token': token})
return check_response(conn) return check_response(conn)
for objnum in xrange(len(segments2)): for objnum in range(len(segments2)):
resp = retry(delete, objnum) resp = retry(delete, objnum)
resp.read() resp.read()
self.assertEqual(resp.status, 204) self.assertEqual(resp.status, 204)
@ -988,7 +989,7 @@ class TestObject(unittest.TestCase):
parsed.path, self.container, str(objnum)), '', parsed.path, self.container, str(objnum)), '',
{'X-Auth-Token': token}) {'X-Auth-Token': token})
return check_response(conn) return check_response(conn)
for objnum in xrange(len(segments1)): for objnum in range(len(segments1)):
resp = retry(delete, objnum) resp = retry(delete, objnum)
resp.read() resp.read()
self.assertEqual(resp.status, 204) self.assertEqual(resp.status, 204)

View File

@ -55,7 +55,7 @@ class Utils(object):
u'\u3705\u1803\u0902\uF112\uD210\uB30E\u940C\u850B'\ u'\u3705\u1803\u0902\uF112\uD210\uB30E\u940C\u850B'\
u'\u5608\u3706\u1804\u0903\u03A9\u2603' u'\u5608\u3706\u1804\u0903\u03A9\u2603'
return ''.join([random.choice(utf8_chars) return ''.join([random.choice(utf8_chars)
for x in xrange(length)]).encode('utf-8') for x in range(length)]).encode('utf-8')
create_name = create_ascii_name create_name = create_ascii_name
@ -393,14 +393,14 @@ class TestContainer(Base):
cont = self.env.account.container(Utils.create_name()) cont = self.env.account.container(Utils.create_name())
self.assert_(cont.create()) self.assert_(cont.create())
files = sorted([Utils.create_name() for x in xrange(10)]) files = sorted([Utils.create_name() for x in range(10)])
for f in files: for f in files:
file_item = cont.file(f) file_item = cont.file(f)
self.assert_(file_item.write_random()) self.assert_(file_item.write_random())
for i in xrange(len(files)): for i in range(len(files)):
f = files[i] f = files[i]
for j in xrange(1, len(files) - i): for j in range(1, len(files) - i):
self.assert_(cont.files(parms={'limit': j, 'marker': f}) == self.assert_(cont.files(parms={'limit': j, 'marker': f}) ==
files[i + 1: i + j + 1]) files[i + 1: i + j + 1])
self.assert_(cont.files(parms={'marker': f}) == files[i + 1:]) self.assert_(cont.files(parms={'marker': f}) == files[i + 1:])

View File

@ -36,7 +36,7 @@ def get_data_file_path(obj_dir):
files = [] files = []
# We might need to try a few times if a request hasn't yet settled. For # We might need to try a few times if a request hasn't yet settled. For
# instance, a PUT can return success when just 2 of 3 nodes has completed. # instance, a PUT can return success when just 2 of 3 nodes has completed.
for attempt in xrange(RETRIES + 1): for attempt in range(RETRIES + 1):
try: try:
files = sorted(listdir(obj_dir), reverse=True) files = sorted(listdir(obj_dir), reverse=True)
break break

View File

@ -19,6 +19,7 @@ import os
import copy import copy
import logging import logging
import errno import errno
from six.moves import range
import sys import sys
from contextlib import contextmanager, closing from contextlib import contextmanager, closing
from collections import defaultdict, Iterable from collections import defaultdict, Iterable
@ -227,7 +228,7 @@ class FakeRing(Ring):
def get_more_nodes(self, part): def get_more_nodes(self, part):
# replicas^2 is the true cap # replicas^2 is the true cap
for x in xrange(self.replicas, min(self.replicas + self.max_more_nodes, for x in range(self.replicas, min(self.replicas + self.max_more_nodes,
self.replicas * self.replicas)): self.replicas * self.replicas)):
yield {'ip': '10.0.0.%s' % x, yield {'ip': '10.0.0.%s' % x,
'replication_ip': '10.0.0.%s' % x, 'replication_ip': '10.0.0.%s' % x,

View File

@ -385,17 +385,17 @@ class TestAccountBroker(unittest.TestCase):
# Test AccountBroker.list_containers_iter # Test AccountBroker.list_containers_iter
broker = AccountBroker(':memory:', account='a') broker = AccountBroker(':memory:', account='a')
broker.initialize(Timestamp('1').internal) broker.initialize(Timestamp('1').internal)
for cont1 in xrange(4): for cont1 in range(4):
for cont2 in xrange(125): for cont2 in range(125):
broker.put_container('%d-%04d' % (cont1, cont2), broker.put_container('%d-%04d' % (cont1, cont2),
Timestamp(time()).internal, 0, 0, 0, Timestamp(time()).internal, 0, 0, 0,
POLICIES.default.idx) POLICIES.default.idx)
for cont in xrange(125): for cont in range(125):
broker.put_container('2-0051-%04d' % cont, broker.put_container('2-0051-%04d' % cont,
Timestamp(time()).internal, 0, 0, 0, Timestamp(time()).internal, 0, 0, 0,
POLICIES.default.idx) POLICIES.default.idx)
for cont in xrange(125): for cont in range(125):
broker.put_container('3-%04d-0049' % cont, broker.put_container('3-%04d-0049' % cont,
Timestamp(time()).internal, 0, 0, 0, Timestamp(time()).internal, 0, 0, 0,
POLICIES.default.idx) POLICIES.default.idx)

View File

@ -947,7 +947,7 @@ class TestAccountController(unittest.TestCase):
req = Request.blank('/sda1/p/a', environ={'REQUEST_METHOD': 'PUT', req = Request.blank('/sda1/p/a', environ={'REQUEST_METHOD': 'PUT',
'HTTP_X_TIMESTAMP': '0'}) 'HTTP_X_TIMESTAMP': '0'})
req.get_response(self.controller) req.get_response(self.controller)
for c in xrange(5): for c in range(5):
req = Request.blank( req = Request.blank(
'/sda1/p/a/c%d' % c, '/sda1/p/a/c%d' % c,
environ={'REQUEST_METHOD': 'PUT'}, environ={'REQUEST_METHOD': 'PUT'},
@ -972,7 +972,7 @@ class TestAccountController(unittest.TestCase):
req = Request.blank('/sda1/p/a', environ={'REQUEST_METHOD': 'PUT', req = Request.blank('/sda1/p/a', environ={'REQUEST_METHOD': 'PUT',
'HTTP_X_TIMESTAMP': '0'}) 'HTTP_X_TIMESTAMP': '0'})
req.get_response(self.controller) req.get_response(self.controller)
for c in xrange(5): for c in range(5):
req = Request.blank( req = Request.blank(
'/sda1/p/a/c%d' % c, '/sda1/p/a/c%d' % c,
environ={'REQUEST_METHOD': 'PUT'}, environ={'REQUEST_METHOD': 'PUT'},
@ -1002,7 +1002,7 @@ class TestAccountController(unittest.TestCase):
req = Request.blank('/sda1/p/a', environ={'REQUEST_METHOD': 'PUT', req = Request.blank('/sda1/p/a', environ={'REQUEST_METHOD': 'PUT',
'HTTP_X_TIMESTAMP': '0'}) 'HTTP_X_TIMESTAMP': '0'})
req.get_response(self.controller) req.get_response(self.controller)
for c in xrange(5): for c in range(5):
req = Request.blank( req = Request.blank(
'/sda1/p/a/c%d' % c, '/sda1/p/a/c%d' % c,
environ={'REQUEST_METHOD': 'PUT'}, environ={'REQUEST_METHOD': 'PUT'},

View File

@ -713,7 +713,7 @@ class TestDelete(unittest.TestCase):
with patch.object(self.bulk, 'max_deletes_per_request', 9): with patch.object(self.bulk, 'max_deletes_per_request', 9):
with patch.object(self.bulk, 'max_path_length', 1): with patch.object(self.bulk, 'max_path_length', 1):
req_body = '\n'.join([str(i) for i in xrange(10)]) req_body = '\n'.join([str(i) for i in range(10)])
req = Request.blank('/delete_works/AUTH_Acc', body=req_body) req = Request.blank('/delete_works/AUTH_Acc', body=req_body)
self.assertRaises( self.assertRaises(
HTTPException, self.bulk.get_objs_to_delete, req) HTTPException, self.bulk.get_objs_to_delete, req)

View File

@ -14,6 +14,8 @@
# 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 six.moves import range
import hashlib import hashlib
import time import time
import unittest import unittest
@ -1374,7 +1376,7 @@ class TestSloGetManifest(SloTestCase):
def test_recursion_limit(self): def test_recursion_limit(self):
# man1 points to obj1 and man2, man2 points to obj2 and man3... # man1 points to obj1 and man2, man2 points to obj2 and man3...
for i in xrange(20): for i in range(20):
self.app.register('GET', '/v1/AUTH_test/gettest/obj%d' % i, self.app.register('GET', '/v1/AUTH_test/gettest/obj%d' % i,
swob.HTTPOk, {'Content-Type': 'text/plain', swob.HTTPOk, {'Content-Type': 'text/plain',
'Etag': md5hex('body%02d' % i)}, 'Etag': md5hex('body%02d' % i)},
@ -1391,7 +1393,7 @@ class TestSloGetManifest(SloTestCase):
'Etag': 'man%d' % i}, 'Etag': 'man%d' % i},
manifest_json) manifest_json)
for i in xrange(19, 0, -1): for i in range(19, 0, -1):
manifest_data = [ manifest_data = [
{'name': '/gettest/obj%d' % i, {'name': '/gettest/obj%d' % i,
'hash': md5hex('body%02d' % i), 'hash': md5hex('body%02d' % i),
@ -1429,7 +1431,7 @@ class TestSloGetManifest(SloTestCase):
def test_sub_slo_recursion(self): def test_sub_slo_recursion(self):
# man1 points to man2 and obj1, man2 points to man3 and obj2... # man1 points to man2 and obj1, man2 points to man3 and obj2...
for i in xrange(11): for i in range(11):
self.app.register('GET', '/v1/AUTH_test/gettest/obj%d' % i, self.app.register('GET', '/v1/AUTH_test/gettest/obj%d' % i,
swob.HTTPOk, {'Content-Type': 'text/plain', swob.HTTPOk, {'Content-Type': 'text/plain',
'Content-Length': '6', 'Content-Length': '6',
@ -1452,7 +1454,7 @@ class TestSloGetManifest(SloTestCase):
'Etag': md5hex('body%2d' % i)}, 'Etag': md5hex('body%2d' % i)},
None) None)
for i in xrange(9, 0, -1): for i in range(9, 0, -1):
manifest_data = [ manifest_data = [
{'name': '/gettest/man%d' % (i + 1), {'name': '/gettest/man%d' % (i + 1),
'hash': 'man%d' % (i + 1), 'hash': 'man%d' % (i + 1),
@ -1486,7 +1488,7 @@ class TestSloGetManifest(SloTestCase):
def test_sub_slo_recursion_limit(self): def test_sub_slo_recursion_limit(self):
# man1 points to man2 and obj1, man2 points to man3 and obj2... # man1 points to man2 and obj1, man2 points to man3 and obj2...
for i in xrange(12): for i in range(12):
self.app.register('GET', '/v1/AUTH_test/gettest/obj%d' % i, self.app.register('GET', '/v1/AUTH_test/gettest/obj%d' % i,
swob.HTTPOk, swob.HTTPOk,
{'Content-Type': 'text/plain', {'Content-Type': 'text/plain',
@ -1509,7 +1511,7 @@ class TestSloGetManifest(SloTestCase):
'Etag': md5hex('body%2d' % i)}, 'Etag': md5hex('body%2d' % i)},
None) None)
for i in xrange(11, 0, -1): for i in range(11, 0, -1):
manifest_data = [ manifest_data = [
{'name': '/gettest/man%d' % (i + 1), {'name': '/gettest/man%d' % (i + 1),
'hash': 'man%d' % (i + 1), 'hash': 'man%d' % (i + 1),

View File

@ -26,6 +26,8 @@ from math import ceil
from tempfile import mkdtemp from tempfile import mkdtemp
from shutil import rmtree from shutil import rmtree
from six.moves import range
from swift.common import exceptions from swift.common import exceptions
from swift.common import ring from swift.common import ring
from swift.common.ring.builder import MAX_BALANCE from swift.common.ring.builder import MAX_BALANCE
@ -373,9 +375,9 @@ class TestRingBuilder(unittest.TestCase):
rb.rebalance() rb.rebalance()
rb.validate() rb.validate()
for part in xrange(rb.parts): for part in range(rb.parts):
counts = defaultdict(lambda: defaultdict(int)) counts = defaultdict(lambda: defaultdict(int))
for replica in xrange(rb.replicas): for replica in range(rb.replicas):
dev = rb.devs[rb._replica2part2dev[replica][part]] dev = rb.devs[rb._replica2part2dev[replica][part]]
counts['region'][dev['region']] += 1 counts['region'][dev['region']] += 1
counts['zone'][dev['zone']] += 1 counts['zone'][dev['zone']] += 1
@ -415,9 +417,9 @@ class TestRingBuilder(unittest.TestCase):
rb.rebalance() rb.rebalance()
rb.validate() rb.validate()
for part in xrange(rb.parts): for part in range(rb.parts):
counts = defaultdict(lambda: defaultdict(int)) counts = defaultdict(lambda: defaultdict(int))
for replica in xrange(rb.replicas): for replica in range(rb.replicas):
dev = rb.devs[rb._replica2part2dev[replica][part]] dev = rb.devs[rb._replica2part2dev[replica][part]]
counts['zone'][dev['zone']] += 1 counts['zone'][dev['zone']] += 1
counts['dev_id'][dev['id']] += 1 counts['dev_id'][dev['id']] += 1
@ -452,9 +454,9 @@ class TestRingBuilder(unittest.TestCase):
rb.rebalance() rb.rebalance()
rb.validate() rb.validate()
for part in xrange(rb.parts): for part in range(rb.parts):
counts = defaultdict(lambda: defaultdict(int)) counts = defaultdict(lambda: defaultdict(int))
for replica in xrange(rb.replicas): for replica in range(rb.replicas):
dev = rb.devs[rb._replica2part2dev[replica][part]] dev = rb.devs[rb._replica2part2dev[replica][part]]
counts['zone'][dev['zone']] += 1 counts['zone'][dev['zone']] += 1
counts['dev_id'][dev['id']] += 1 counts['dev_id'][dev['id']] += 1
@ -489,9 +491,9 @@ class TestRingBuilder(unittest.TestCase):
rb.rebalance() rb.rebalance()
rb.validate() rb.validate()
for part in xrange(rb.parts): for part in range(rb.parts):
counts = defaultdict(lambda: defaultdict(int)) counts = defaultdict(lambda: defaultdict(int))
for replica in xrange(rb.replicas): for replica in range(rb.replicas):
dev = rb.devs[rb._replica2part2dev[replica][part]] dev = rb.devs[rb._replica2part2dev[replica][part]]
counts['zone'][dev['zone']] += 1 counts['zone'][dev['zone']] += 1
counts['dev_id'][dev['id']] += 1 counts['dev_id'][dev['id']] += 1
@ -528,15 +530,15 @@ class TestRingBuilder(unittest.TestCase):
rb.add_dev({'id': 5, 'region': 0, 'zone': 2, 'weight': 1, rb.add_dev({'id': 5, 'region': 0, 'zone': 2, 'weight': 1,
'ip': '127.0.0.1', 'port': 10000, 'device': 'sdf'}) 'ip': '127.0.0.1', 'port': 10000, 'device': 'sdf'})
for _ in xrange(5): for _ in range(5):
rb.pretend_min_part_hours_passed() rb.pretend_min_part_hours_passed()
rb.rebalance() rb.rebalance()
rb.validate() rb.validate()
for part in xrange(rb.parts): for part in range(rb.parts):
counts = dict(zone=defaultdict(int), counts = dict(zone=defaultdict(int),
dev_id=defaultdict(int)) dev_id=defaultdict(int))
for replica in xrange(rb.replicas): for replica in range(rb.replicas):
dev = rb.devs[rb._replica2part2dev[replica][part]] dev = rb.devs[rb._replica2part2dev[replica][part]]
counts['zone'][dev['zone']] += 1 counts['zone'][dev['zone']] += 1
counts['dev_id'][dev['id']] += 1 counts['dev_id'][dev['id']] += 1
@ -561,9 +563,9 @@ class TestRingBuilder(unittest.TestCase):
rb.rebalance() rb.rebalance()
rb.validate() rb.validate()
for part in xrange(rb.parts): for part in range(rb.parts):
devs = set() devs = set()
for replica in xrange(rb.replicas): for replica in range(rb.replicas):
devs.add(rb._replica2part2dev[replica][part]) devs.add(rb._replica2part2dev[replica][part])
if len(devs) != 3: if len(devs) != 3:
@ -587,9 +589,9 @@ class TestRingBuilder(unittest.TestCase):
rb.rebalance() rb.rebalance()
rb.validate() rb.validate()
for part in xrange(rb.parts): for part in range(rb.parts):
devs = set() devs = set()
for replica in xrange(rb.replicas): for replica in range(rb.replicas):
devs.add(rb._replica2part2dev[replica][part]) devs.add(rb._replica2part2dev[replica][part])
if len(devs) != 2: if len(devs) != 2:
@ -616,9 +618,9 @@ class TestRingBuilder(unittest.TestCase):
rb.rebalance() rb.rebalance()
rb.validate() rb.validate()
for part in xrange(rb.parts): for part in range(rb.parts):
zones = set() zones = set()
for replica in xrange(rb.replicas): for replica in range(rb.replicas):
zones.add(rb.devs[rb._replica2part2dev[replica][part]]['zone']) zones.add(rb.devs[rb._replica2part2dev[replica][part]]['zone'])
if len(zones) != 3: if len(zones) != 3:

View File

@ -25,6 +25,8 @@ from tempfile import mkdtemp
from shutil import rmtree from shutil import rmtree
from time import sleep, time from time import sleep, time
from six.moves import range
from swift.common import ring, utils from swift.common import ring, utils
@ -74,7 +76,7 @@ class TestRingData(unittest.TestCase):
{'id': 1, 'zone': 1, 'ip': '10.1.1.1', 'port': 7000}], {'id': 1, 'zone': 1, 'ip': '10.1.1.1', 'port': 7000}],
30) 30)
ring_fname = os.path.join(self.testdir, 'foo.ring.gz') ring_fname = os.path.join(self.testdir, 'foo.ring.gz')
for p in xrange(pickle.HIGHEST_PROTOCOL): for p in range(pickle.HIGHEST_PROTOCOL):
with closing(GzipFile(ring_fname, 'wb')) as f: with closing(GzipFile(ring_fname, 'wb')) as f:
pickle.dump(rd, f, protocol=p) pickle.dump(rd, f, protocol=p)
meta_only = ring.RingData.load(ring_fname, metadata_only=True) meta_only = ring.RingData.load(ring_fname, metadata_only=True)
@ -490,9 +492,9 @@ class TestRing(TestRingBase):
19, 55] 19, 55]
rb = ring.RingBuilder(8, 3, 1) rb = ring.RingBuilder(8, 3, 1)
next_dev_id = 0 next_dev_id = 0
for zone in xrange(1, 10): for zone in range(1, 10):
for server in xrange(1, 5): for server in range(1, 5):
for device in xrange(1, 4): for device in range(1, 4):
rb.add_dev({'id': next_dev_id, rb.add_dev({'id': next_dev_id,
'ip': '1.2.%d.%d' % (zone, server), 'ip': '1.2.%d.%d' % (zone, server),
'port': 1234 + device, 'port': 1234 + device,
@ -518,7 +520,7 @@ class TestRing(TestRingBase):
# The first handoff nodes for each partition in the ring # The first handoff nodes for each partition in the ring
devs = [] devs = []
for part in xrange(r.partition_count): for part in range(r.partition_count):
devs.append(next(r.get_more_nodes(part))['id']) devs.append(next(r.get_more_nodes(part))['id'])
self.assertEquals(devs, exp_first_handoffs) self.assertEquals(devs, exp_first_handoffs)
@ -554,9 +556,9 @@ class TestRing(TestRingBase):
self.assertEquals(seen_zones, set(range(1, 10))) self.assertEquals(seen_zones, set(range(1, 10)))
devs = [] devs = []
for part in xrange(r.partition_count): for part in range(r.partition_count):
devs.append(next(r.get_more_nodes(part))['id']) devs.append(next(r.get_more_nodes(part))['id'])
for part in xrange(r.partition_count): for part in range(r.partition_count):
self.assertEquals( self.assertEquals(
devs[part], exp_first_handoffs[part], devs[part], exp_first_handoffs[part],
'handoff for partitition %d is now device id %d' % ( 'handoff for partitition %d is now device id %d' % (
@ -603,9 +605,9 @@ class TestRing(TestRingBase):
self.assertEquals(seen_zones, set(range(1, 10))) self.assertEquals(seen_zones, set(range(1, 10)))
devs = [] devs = []
for part in xrange(r.partition_count): for part in range(r.partition_count):
devs.append(next(r.get_more_nodes(part))['id']) devs.append(next(r.get_more_nodes(part))['id'])
for part in xrange(r.partition_count): for part in range(r.partition_count):
self.assertEquals( self.assertEquals(
devs[part], exp_first_handoffs[part], devs[part], exp_first_handoffs[part],
'handoff for partitition %d is now device id %d' % ( 'handoff for partitition %d is now device id %d' % (
@ -684,9 +686,9 @@ class TestRing(TestRingBase):
self.assertEquals(seen_zones, set(range(1, 10))) self.assertEquals(seen_zones, set(range(1, 10)))
devs = [] devs = []
for part in xrange(r.partition_count): for part in range(r.partition_count):
devs.append(next(r.get_more_nodes(part))['id']) devs.append(next(r.get_more_nodes(part))['id'])
for part in xrange(r.partition_count): for part in range(r.partition_count):
self.assertEquals( self.assertEquals(
devs[part], exp_first_handoffs[part], devs[part], exp_first_handoffs[part],
'handoff for partitition %d is now device id %d' % ( 'handoff for partitition %d is now device id %d' % (
@ -727,7 +729,7 @@ class TestRing(TestRingBase):
# Test distribution across regions # Test distribution across regions
rb.set_replicas(3) rb.set_replicas(3)
for region in xrange(1, 5): for region in range(1, 5):
rb.add_dev({'id': next_dev_id, rb.add_dev({'id': next_dev_id,
'ip': '1.%d.1.%d' % (region, server), 'port': 1234, 'ip': '1.%d.1.%d' % (region, server), 'port': 1234,
# 108.0 is the weight of all devices created prior to # 108.0 is the weight of all devices created prior to

View File

@ -18,6 +18,7 @@ import mock
import tempfile import tempfile
import time import time
from six.moves import range
from test import safe_repr from test import safe_repr
from test.unit import MockTrue from test.unit import MockTrue
@ -87,7 +88,7 @@ class TestConstraints(unittest.TestCase):
def test_check_metadata_count(self): def test_check_metadata_count(self):
headers = {} headers = {}
for x in xrange(constraints.MAX_META_COUNT): for x in range(constraints.MAX_META_COUNT):
headers['X-Object-Meta-%d' % x] = 'v' headers['X-Object-Meta-%d' % x] = 'v'
self.assertEquals(constraints.check_metadata(Request.blank( self.assertEquals(constraints.check_metadata(Request.blank(
'/', headers=headers), 'object'), None) '/', headers=headers), 'object'), None)

View File

@ -31,6 +31,7 @@ import random
from mock import patch, MagicMock from mock import patch, MagicMock
from eventlet.timeout import Timeout from eventlet.timeout import Timeout
from six.moves import range
import swift.common.db import swift.common.db
from swift.common.constraints import \ from swift.common.constraints import \
@ -1136,7 +1137,7 @@ class TestDatabaseBroker(unittest.TestCase):
def test_metadata_with_max_count(self): def test_metadata_with_max_count(self):
metadata = {} metadata = {}
for c in xrange(MAX_META_COUNT): for c in range(MAX_META_COUNT):
key = 'X-Account-Meta-F{0}'.format(c) key = 'X-Account-Meta-F{0}'.format(c)
metadata[key] = ('B', normalize_timestamp(1)) metadata[key] = ('B', normalize_timestamp(1))
key = 'X-Account-Meta-Foo'.format(c) key = 'X-Account-Meta-Foo'.format(c)
@ -1148,7 +1149,7 @@ class TestDatabaseBroker(unittest.TestCase):
def test_metadata_raises_exception_over_max_count(self): def test_metadata_raises_exception_over_max_count(self):
metadata = {} metadata = {}
for c in xrange(MAX_META_COUNT + 1): for c in range(MAX_META_COUNT + 1):
key = 'X-Account-Meta-F{0}'.format(c) key = 'X-Account-Meta-F{0}'.format(c)
metadata[key] = ('B', normalize_timestamp(1)) metadata[key] = ('B', normalize_timestamp(1))
message = '' message = ''

View File

@ -22,6 +22,7 @@ import zlib
from textwrap import dedent from textwrap import dedent
import os import os
from six.moves import range
from test.unit import FakeLogger from test.unit import FakeLogger
import eventlet import eventlet
from eventlet.green import urllib2 from eventlet.green import urllib2
@ -38,7 +39,7 @@ def not_sleep(seconds):
def unicode_string(start, length): def unicode_string(start, length):
return u''.join([unichr(x) for x in xrange(start, start + length)]) return u''.join([unichr(x) for x in range(start, start + length)])
def path_parts(): def path_parts():
@ -575,7 +576,7 @@ class TestInternalClient(unittest.TestCase):
exp_items = [] exp_items = []
responses = [] responses = []
for i in xrange(3): for i in range(3):
data = [ data = [
{'name': 'item%02d' % (2 * i)}, {'name': 'item%02d' % (2 * i)},
{'name': 'item%02d' % (2 * i + 1)}] {'name': 'item%02d' % (2 * i + 1)}]

View File

@ -1234,12 +1234,12 @@ class TestResponse(unittest.TestCase):
def app_iter_ranges(self, ranges, content_type, boundary, size): def app_iter_ranges(self, ranges, content_type, boundary, size):
app_iter_ranges_args.append((ranges, content_type, boundary, app_iter_ranges_args.append((ranges, content_type, boundary,
size)) size))
for i in xrange(3): for i in range(3):
yield str(i) + 'fun' yield str(i) + 'fun'
yield boundary yield boundary
def __iter__(self): def __iter__(self):
for i in xrange(3): for i in range(3):
yield str(i) + 'fun' yield str(i) + 'fun'
req = swift.common.swob.Request.blank( req = swift.common.swob.Request.blank(

View File

@ -28,6 +28,7 @@ import os
import mock import mock
import random import random
import re import re
from six.moves import range
import socket import socket
import stat import stat
import sys import sys
@ -3741,7 +3742,7 @@ class TestRateLimitedIterator(unittest.TestCase):
def test_rate_limiting(self): def test_rate_limiting(self):
def testfunc(): def testfunc():
limited_iterator = utils.RateLimitedIterator(xrange(9999), 100) limited_iterator = utils.RateLimitedIterator(range(9999), 100)
got = [] got = []
started_at = time.time() started_at = time.time()
try: try:
@ -3760,7 +3761,7 @@ class TestRateLimitedIterator(unittest.TestCase):
def testfunc(): def testfunc():
limited_iterator = utils.RateLimitedIterator( limited_iterator = utils.RateLimitedIterator(
xrange(9999), 100, limit_after=5) range(9999), 100, limit_after=5)
got = [] got = []
started_at = time.time() started_at = time.time()
try: try:
@ -3790,7 +3791,7 @@ class TestGreenthreadSafeIterator(unittest.TestCase):
iterable = UnsafeXrange(10) iterable = UnsafeXrange(10)
pile = eventlet.GreenPile(2) pile = eventlet.GreenPile(2)
for _ in xrange(2): for _ in range(2):
pile.spawn(self.increment, iterable) pile.spawn(self.increment, iterable)
sorted([resp for resp in pile]) sorted([resp for resp in pile])
@ -3801,10 +3802,10 @@ class TestGreenthreadSafeIterator(unittest.TestCase):
pile = eventlet.GreenPile(2) pile = eventlet.GreenPile(2)
unsafe_iterable = UnsafeXrange(10) unsafe_iterable = UnsafeXrange(10)
iterable = utils.GreenthreadSafeIterator(unsafe_iterable) iterable = utils.GreenthreadSafeIterator(unsafe_iterable)
for _ in xrange(2): for _ in range(2):
pile.spawn(self.increment, iterable) pile.spawn(self.increment, iterable)
response = sorted(sum([resp for resp in pile], [])) response = sorted(sum([resp for resp in pile], []))
self.assertEquals(range(1, 11), response) self.assertEquals(list(range(1, 11)), response)
self.assertTrue( self.assertTrue(
not unsafe_iterable.concurrent_call, 'concurrent call occurred') not unsafe_iterable.concurrent_call, 'concurrent call occurred')
@ -4472,7 +4473,7 @@ class TestGreenAsyncPile(unittest.TestCase):
return tests_ran[0] return tests_ran[0]
tests_ran = [0] tests_ran = [0]
pile = utils.GreenAsyncPile(3) pile = utils.GreenAsyncPile(3)
for x in xrange(3): for x in range(3):
pile.spawn(run_test) pile.spawn(run_test)
self.assertEqual(sorted(x for x in pile), [1, 2, 3]) self.assertEqual(sorted(x for x in pile), [1, 2, 3])
@ -4485,7 +4486,7 @@ class TestGreenAsyncPile(unittest.TestCase):
for order in ((1, 2, 0), (0, 1, 2), (2, 1, 0), (0, 2, 1)): for order in ((1, 2, 0), (0, 1, 2), (2, 1, 0), (0, 2, 1)):
events = [eventlet.event.Event(), eventlet.event.Event(), events = [eventlet.event.Event(), eventlet.event.Event(),
eventlet.event.Event()] eventlet.event.Event()]
for x in xrange(3): for x in range(3):
pile.spawn(run_test, x) pile.spawn(run_test, x)
for x in order: for x in order:
events[x].send() events[x].send()

View File

@ -1317,7 +1317,7 @@ class TestPipelineModification(unittest.TestCase):
# This is rather brittle; it'll break if a middleware stores its app # This is rather brittle; it'll break if a middleware stores its app
# anywhere other than an attribute named "app", but it works for now. # anywhere other than an attribute named "app", but it works for now.
pipe = [] pipe = []
for _ in xrange(1000): for _ in range(1000):
pipe.append(app.__class__.__module__) pipe.append(app.__class__.__module__)
if not hasattr(app, 'app'): if not hasattr(app, 'app'):
break break

View File

@ -738,17 +738,17 @@ class TestContainerBroker(unittest.TestCase):
# Test ContainerBroker.list_objects_iter # Test ContainerBroker.list_objects_iter
broker = ContainerBroker(':memory:', account='a', container='c') broker = ContainerBroker(':memory:', account='a', container='c')
broker.initialize(Timestamp('1').internal, 0) broker.initialize(Timestamp('1').internal, 0)
for obj1 in xrange(4): for obj1 in range(4):
for obj2 in xrange(125): for obj2 in range(125):
broker.put_object('%d/%04d' % (obj1, obj2), broker.put_object('%d/%04d' % (obj1, obj2),
Timestamp(time()).internal, 0, 'text/plain', Timestamp(time()).internal, 0, 'text/plain',
'd41d8cd98f00b204e9800998ecf8427e') 'd41d8cd98f00b204e9800998ecf8427e')
for obj in xrange(125): for obj in range(125):
broker.put_object('2/0051/%04d' % obj, broker.put_object('2/0051/%04d' % obj,
Timestamp(time()).internal, 0, 'text/plain', Timestamp(time()).internal, 0, 'text/plain',
'd41d8cd98f00b204e9800998ecf8427e') 'd41d8cd98f00b204e9800998ecf8427e')
for obj in xrange(125): for obj in range(125):
broker.put_object('3/%04d/0049' % obj, broker.put_object('3/%04d/0049' % obj,
Timestamp(time()).internal, 0, 'text/plain', Timestamp(time()).internal, 0, 'text/plain',
'd41d8cd98f00b204e9800998ecf8427e') 'd41d8cd98f00b204e9800998ecf8427e')
@ -857,17 +857,17 @@ class TestContainerBroker(unittest.TestCase):
# delimiter that is not a slash # delimiter that is not a slash
broker = ContainerBroker(':memory:', account='a', container='c') broker = ContainerBroker(':memory:', account='a', container='c')
broker.initialize(Timestamp('1').internal, 0) broker.initialize(Timestamp('1').internal, 0)
for obj1 in xrange(4): for obj1 in range(4):
for obj2 in xrange(125): for obj2 in range(125):
broker.put_object('%d:%04d' % (obj1, obj2), broker.put_object('%d:%04d' % (obj1, obj2),
Timestamp(time()).internal, 0, 'text/plain', Timestamp(time()).internal, 0, 'text/plain',
'd41d8cd98f00b204e9800998ecf8427e') 'd41d8cd98f00b204e9800998ecf8427e')
for obj in xrange(125): for obj in range(125):
broker.put_object('2:0051:%04d' % obj, broker.put_object('2:0051:%04d' % obj,
Timestamp(time()).internal, 0, 'text/plain', Timestamp(time()).internal, 0, 'text/plain',
'd41d8cd98f00b204e9800998ecf8427e') 'd41d8cd98f00b204e9800998ecf8427e')
for obj in xrange(125): for obj in range(125):
broker.put_object('3:%04d:0049' % obj, broker.put_object('3:%04d:0049' % obj,
Timestamp(time()).internal, 0, 'text/plain', Timestamp(time()).internal, 0, 'text/plain',
'd41d8cd98f00b204e9800998ecf8427e') 'd41d8cd98f00b204e9800998ecf8427e')

View File

@ -37,7 +37,7 @@ class FakeRing(object):
def __init__(self): def __init__(self):
self.devs = [{'ip': '10.0.0.%s' % x, 'port': 1000 + x, 'device': 'sda'} self.devs = [{'ip': '10.0.0.%s' % x, 'port': 1000 + x, 'device': 'sda'}
for x in xrange(3)] for x in range(3)]
def get_nodes(self, account, container=None, obj=None): def get_nodes(self, account, container=None, obj=None):
return 1, list(self.devs) return 1, list(self.devs)

View File

@ -139,7 +139,7 @@ class TestContainerUpdater(unittest.TestCase):
def spawn_accepts(): def spawn_accepts():
events = [] events = []
for _junk in xrange(2): for _junk in range(2):
sock, addr = bindsock.accept() sock, addr = bindsock.accept()
events.append(spawn(accept, sock, addr, 201)) events.append(spawn(accept, sock, addr, 201))
return events return events
@ -234,7 +234,7 @@ class TestContainerUpdater(unittest.TestCase):
def spawn_accepts(): def spawn_accepts():
events = [] events = []
for _junk in xrange(2): for _junk in range(2):
with Timeout(3): with Timeout(3):
sock, addr = bindsock.accept() sock, addr = bindsock.accept()
events.append(spawn(accept, sock, addr)) events.append(spawn(accept, sock, addr))

View File

@ -172,7 +172,7 @@ class TestObjectExpirer(TestCase):
x.swift = InternalClient(containers) x.swift = InternalClient(containers)
deleted_objects = {} deleted_objects = {}
for i in xrange(3): for i in range(3):
x.process = i x.process = i
x.run_once() x.run_once()
self.assertNotEqual(deleted_objects, x.deleted_objects) self.assertNotEqual(deleted_objects, x.deleted_objects)

View File

@ -28,6 +28,7 @@ from time import time
from distutils.dir_util import mkpath from distutils.dir_util import mkpath
from eventlet import spawn, Timeout, listen from eventlet import spawn, Timeout, listen
from six.moves import range
from swift.obj import updater as object_updater from swift.obj import updater as object_updater
from swift.obj.diskfile import (ASYNCDIR_BASE, get_async_dir, DiskFileManager, from swift.obj.diskfile import (ASYNCDIR_BASE, get_async_dir, DiskFileManager,
@ -332,7 +333,7 @@ class TestObjectUpdater(unittest.TestCase):
codes = iter(return_codes) codes = iter(return_codes)
try: try:
events = [] events = []
for x in xrange(len(return_codes)): for x in range(len(return_codes)):
with Timeout(3): with Timeout(3):
sock, addr = bindsock.accept() sock, addr = bindsock.accept()
events.append( events.append(

View File

@ -26,6 +26,7 @@ from hashlib import md5
import mock import mock
from eventlet import Timeout from eventlet import Timeout
from six.moves import range
import swift import swift
from swift.common import utils, swob from swift.common import utils, swob
@ -1442,7 +1443,7 @@ class TestECObjController(BaseObjectControllerMixin, unittest.TestCase):
# swap out some with regular fast responses # swap out some with regular fast responses
number_of_fast_responses_needed_to_be_quick_enough = 2 number_of_fast_responses_needed_to_be_quick_enough = 2
fast_indexes = random.sample( fast_indexes = random.sample(
xrange(self.replicas()), range(self.replicas()),
number_of_fast_responses_needed_to_be_quick_enough) number_of_fast_responses_needed_to_be_quick_enough)
for i in fast_indexes: for i in fast_indexes:
codes[i] = 201 codes[i] = 201

View File

@ -42,6 +42,7 @@ import random
import mock import mock
from eventlet import sleep, spawn, wsgi, listen, Timeout from eventlet import sleep, spawn, wsgi, listen, Timeout
from six.moves import range
from swift.common.utils import hash_path, json, storage_directory, \ from swift.common.utils import hash_path, json, storage_directory, \
parse_content_type, iter_multipart_mime_documents, public parse_content_type, iter_multipart_mime_documents, public
@ -3416,7 +3417,7 @@ class TestObjectController(unittest.TestCase):
with save_globals(): with save_globals():
limit = constraints.MAX_META_COUNT limit = constraints.MAX_META_COUNT
headers = dict( headers = dict(
(('X-Object-Meta-' + str(i), 'a') for i in xrange(limit + 1))) (('X-Object-Meta-' + str(i), 'a') for i in range(limit + 1)))
headers.update({'Content-Type': 'foo/bar'}) headers.update({'Content-Type': 'foo/bar'})
set_http_connect(202, 202, 202) set_http_connect(202, 202, 202)
req = Request.blank('/v1/a/c/o', {'REQUEST_METHOD': 'POST'}, req = Request.blank('/v1/a/c/o', {'REQUEST_METHOD': 'POST'},
@ -3431,7 +3432,7 @@ class TestObjectController(unittest.TestCase):
count = limit / 256 # enough to cause the limit to be reached count = limit / 256 # enough to cause the limit to be reached
headers = dict( headers = dict(
(('X-Object-Meta-' + str(i), 'a' * 256) (('X-Object-Meta-' + str(i), 'a' * 256)
for i in xrange(count + 1))) for i in range(count + 1)))
headers.update({'Content-Type': 'foo/bar'}) headers.update({'Content-Type': 'foo/bar'})
set_http_connect(202, 202, 202) set_http_connect(202, 202, 202)
req = Request.blank('/v1/a/c/o', {'REQUEST_METHOD': 'POST'}, req = Request.blank('/v1/a/c/o', {'REQUEST_METHOD': 'POST'},
@ -3860,7 +3861,7 @@ class TestObjectController(unittest.TestCase):
def test_iter_nodes_with_custom_node_iter(self): def test_iter_nodes_with_custom_node_iter(self):
object_ring = self.app.get_object_ring(None) object_ring = self.app.get_object_ring(None)
node_list = [dict(id=n, ip='1.2.3.4', port=n, device='D') node_list = [dict(id=n, ip='1.2.3.4', port=n, device='D')
for n in xrange(10)] for n in range(10)]
with nested( with nested(
mock.patch.object(self.app, 'sort_nodes', lambda n: n), mock.patch.object(self.app, 'sort_nodes', lambda n: n),
mock.patch.object(self.app, 'request_node_count', mock.patch.object(self.app, 'request_node_count',
@ -3945,7 +3946,7 @@ class TestObjectController(unittest.TestCase):
node_error_count(controller.app, object_ring.devs[0]), 2) node_error_count(controller.app, object_ring.devs[0]), 2)
self.assert_(node_last_error(controller.app, object_ring.devs[0]) self.assert_(node_last_error(controller.app, object_ring.devs[0])
is not None) is not None)
for _junk in xrange(self.app.error_suppression_limit): for _junk in range(self.app.error_suppression_limit):
self.assert_status_map(controller.HEAD, (200, 200, 503, 503, self.assert_status_map(controller.HEAD, (200, 200, 503, 503,
503), 503) 503), 503)
self.assertEquals( self.assertEquals(
@ -3982,7 +3983,7 @@ class TestObjectController(unittest.TestCase):
node_error_count(controller.app, object_ring.devs[0]), 2) node_error_count(controller.app, object_ring.devs[0]), 2)
self.assert_(node_last_error(controller.app, object_ring.devs[0]) self.assert_(node_last_error(controller.app, object_ring.devs[0])
is not None) is not None)
for _junk in xrange(self.app.error_suppression_limit): for _junk in range(self.app.error_suppression_limit):
self.assert_status_map(controller.HEAD, (200, 200, 503, 503, self.assert_status_map(controller.HEAD, (200, 200, 503, 503,
503), 503) 503), 503)
self.assertEquals( self.assertEquals(
@ -4226,7 +4227,7 @@ class TestObjectController(unittest.TestCase):
set_http_connect(201, 201, 201) set_http_connect(201, 201, 201)
headers = {'Content-Length': '0'} headers = {'Content-Length': '0'}
for x in xrange(constraints.MAX_META_COUNT): for x in range(constraints.MAX_META_COUNT):
headers['X-Object-Meta-%d' % x] = 'v' headers['X-Object-Meta-%d' % x] = 'v'
req = Request.blank('/v1/a/c/o', environ={'REQUEST_METHOD': 'PUT'}, req = Request.blank('/v1/a/c/o', environ={'REQUEST_METHOD': 'PUT'},
headers=headers) headers=headers)
@ -4235,7 +4236,7 @@ class TestObjectController(unittest.TestCase):
self.assertEquals(resp.status_int, 201) self.assertEquals(resp.status_int, 201)
set_http_connect(201, 201, 201) set_http_connect(201, 201, 201)
headers = {'Content-Length': '0'} headers = {'Content-Length': '0'}
for x in xrange(constraints.MAX_META_COUNT + 1): for x in range(constraints.MAX_META_COUNT + 1):
headers['X-Object-Meta-%d' % x] = 'v' headers['X-Object-Meta-%d' % x] = 'v'
req = Request.blank('/v1/a/c/o', environ={'REQUEST_METHOD': 'PUT'}, req = Request.blank('/v1/a/c/o', environ={'REQUEST_METHOD': 'PUT'},
headers=headers) headers=headers)
@ -5359,7 +5360,7 @@ class TestObjectController(unittest.TestCase):
exp = 'HTTP/1.1 201' exp = 'HTTP/1.1 201'
self.assertEquals(headers[:len(exp)], exp) self.assertEquals(headers[:len(exp)], exp)
# Create the object versions # Create the object versions
for segment in xrange(1, versions_to_create): for segment in range(1, versions_to_create):
sleep(.01) # guarantee that the timestamp changes sleep(.01) # guarantee that the timestamp changes
sock = connect_tcp(('localhost', prolis.getsockname()[1])) sock = connect_tcp(('localhost', prolis.getsockname()[1]))
fd = sock.makefile() fd = sock.makefile()
@ -5445,7 +5446,7 @@ class TestObjectController(unittest.TestCase):
body = fd.read() body = fd.read()
self.assertEquals(body, '%05d' % segment) self.assertEquals(body, '%05d' % segment)
# Delete the object versions # Delete the object versions
for segment in xrange(versions_to_create - 1, 0, -1): for segment in range(versions_to_create - 1, 0, -1):
sock = connect_tcp(('localhost', prolis.getsockname()[1])) sock = connect_tcp(('localhost', prolis.getsockname()[1]))
fd = sock.makefile() fd = sock.makefile()
fd.write('DELETE /v1/a/%s/%s HTTP/1.1\r\nHost: localhost\r' fd.write('DELETE /v1/a/%s/%s HTTP/1.1\r\nHost: localhost\r'
@ -5514,7 +5515,7 @@ class TestObjectController(unittest.TestCase):
self.assertEquals(headers[:len(exp)], exp) self.assertEquals(headers[:len(exp)], exp)
# make sure dlo manifest files don't get versioned # make sure dlo manifest files don't get versioned
for _junk in xrange(1, versions_to_create): for _junk in range(1, versions_to_create):
sleep(.01) # guarantee that the timestamp changes sleep(.01) # guarantee that the timestamp changes
sock = connect_tcp(('localhost', prolis.getsockname()[1])) sock = connect_tcp(('localhost', prolis.getsockname()[1]))
fd = sock.makefile() fd = sock.makefile()
@ -6071,7 +6072,7 @@ class TestObjectController(unittest.TestCase):
self.assertEqual(headers[:len(exp)], exp) self.assertEqual(headers[:len(exp)], exp)
# Remember Request instance count, make sure the GC is run for # Remember Request instance count, make sure the GC is run for
# pythons without reference counting. # pythons without reference counting.
for i in xrange(4): for i in range(4):
sleep(0) # let eventlet do its thing sleep(0) # let eventlet do its thing
gc.collect() gc.collect()
else: else:
@ -6094,7 +6095,7 @@ class TestObjectController(unittest.TestCase):
sock.close() sock.close()
# Make sure the GC is run again for pythons without reference # Make sure the GC is run again for pythons without reference
# counting # counting
for i in xrange(4): for i in range(4):
sleep(0) # let eventlet do its thing sleep(0) # let eventlet do its thing
gc.collect() gc.collect()
else: else:
@ -7593,7 +7594,7 @@ class TestContainerController(unittest.TestCase):
self.assert_( self.assert_(
node_last_error(controller.app, container_ring.devs[0]) node_last_error(controller.app, container_ring.devs[0])
is not None) is not None)
for _junk in xrange(self.app.error_suppression_limit): for _junk in range(self.app.error_suppression_limit):
self.assert_status_map(controller.HEAD, self.assert_status_map(controller.HEAD,
(200, 503, 503, 503), 503) (200, 503, 503, 503), 503)
self.assertEquals( self.assertEquals(
@ -7749,7 +7750,7 @@ class TestContainerController(unittest.TestCase):
set_http_connect(201, 201, 201) set_http_connect(201, 201, 201)
headers = {} headers = {}
for x in xrange(constraints.MAX_META_COUNT): for x in range(constraints.MAX_META_COUNT):
headers['X-Container-Meta-%d' % x] = 'v' headers['X-Container-Meta-%d' % x] = 'v'
req = Request.blank('/v1/a/c', environ={'REQUEST_METHOD': method}, req = Request.blank('/v1/a/c', environ={'REQUEST_METHOD': method},
headers=headers) headers=headers)
@ -7758,7 +7759,7 @@ class TestContainerController(unittest.TestCase):
self.assertEquals(resp.status_int, 201) self.assertEquals(resp.status_int, 201)
set_http_connect(201, 201, 201) set_http_connect(201, 201, 201)
headers = {} headers = {}
for x in xrange(constraints.MAX_META_COUNT + 1): for x in range(constraints.MAX_META_COUNT + 1):
headers['X-Container-Meta-%d' % x] = 'v' headers['X-Container-Meta-%d' % x] = 'v'
req = Request.blank('/v1/a/c', environ={'REQUEST_METHOD': method}, req = Request.blank('/v1/a/c', environ={'REQUEST_METHOD': method},
headers=headers) headers=headers)
@ -8704,7 +8705,7 @@ class TestAccountController(unittest.TestCase):
set_http_connect(201, 201, 201) set_http_connect(201, 201, 201)
headers = {} headers = {}
for x in xrange(constraints.MAX_META_COUNT): for x in range(constraints.MAX_META_COUNT):
headers['X-Account-Meta-%d' % x] = 'v' headers['X-Account-Meta-%d' % x] = 'v'
req = Request.blank('/v1/a/c', environ={'REQUEST_METHOD': method}, req = Request.blank('/v1/a/c', environ={'REQUEST_METHOD': method},
headers=headers) headers=headers)
@ -8713,7 +8714,7 @@ class TestAccountController(unittest.TestCase):
self.assertEquals(resp.status_int, 201) self.assertEquals(resp.status_int, 201)
set_http_connect(201, 201, 201) set_http_connect(201, 201, 201)
headers = {} headers = {}
for x in xrange(constraints.MAX_META_COUNT + 1): for x in range(constraints.MAX_META_COUNT + 1):
headers['X-Account-Meta-%d' % x] = 'v' headers['X-Account-Meta-%d' % x] = 'v'
req = Request.blank('/v1/a/c', environ={'REQUEST_METHOD': method}, req = Request.blank('/v1/a/c', environ={'REQUEST_METHOD': method},
headers=headers) headers=headers)