Merge "py3: fix up some NameErrors"

This commit is contained in:
Zuul 2018-07-24 19:22:43 +00:00 committed by Gerrit Code Review
commit d398d60e5a
6 changed files with 21 additions and 11 deletions

View File

@ -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))))

View File

@ -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)

View File

@ -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')

View File

@ -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

View File

@ -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]):

View File

@ -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):
"""