diff --git a/swift/common/middleware/crypto/crypto_utils.py b/swift/common/middleware/crypto/crypto_utils.py index 13327ebb2b..6de9b96c89 100644 --- a/swift/common/middleware/crypto/crypto_utils.py +++ b/swift/common/middleware/crypto/crypto_utils.py @@ -78,7 +78,7 @@ class Crypto(object): # The CTR mode offset is incremented for every AES block and taken # modulo 2^128. offset_blocks, offset_in_block = divmod(offset, self.iv_length) - ivl = long(binascii.hexlify(iv), 16) + offset_blocks + ivl = int(binascii.hexlify(iv), 16) + offset_blocks ivl %= 1 << algorithms.AES.block_size iv = str(bytearray.fromhex(format( ivl, '0%dx' % (2 * self.iv_length)))) diff --git a/swift/common/middleware/s3api/controllers/obj.py b/swift/common/middleware/s3api/controllers/obj.py index 7017170a7b..57e1fc5518 100644 --- a/swift/common/middleware/s3api/controllers/obj.py +++ b/swift/common/middleware/s3api/controllers/obj.py @@ -37,7 +37,7 @@ class ObjectController(Controller): conditions which are described in the following document. - http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35 """ - length = long(resp.headers.get('Content-Length')) + length = int(resp.headers.get('Content-Length')) try: content_range = Range(req_range) diff --git a/swift/common/middleware/s3api/etree.py b/swift/common/middleware/s3api/etree.py index cfbc8b24df..386e1bd767 100644 --- a/swift/common/middleware/s3api/etree.py +++ b/swift/common/middleware/s3api/etree.py @@ -17,6 +17,7 @@ import lxml.etree from urllib import quote from copy import deepcopy from pkg_resources import resource_stream # pylint: disable-msg=E0611 +import six import sys from swift.common.utils import get_logger @@ -42,7 +43,7 @@ def cleanup_namespaces(elem): tag = tag[len('{%s}' % ns):] return tag - if not isinstance(elem.tag, basestring): + if not isinstance(elem.tag, six.string_types): # elem is a comment element. return @@ -104,7 +105,7 @@ def tostring(tree, encoding_type=None, use_s3ns=True): # encoding_type=url. blacklist = ['LastModified', 'ID', 'DisplayName', 'Initiated'] if e.tag not in blacklist: - if isinstance(e.text, basestring): + if isinstance(e.text, six.string_types): e.text = quote(e.text) return lxml.etree.tostring(tree, xml_declaration=True, encoding='UTF-8') diff --git a/swift/common/middleware/s3api/utils.py b/swift/common/middleware/s3api/utils.py index bdc3346a1d..a8ed2748fb 100644 --- a/swift/common/middleware/s3api/utils.py +++ b/swift/common/middleware/s3api/utils.py @@ -55,13 +55,13 @@ def unique_id(): def utf8encode(s): - if isinstance(s, unicode): - s = s.encode('utf8') - return s + if s is None or isinstance(s, bytes): + return s + return s.encode('utf8') def utf8decode(s): - if isinstance(s, str): + if isinstance(s, bytes): s = s.decode('utf8') return s diff --git a/swift/container/reconciler.py b/swift/container/reconciler.py index ba0fa7438f..539288e168 100644 --- a/swift/container/reconciler.py +++ b/swift/container/reconciler.py @@ -54,6 +54,14 @@ def cmp_policy_info(info, remote_info): return (info['delete_timestamp'] > info['put_timestamp'] and info.get('count', info.get('object_count', 0)) == 0) + def cmp(a, b): + if a < b: + return -1 + elif b < a: + return 1 + else: + return 0 + deleted = is_deleted(info) remote_deleted = is_deleted(remote_info) if any([deleted, remote_deleted]): diff --git a/swift/obj/reconstructor.py b/swift/obj/reconstructor.py index 6f7ac821d8..2a2de8ef22 100644 --- a/swift/obj/reconstructor.py +++ b/swift/obj/reconstructor.py @@ -1016,9 +1016,10 @@ class ObjectReconstructor(Daemon): def get_local_devices(self): """Returns a set of all local devices in all EC policies.""" policy2devices = self.get_policy2devices() - return reduce(set.union, ( - set(d['device'] for d in devices) - for devices in policy2devices.values()), set()) + local_devices = set() + for devices in policy2devices.values(): + local_devices.update(d['device'] for d in devices) + return local_devices def collect_parts(self, override_devices=None, override_partitions=None): """