diff --git a/swift/account/reaper.py b/swift/account/reaper.py index 90265b9ea5..488f1c541e 100644 --- a/swift/account/reaper.py +++ b/swift/account/reaper.py @@ -267,7 +267,7 @@ class AccountReaper(Daemon): self.stats_objects_possibly_remaining if self.stats_return_codes: log += _(', return codes: ') - for code in sorted(self.stats_return_codes.keys()): + for code in sorted(self.stats_return_codes): log += '%s %sxxs, ' % (self.stats_return_codes[code], code) log = log[:-2] log += _(', elapsed: %.02fs') % (time() - begin) diff --git a/swift/common/db.py b/swift/common/db.py index cbe1c2ca35..20fec973af 100644 --- a/swift/common/db.py +++ b/swift/common/db.py @@ -50,7 +50,7 @@ def utf8encode(*args): def utf8encodekeys(metadata): - uni_keys = [k for k in metadata.keys() if isinstance(k, unicode)] + uni_keys = [k for k in metadata if isinstance(k, unicode)] for k in uni_keys: sv = metadata[k] del metadata[k] @@ -274,7 +274,7 @@ class DatabaseBroker(object): timestamp = normalize_timestamp(timestamp) # first, clear the metadata cleared_meta = {} - for k in self.metadata.iterkeys(): + for k in self.metadata: cleared_meta[k] = ('', timestamp) self.update_metadata(cleared_meta) # then mark the db as deleted diff --git a/swift/common/memcached.py b/swift/common/memcached.py index 9c5f96d487..678e66a668 100644 --- a/swift/common/memcached.py +++ b/swift/common/memcached.py @@ -106,7 +106,7 @@ class MemcacheRing(object): for i in xrange(NODE_WEIGHT): self._ring[md5hash('%s-%s' % (server, i))] = server self._tries = tries if tries <= len(servers) else len(servers) - self._sorted = sorted(self._ring.keys()) + self._sorted = sorted(self._ring) self._client_cache = dict(((server, []) for server in servers)) self._connect_timeout = connect_timeout self._io_timeout = io_timeout diff --git a/swift/common/middleware/bulk.py b/swift/common/middleware/bulk.py index 89971ed6b5..92abdbd556 100644 --- a/swift/common/middleware/bulk.py +++ b/swift/common/middleware/bulk.py @@ -56,7 +56,7 @@ def get_response_body(data_format, data_dict, error_list): return json.dumps(data_dict) if data_format and data_format.endswith('/xml'): output = '\n' - for key in sorted(data_dict.keys()): + for key in sorted(data_dict): xml_key = key.replace(' ', '_').lower() output += '<%s>%s\n' % (xml_key, data_dict[key], xml_key) output += '\n' @@ -69,7 +69,7 @@ def get_response_body(data_format, data_dict, error_list): return output output = '' - for key in sorted(data_dict.keys()): + for key in sorted(data_dict): output += '%s: %s\n' % (key, data_dict[key]) output += 'Errors:\n' output += '\n'.join( diff --git a/swift/common/middleware/ratelimit.py b/swift/common/middleware/ratelimit.py index 56efb411be..a139e8e2db 100644 --- a/swift/common/middleware/ratelimit.py +++ b/swift/common/middleware/ratelimit.py @@ -25,7 +25,7 @@ from swift.common.swob import Request, Response def interpret_conf_limits(conf, name_prefix): conf_limits = [] - for conf_key in conf.keys(): + for conf_key in conf: if conf_key.startswith(name_prefix): cont_size = int(conf_key[len(name_prefix):]) rate = float(conf[conf_key]) diff --git a/swift/common/middleware/slo.py b/swift/common/middleware/slo.py index 48760867b5..186e28cc5c 100644 --- a/swift/common/middleware/slo.py +++ b/swift/common/middleware/slo.py @@ -164,7 +164,7 @@ def parse_input(raw_data): req_keys = set(['path', 'etag', 'size_bytes']) try: for seg_dict in parsed_data: - if (set(seg_dict.keys()) != req_keys or + if (set(seg_dict) != req_keys or '/' not in seg_dict['path'].lstrip('/')): raise HTTPBadRequest('Invalid SLO Manifest File') except (AttributeError, TypeError): diff --git a/swift/common/ring/ring.py b/swift/common/ring/ring.py index 5f4dba83be..9ed0b35bfd 100644 --- a/swift/common/ring/ring.py +++ b/swift/common/ring/ring.py @@ -171,7 +171,7 @@ class Ring(object): self.tier2devs[tier].append(dev) tiers_by_length = defaultdict(list) - for tier in self.tier2devs.keys(): + for tier in self.tier2devs: tiers_by_length[len(tier)].append(tier) self.tiers_by_length = sorted(tiers_by_length.values(), key=lambda x: len(x[0])) diff --git a/swift/common/swob.py b/swift/common/swob.py index 7a396354f2..73efa60700 100644 --- a/swift/common/swob.py +++ b/swift/common/swob.py @@ -235,7 +235,7 @@ class HeaderEnvironProxy(UserDict.DictMixin): def keys(self): keys = [key[5:].replace('_', '-').title() - for key in self.environ.iterkeys() if key.startswith('HTTP_')] + for key in self.environ if key.startswith('HTTP_')] if 'CONTENT_LENGTH' in self.environ: keys.append('Content-Length') if 'CONTENT_TYPE' in self.environ: diff --git a/swift/container/server.py b/swift/container/server.py index 42aed48af1..9013ce8c57 100644 --- a/swift/container/server.py +++ b/swift/container/server.py @@ -406,7 +406,7 @@ class ContainerController(object): "last_modified"]: SubElement(obj_element, field).text = str( record.pop(field)).decode('utf-8') - for field in sorted(record.keys()): + for field in sorted(record): SubElement(obj_element, field).text = str( record[field]).decode('utf-8') ret.body = tostring(doc, encoding='UTF-8').replace(