From 70f4e115b61bdae7af5edc16f443683fb718a5b2 Mon Sep 17 00:00:00 2001 From: abhishekkekane Date: Sun, 31 Jan 2016 00:23:01 -0800 Subject: [PATCH] Python3: Add support for iteritems and iterkeys Replaced dict.iteritems with dict.items Replaced dict.iterkeys with key in dict Partially implements: blueprint trove-python3 Change-Id: I24c3fdea4f40ef92dd6cd564ee34eab8c03b2520 --- trove/common/base_wsgi.py | 2 +- trove/common/extensions.py | 12 ++++++------ trove/common/strategies/storage/swift.py | 4 ++-- trove/common/utils.py | 4 ++-- trove/configuration/models.py | 2 +- trove/configuration/service.py | 6 +++--- trove/db/models.py | 2 +- trove/db/sqlalchemy/api.py | 2 +- trove/guestagent/common/guestagent_utils.py | 2 +- trove/guestagent/datastore/mysql_common/service.py | 2 +- trove/guestagent/dbaas.py | 4 ++-- trove/tests/api/configurations.py | 2 +- trove/tests/fakes/keystone.py | 2 +- trove/tests/fakes/swift.py | 2 +- trove/tests/util/usage.py | 2 +- 15 files changed, 25 insertions(+), 25 deletions(-) diff --git a/trove/common/base_wsgi.py b/trove/common/base_wsgi.py index 3b7a5103b8..a43016cf96 100644 --- a/trove/common/base_wsgi.py +++ b/trove/common/base_wsgi.py @@ -210,7 +210,7 @@ class Debug(Middleware): resp = req.get_response(self.application) print(("*" * 40) + " RESPONSE HEADERS") - for (key, value) in resp.headers.iteritems(): + for (key, value) in resp.headers.items(): print(key, "=", value) print() diff --git a/trove/common/extensions.py b/trove/common/extensions.py index a822946de3..ad5b1cb95c 100644 --- a/trove/common/extensions.py +++ b/trove/common/extensions.py @@ -125,7 +125,7 @@ class ActionExtensionController(object): self.action_handlers[action_name] = handler def action(self, req, id, body): - for action_name, handler in self.action_handlers.iteritems(): + for action_name, handler in self.action_handlers.items(): if action_name in body: return handler(body, req, id) # no action handler found (bump to downstream application) @@ -191,7 +191,7 @@ class ExtensionsResource(wsgi.Resource): def index(self, req): extensions = [] - for _alias, ext in self.extension_manager.extensions.iteritems(): + for _alias, ext in self.extension_manager.extensions.items(): extensions.append(self._translate(ext)) return dict(extensions=extensions) @@ -304,7 +304,7 @@ class ExtensionMiddleware(wsgi.Middleware): def _map_custom_collection_actions(self, resource_ext, mapper, controller_resource): - for action, method in resource_ext.collection_actions.iteritems(): + for action, method in resource_ext.collection_actions.items(): parent = resource_ext.parent conditions = dict(method=[method]) path = "/%s/%s" % (resource_ext.collection, action) @@ -362,7 +362,7 @@ class ExtensionManager(object): extension_resource, serializer=extension_resource.serializer) resources.append(res_ext) - for alias, ext in self.extensions.iteritems(): + for alias, ext in self.extensions.items(): try: resources.extend(ext.get_resources()) except AttributeError: @@ -372,7 +372,7 @@ class ExtensionManager(object): def get_actions(self): """Returns a list of ActionExtension objects.""" actions = [] - for alias, ext in self.extensions.iteritems(): + for alias, ext in self.extensions.items(): try: actions.extend(ext.get_actions()) except AttributeError: @@ -382,7 +382,7 @@ class ExtensionManager(object): def get_request_extensions(self): """Returns a list of RequestExtension objects.""" request_exts = [] - for alias, ext in self.extensions.iteritems(): + for alias, ext in self.extensions.items(): try: request_exts.extend(ext.get_request_extensions()) except AttributeError: diff --git a/trove/common/strategies/storage/swift.py b/trove/common/strategies/storage/swift.py index efe67cfdd5..3ec26a5e02 100644 --- a/trove/common/strategies/storage/swift.py +++ b/trove/common/strategies/storage/swift.py @@ -218,7 +218,7 @@ class SwiftStorage(base.Storage): self._verify_checksum(headers.get('etag', ''), backup_checksum) _meta = {} - for key, value in headers.iteritems(): + for key, value in headers.items(): if key.startswith('x-object-meta'): _meta[self._get_attr(key)] = value @@ -231,7 +231,7 @@ class SwiftStorage(base.Storage): _headers = self.connection.head_object(container, filename) headers = {'X-Object-Manifest': _headers.get('x-object-manifest')} - for key, value in metadata.iteritems(): + for key, value in metadata.items(): headers[self._set_attr(key)] = value LOG.info(_("Writing metadata: %s"), str(headers)) diff --git a/trove/common/utils.py b/trove/common/utils.py index f86b306db7..f09499ae7f 100644 --- a/trove/common/utils.py +++ b/trove/common/utils.py @@ -83,13 +83,13 @@ def create_method_args_string(*args, **kwargs): def stringify_keys(dictionary): if dictionary is None: return None - return {str(key): value for key, value in dictionary.iteritems()} + return {str(key): value for key, value in dictionary.items()} def exclude(key_values, *exclude_keys): if key_values is None: return None - return {key: value for key, value in key_values.iteritems() + return {key: value for key, value in key_values.items() if key not in exclude_keys} diff --git a/trove/configuration/models.py b/trove/configuration/models.py index 3d6c081e53..dd4f6662e1 100644 --- a/trove/configuration/models.py +++ b/trove/configuration/models.py @@ -93,7 +93,7 @@ class Configuration(object): LOG.debug("Saving configuration values for %s - " "values: %s" % (cfg_id, values)) config_items = [] - for key, val in values.iteritems(): + for key, val in values.items(): config_item = DBConfigurationParameter.create( configuration_id=cfg_id, configuration_key=key, diff --git a/trove/configuration/service.py b/trove/configuration/service.py index ada0be97f4..b26086ca12 100644 --- a/trove/configuration/service.py +++ b/trove/configuration/service.py @@ -114,7 +114,7 @@ class ConfigurationsController(wsgi.Controller): models.DatastoreConfigurationParameters.load_parameters( datastore_version.id)) - for k, v in values.iteritems(): + for k, v in values.items(): configItems.append(DBConfigurationParameter( configuration_key=k, configuration_value=v)) @@ -219,7 +219,7 @@ class ConfigurationsController(wsgi.Controller): ds_version, models.DatastoreConfigurationParameters.load_parameters( ds_version.id)) - for k, v in configuration['values'].iteritems(): + for k, v in configuration['values'].items(): items.append(DBConfigurationParameter( configuration_id=group.id, configuration_key=k, @@ -244,7 +244,7 @@ class ConfigurationsController(wsgi.Controller): "datastore: %(name)s %(version)s") % output raise exception.UnprocessableEntity(message=msg) - for k, v in values.iteritems(): + for k, v in values.items(): key = k.lower() # parameter name validation if key not in rules_lookup: diff --git a/trove/db/models.py b/trove/db/models.py index 5a94fc1527..6b8e0475e6 100644 --- a/trove/db/models.py +++ b/trove/db/models.py @@ -88,7 +88,7 @@ class DatabaseModelBase(models.ModelBase): def merge_attributes(self, values): """dict.update() behaviour.""" - for k, v in values.iteritems(): + for k, v in values.items(): self[k] = v @classmethod diff --git a/trove/db/sqlalchemy/api.py b/trove/db/sqlalchemy/api.py index 4653f9ae20..b5aa3be9cb 100644 --- a/trove/db/sqlalchemy/api.py +++ b/trove/db/sqlalchemy/api.py @@ -73,7 +73,7 @@ def delete_all(query_func, model, **conditions): def update(model, **values): - for k, v in values.iteritems(): + for k, v in values.items(): model[k] = v diff --git a/trove/guestagent/common/guestagent_utils.py b/trove/guestagent/common/guestagent_utils.py index ddfb9425b5..be4dc76d3c 100644 --- a/trove/guestagent/common/guestagent_utils.py +++ b/trove/guestagent/common/guestagent_utils.py @@ -38,7 +38,7 @@ def update_dict(updates, target): return target if updates is not None: - for k, v in updates.iteritems(): + for k, v in updates.items(): if isinstance(v, collections.Mapping): target[k] = update_dict(v, target.get(k, {})) else: diff --git a/trove/guestagent/datastore/mysql_common/service.py b/trove/guestagent/datastore/mysql_common/service.py index 90a83ee26c..7dcc1716d6 100644 --- a/trove/guestagent/datastore/mysql_common/service.py +++ b/trove/guestagent/datastore/mysql_common/service.py @@ -802,7 +802,7 @@ class BaseMySqlApp(object): LOG.debug("Applying overrides to MySQL.") with self.local_sql_client(self.get_engine()) as client: LOG.debug("Updating override values in running MySQL.") - for k, v in overrides.iteritems(): + for k, v in overrides.items(): byte_value = guestagent_utils.to_bytes(v) q = sql_query.SetServerVariable(key=k, value=byte_value) t = text(str(q)) diff --git a/trove/guestagent/dbaas.py b/trove/guestagent/dbaas.py index fcaa6540c9..4486db0f6a 100644 --- a/trove/guestagent/dbaas.py +++ b/trove/guestagent/dbaas.py @@ -67,8 +67,8 @@ def get_custom_managers(): def datastore_registry(): - return dict(chain(defaults.iteritems(), - get_custom_managers().iteritems())) + return dict(chain(defaults.items(), + get_custom_managers().items())) def to_gb(bytes): diff --git a/trove/tests/api/configurations.py b/trove/tests/api/configurations.py index d9fde12057..fc9d7b4a10 100644 --- a/trove/tests/api/configurations.py +++ b/trove/tests/api/configurations.py @@ -414,7 +414,7 @@ class AfterConfigurationsCreation(ConfigurationsTestBase): with CollectionCheck("configuration_values", result.values) as check: # check each item has the correct type according to the rules - for (item_key, item_val) in result.values.iteritems(): + for (item_key, item_val) in result.values.items(): print("item_key: %s" % item_key) print("item_val: %s" % item_val) dbaas = instance_info.dbaas diff --git a/trove/tests/fakes/keystone.py b/trove/tests/fakes/keystone.py index e7db8480d1..29b2416e79 100644 --- a/trove/tests/fakes/keystone.py +++ b/trove/tests/fakes/keystone.py @@ -37,7 +37,7 @@ class AuthProtocol(object): def _add_headers(self, env, headers): """Add http headers to environment.""" - for (k, v) in headers.iteritems(): + for (k, v) in headers.items(): env_key = self._header_to_env_var(k) env[env_key] = v diff --git a/trove/tests/fakes/swift.py b/trove/tests/fakes/swift.py index 4dcf209ee3..d1af8cd94b 100644 --- a/trove/tests/fakes/swift.py +++ b/trove/tests/fakes/swift.py @@ -102,7 +102,7 @@ class FakeSwiftConnection(object): {'container': container, 'name': name}) checksum = md5() if self.manifest_prefix and self.manifest_name == name: - for object_name in sorted(self.container_objects.iterkeys()): + for object_name in sorted(self.container_objects): object_checksum = md5(self.container_objects[object_name]) # The manifest file etag for a HEAD or GET is the checksum of # the concatenated checksums. diff --git a/trove/tests/util/usage.py b/trove/tests/util/usage.py index 7d4b801469..5217606eac 100644 --- a/trove/tests/util/usage.py +++ b/trove/tests/util/usage.py @@ -47,7 +47,7 @@ class UsageVerifier(object): "No message type %s for resource %s" % (event_type, resource_id)) with asserts.Check() as check: - for key, value in attrs.iteritems(): + for key, value in attrs.items(): check.equal(found[key], value) def get_messages(self, resource_id, expected_messages=None):