From 386c9c7c55147b27c258edd5deee36594553493d Mon Sep 17 00:00:00 2001 From: Berker Peksag Date: Mon, 26 May 2014 19:50:38 +0300 Subject: [PATCH] Use six.iteritems() instead of dict.iteritems(). --- mediagoblin/db/models.py | 6 ++++-- mediagoblin/gmg_commands/__init__.py | 4 +++- mediagoblin/init/celery/__init__.py | 6 ++++-- mediagoblin/mg_globals.py | 3 ++- mediagoblin/moderation/tools.py | 7 +++++-- mediagoblin/plugins/ldap/tools.py | 4 +++- mediagoblin/plugins/piwigo/tools.py | 2 +- mediagoblin/storage/__init__.py | 4 +++- mediagoblin/storage/mountstorage.py | 4 +++- mediagoblin/tests/test_sql_migrations.py | 4 +++- mediagoblin/tests/tools.py | 5 +++-- mediagoblin/tools/exif.py | 6 ++++-- mediagoblin/tools/response.py | 3 ++- mediagoblin/tools/staticdirect.py | 4 +++- 14 files changed, 43 insertions(+), 19 deletions(-) diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py index 79389002..1fecbaaa 100644 --- a/mediagoblin/db/models.py +++ b/mediagoblin/db/models.py @@ -40,6 +40,8 @@ from mediagoblin.db.mixin import UserMixin, MediaEntryMixin, \ from mediagoblin.tools.files import delete_media_files from mediagoblin.tools.common import import_component +import six + # It's actually kind of annoying how sqlalchemy-migrate does this, if # I understand it right, but whatever. Anyway, don't remove this :P # @@ -319,7 +321,7 @@ class MediaEntry(Base, MediaEntryMixin): file_metadata = media_file.file_metadata or {} - for key, value in kwargs.iteritems(): + for key, value in six.iteritems(kwargs): file_metadata[key] = value media_file.file_metadata = file_metadata @@ -344,7 +346,7 @@ class MediaEntry(Base, MediaEntryMixin): media_data.get_media_entry = self else: # Update old media data - for field, value in kwargs.iteritems(): + for field, value in six.iteritems(kwargs): setattr(media_data, field, value) @memoized_property diff --git a/mediagoblin/gmg_commands/__init__.py b/mediagoblin/gmg_commands/__init__.py index 9de4130e..e0400897 100644 --- a/mediagoblin/gmg_commands/__init__.py +++ b/mediagoblin/gmg_commands/__init__.py @@ -17,6 +17,8 @@ import argparse import os +import six + from mediagoblin.tools.common import import_component @@ -90,7 +92,7 @@ def main_cli(): "otherwise mediagoblin.ini")) subparsers = parser.add_subparsers(help='sub-command help') - for command_name, command_struct in SUBCOMMAND_MAP.iteritems(): + for command_name, command_struct in six.iteritems(SUBCOMMAND_MAP): if 'help' in command_struct: subparser = subparsers.add_parser( command_name, help=command_struct['help']) diff --git a/mediagoblin/init/celery/__init__.py b/mediagoblin/init/celery/__init__.py index 57242bf6..ffc7ca0e 100644 --- a/mediagoblin/init/celery/__init__.py +++ b/mediagoblin/init/celery/__init__.py @@ -18,6 +18,8 @@ import os import sys import logging +import six + from celery import Celery from mediagoblin.tools.pluginapi import hook_runall @@ -45,7 +47,7 @@ def get_celery_settings_dict(app_config, global_config, celery_settings = {} # Add all celery settings from config - for key, value in celery_conf.iteritems(): + for key, value in six.iteritems(celery_conf): celery_settings[key] = value # TODO: use default result stuff here if it exists @@ -98,7 +100,7 @@ def setup_celery_from_config(app_config, global_config, __import__(settings_module) this_module = sys.modules[settings_module] - for key, value in celery_settings.iteritems(): + for key, value in six.iteritems(celery_settings): setattr(this_module, key, value) if set_environ: diff --git a/mediagoblin/mg_globals.py b/mediagoblin/mg_globals.py index 26ed66fa..7da31680 100644 --- a/mediagoblin/mg_globals.py +++ b/mediagoblin/mg_globals.py @@ -21,6 +21,7 @@ import gettext import pkg_resources import threading +import six ############################# # General mediagoblin globals @@ -64,7 +65,7 @@ def setup_globals(**kwargs): """ from mediagoblin import mg_globals - for key, value in kwargs.iteritems(): + for key, value in six.iteritems(kwargs): if not hasattr(mg_globals, key): raise AssertionError("Global %s not known" % key) setattr(mg_globals, key, value) diff --git a/mediagoblin/moderation/tools.py b/mediagoblin/moderation/tools.py index e0337536..edee42ef 100644 --- a/mediagoblin/moderation/tools.py +++ b/mediagoblin/moderation/tools.py @@ -14,6 +14,8 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . +import six + from mediagoblin import mg_globals from mediagoblin.db.models import User, Privilege, UserBan from mediagoblin.db.base import Session @@ -22,8 +24,9 @@ from mediagoblin.tools.response import redirect from datetime import datetime from mediagoblin.tools.translate import lazy_pass_to_ugettext as _ + def take_punitive_actions(request, form, report, user): - message_body ='' + message_body = '' # The bulk of this action is running through all of the different # punitive actions that a moderator could take. @@ -212,6 +215,6 @@ def parse_report_panel_settings(form): filters['reporter_id'] = form.reporter.data filters = dict((k, v) - for k, v in filters.iteritems() if v) + for k, v in six.iteritems(filters) if v) return filters diff --git a/mediagoblin/plugins/ldap/tools.py b/mediagoblin/plugins/ldap/tools.py index 1c436792..2be2dcd7 100644 --- a/mediagoblin/plugins/ldap/tools.py +++ b/mediagoblin/plugins/ldap/tools.py @@ -16,6 +16,8 @@ import ldap import logging +import six + from mediagoblin.tools import pluginapi _log = logging.getLogger(__name__) @@ -47,7 +49,7 @@ class LDAP(object): return email def login(self, username, password): - for k, v in self.ldap_settings.iteritems(): + for k, v in six.iteritems(self.ldap_settings): try: self._connect(v) user_dn = v['LDAP_USER_DN_TEMPLATE'].format(username=username) diff --git a/mediagoblin/plugins/piwigo/tools.py b/mediagoblin/plugins/piwigo/tools.py index 484ea531..7b9b7af3 100644 --- a/mediagoblin/plugins/piwigo/tools.py +++ b/mediagoblin/plugins/piwigo/tools.py @@ -47,7 +47,7 @@ class PwgNamedArray(list): def _fill_element_dict(el, data, as_attr=()): - for k, v in data.iteritems(): + for k, v in six.iteritems(data): if k in as_attr: if not isinstance(v, six.string_types): v = str(v) diff --git a/mediagoblin/storage/__init__.py b/mediagoblin/storage/__init__.py index 3aa1f4a4..12109748 100644 --- a/mediagoblin/storage/__init__.py +++ b/mediagoblin/storage/__init__.py @@ -19,6 +19,8 @@ from __future__ import absolute_import import shutil import uuid +import six + from werkzeug.utils import secure_filename from mediagoblin.tools import common @@ -259,7 +261,7 @@ def storage_system_from_config(config_section): """ # This construct is needed, because dict(config) does # not replace the variables in the config items. - config_params = dict(config_section.iteritems()) + config_params = dict(six.iteritems(config_section)) if 'storage_class' in config_params: storage_class = config_params['storage_class'] diff --git a/mediagoblin/storage/mountstorage.py b/mediagoblin/storage/mountstorage.py index dffc619b..4125a88d 100644 --- a/mediagoblin/storage/mountstorage.py +++ b/mediagoblin/storage/mountstorage.py @@ -14,6 +14,8 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . +import six + from mediagoblin.storage import StorageInterface, clean_listy_filepath @@ -120,7 +122,7 @@ class MountStorage(StorageInterface): v = table.get(None) if v: res.append(" " * len(indent) + repr(indent) + ": " + repr(v)) - for k, v in table.iteritems(): + for k, v in six.iteritems(table): if k == None: continue res.append(" " * len(indent) + repr(k) + ":") diff --git a/mediagoblin/tests/test_sql_migrations.py b/mediagoblin/tests/test_sql_migrations.py index 3d67fdf6..e86dcd80 100644 --- a/mediagoblin/tests/test_sql_migrations.py +++ b/mediagoblin/tests/test_sql_migrations.py @@ -16,6 +16,8 @@ import copy +import six + from sqlalchemy import ( Table, Column, MetaData, Index, Integer, Float, Unicode, UnicodeText, DateTime, Boolean, @@ -190,7 +192,7 @@ def level_exits_new_table(db_conn): for level in result: - for exit_name, to_level in level['exits'].iteritems(): + for exit_name, to_level in six.iteritems(level['exits']): # Insert the level exit db_conn.execute( level_exits.insert().values( diff --git a/mediagoblin/tests/tools.py b/mediagoblin/tests/tools.py index 060dfda9..b8e06e19 100644 --- a/mediagoblin/tests/tools.py +++ b/mediagoblin/tests/tools.py @@ -19,6 +19,7 @@ import os import pkg_resources import shutil +import six from paste.deploy import loadapp from webtest import TestApp @@ -142,7 +143,7 @@ def install_fixtures_simple(db, fixtures): """ Very simply install fixtures in the database """ - for collection_name, collection_fixtures in fixtures.iteritems(): + for collection_name, collection_fixtures in six.iteritems(fixtures): collection = db[collection_name] for fixture in collection_fixtures: collection.insert(fixture) @@ -162,7 +163,7 @@ def assert_db_meets_expected(db, expected): {'id': 'foo', 'some_field': 'some_value'},]} """ - for collection_name, collection_data in expected.iteritems(): + for collection_name, collection_data in six.iteritems(expected): collection = db[collection_name] for expected_document in collection_data: document = collection.query.filter_by(id=expected_document['id']).first() diff --git a/mediagoblin/tools/exif.py b/mediagoblin/tools/exif.py index 50f1aabf..736bae7d 100644 --- a/mediagoblin/tools/exif.py +++ b/mediagoblin/tools/exif.py @@ -14,6 +14,8 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . +import six + from exifread import process_file from exifread.utils import Ratio @@ -94,7 +96,7 @@ def clean_exif(exif): 'Thumbnail JPEGInterchangeFormat'] return dict((key, _ifd_tag_to_dict(value)) for (key, value) - in exif.iteritems() if key not in disabled_tags) + in six.iteritems(exif) if key not in disabled_tags) def _ifd_tag_to_dict(tag): @@ -149,7 +151,7 @@ def get_gps_data(tags): 'latitude': tags['GPS GPSLatitude'], 'longitude': tags['GPS GPSLongitude']} - for key, dat in dms_data.iteritems(): + for key, dat in six.iteritems(dms_data): gps_data[key] = ( lambda v: float(v[0].num) / float(v[0].den) \ diff --git a/mediagoblin/tools/response.py b/mediagoblin/tools/response.py index cd99a230..1380633f 100644 --- a/mediagoblin/tools/response.py +++ b/mediagoblin/tools/response.py @@ -16,6 +16,7 @@ import json +import six import werkzeug.utils from werkzeug.wrappers import Response as wz_Response from mediagoblin.tools.template import render_template @@ -152,7 +153,7 @@ def json_response(serializable, _disable_cors=False, *args, **kw): 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Methods': 'POST, GET, OPTIONS', 'Access-Control-Allow-Headers': 'Content-Type, X-Requested-With'} - for key, value in cors_headers.iteritems(): + for key, value in six.iteritems(cors_headers): response.headers.set(key, value) return response diff --git a/mediagoblin/tools/staticdirect.py b/mediagoblin/tools/staticdirect.py index 8381b8b6..881dd20e 100644 --- a/mediagoblin/tools/staticdirect.py +++ b/mediagoblin/tools/staticdirect.py @@ -24,6 +24,8 @@ import logging +import six + _log = logging.getLogger(__name__) @@ -48,7 +50,7 @@ class StaticDirect(object): def __init__(self, domains): self.domains = dict( [(key, value.rstrip('/')) - for key, value in domains.iteritems()]) + for key, value in six.iteritems(domains)]) self.cache = {} def __call__(self, filepath, domain=None): -- 2.25.1