py3: fix up some NameErrors
reduce, cmp, basestring, unicode, long -- none of those exist under py3. Change-Id: I860abbae3fa4e8353a090df1470aa706d5906e2f
This commit is contained in:
parent
ea33638d0c
commit
a718cb3f1f
@ -78,7 +78,7 @@ class Crypto(object):
|
|||||||
# The CTR mode offset is incremented for every AES block and taken
|
# The CTR mode offset is incremented for every AES block and taken
|
||||||
# modulo 2^128.
|
# modulo 2^128.
|
||||||
offset_blocks, offset_in_block = divmod(offset, self.iv_length)
|
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
|
ivl %= 1 << algorithms.AES.block_size
|
||||||
iv = str(bytearray.fromhex(format(
|
iv = str(bytearray.fromhex(format(
|
||||||
ivl, '0%dx' % (2 * self.iv_length))))
|
ivl, '0%dx' % (2 * self.iv_length))))
|
||||||
|
@ -37,7 +37,7 @@ class ObjectController(Controller):
|
|||||||
conditions which are described in the following document.
|
conditions which are described in the following document.
|
||||||
- http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35
|
- 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:
|
try:
|
||||||
content_range = Range(req_range)
|
content_range = Range(req_range)
|
||||||
|
@ -17,6 +17,7 @@ import lxml.etree
|
|||||||
from urllib import quote
|
from urllib import quote
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
from pkg_resources import resource_stream # pylint: disable-msg=E0611
|
from pkg_resources import resource_stream # pylint: disable-msg=E0611
|
||||||
|
import six
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from swift.common.utils import get_logger
|
from swift.common.utils import get_logger
|
||||||
@ -42,7 +43,7 @@ def cleanup_namespaces(elem):
|
|||||||
tag = tag[len('{%s}' % ns):]
|
tag = tag[len('{%s}' % ns):]
|
||||||
return tag
|
return tag
|
||||||
|
|
||||||
if not isinstance(elem.tag, basestring):
|
if not isinstance(elem.tag, six.string_types):
|
||||||
# elem is a comment element.
|
# elem is a comment element.
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -104,7 +105,7 @@ def tostring(tree, encoding_type=None, use_s3ns=True):
|
|||||||
# encoding_type=url.
|
# encoding_type=url.
|
||||||
blacklist = ['LastModified', 'ID', 'DisplayName', 'Initiated']
|
blacklist = ['LastModified', 'ID', 'DisplayName', 'Initiated']
|
||||||
if e.tag not in blacklist:
|
if e.tag not in blacklist:
|
||||||
if isinstance(e.text, basestring):
|
if isinstance(e.text, six.string_types):
|
||||||
e.text = quote(e.text)
|
e.text = quote(e.text)
|
||||||
|
|
||||||
return lxml.etree.tostring(tree, xml_declaration=True, encoding='UTF-8')
|
return lxml.etree.tostring(tree, xml_declaration=True, encoding='UTF-8')
|
||||||
|
@ -55,13 +55,13 @@ def unique_id():
|
|||||||
|
|
||||||
|
|
||||||
def utf8encode(s):
|
def utf8encode(s):
|
||||||
if isinstance(s, unicode):
|
if s is None or isinstance(s, bytes):
|
||||||
s = s.encode('utf8')
|
return s
|
||||||
return s
|
return s.encode('utf8')
|
||||||
|
|
||||||
|
|
||||||
def utf8decode(s):
|
def utf8decode(s):
|
||||||
if isinstance(s, str):
|
if isinstance(s, bytes):
|
||||||
s = s.decode('utf8')
|
s = s.decode('utf8')
|
||||||
return s
|
return s
|
||||||
|
|
||||||
|
@ -54,6 +54,14 @@ def cmp_policy_info(info, remote_info):
|
|||||||
return (info['delete_timestamp'] > info['put_timestamp'] and
|
return (info['delete_timestamp'] > info['put_timestamp'] and
|
||||||
info.get('count', info.get('object_count', 0)) == 0)
|
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)
|
deleted = is_deleted(info)
|
||||||
remote_deleted = is_deleted(remote_info)
|
remote_deleted = is_deleted(remote_info)
|
||||||
if any([deleted, remote_deleted]):
|
if any([deleted, remote_deleted]):
|
||||||
|
@ -1016,9 +1016,10 @@ class ObjectReconstructor(Daemon):
|
|||||||
def get_local_devices(self):
|
def get_local_devices(self):
|
||||||
"""Returns a set of all local devices in all EC policies."""
|
"""Returns a set of all local devices in all EC policies."""
|
||||||
policy2devices = self.get_policy2devices()
|
policy2devices = self.get_policy2devices()
|
||||||
return reduce(set.union, (
|
local_devices = set()
|
||||||
set(d['device'] for d in devices)
|
for devices in policy2devices.values():
|
||||||
for devices in policy2devices.values()), set())
|
local_devices.update(d['device'] for d in devices)
|
||||||
|
return local_devices
|
||||||
|
|
||||||
def collect_parts(self, override_devices=None, override_partitions=None):
|
def collect_parts(self, override_devices=None, override_partitions=None):
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user