Skip to content

Commit

Permalink
[#4801] Replace usage of iteritems() with six.iteritems()
Browse files Browse the repository at this point in the history
  • Loading branch information
amercader committed Nov 27, 2019
1 parent 19bf78c commit e352357
Show file tree
Hide file tree
Showing 33 changed files with 89 additions and 64 deletions.
5 changes: 3 additions & 2 deletions ckan/authz.py
Expand Up @@ -2,11 +2,12 @@

import functools
import sys
import re

from collections import defaultdict
from logging import getLogger

import six

from ckan.common import config
from ckan.common import asbool

Expand Down Expand Up @@ -101,7 +102,7 @@ def _build(self):
resolved_auth_function_plugins[name] = plugin.name
fetched_auth_functions[name] = auth_function

for name, func_list in chained_auth_functions.iteritems():
for name, func_list in six.iteritems(chained_auth_functions):
if (name not in fetched_auth_functions and
name not in self._functions):
raise Exception('The auth %r is not found for chained auth' % (
Expand Down
3 changes: 2 additions & 1 deletion ckan/cli/translation.py
Expand Up @@ -6,6 +6,7 @@
import os

import click
import six

from ckan.cli import error_shout
from ckan.common import config
Expand Down Expand Up @@ -145,7 +146,7 @@ def check_po_file(path):
for function in (
simple_conv_specs, mapping_keys, replacement_fields
):
for key, msgstr in entry.msgstr_plural.iteritems():
for key, msgstr in six.iteritems(entry.msgstr_plural):
if key == u'0':
error = check_translation(
function, entry.msgid, entry.msgstr_plural[key]
Expand Down
2 changes: 1 addition & 1 deletion ckan/config/middleware/__init__.py
Expand Up @@ -105,7 +105,7 @@ def ask_around(self, environ):
'''
answers = [
app._wsgi_app.can_handle_request(environ)
for name, app in self.apps.iteritems()
for name, app in six.iteritems(self.apps)
]
# Sort answers by app name
answers = sorted(answers, key=lambda x: x[1])
Expand Down
6 changes: 3 additions & 3 deletions ckan/config/middleware/flask_app.py
Expand Up @@ -12,6 +12,7 @@
from flask.ctx import _AppCtxGlobals
from flask.sessions import SessionInterface

import six
from werkzeug.exceptions import default_exceptions, HTTPException
from werkzeug.routing import Rule

Expand All @@ -23,7 +24,6 @@
from repoze.who.config import WhoConfig
from repoze.who.middleware import PluggableAuthenticationMiddleware

import ckan
import ckan.model as model
from ckan.lib import base
from ckan.lib import helpers
Expand Down Expand Up @@ -130,7 +130,7 @@ def save_session(self, app, session, response):

namespace = 'beaker.session.'
session_opts = {k.replace('beaker.', ''): v
for k, v in config.iteritems()
for k, v in six.iteritems(config)
if k.startswith(namespace)}
if (not session_opts.get('session.data_dir') and
session_opts.get('session.type', 'file') == 'file'):
Expand Down Expand Up @@ -417,7 +417,7 @@ def register_extension_blueprint(self, blueprint, **kwargs):

# Get the new blueprint rules
bp_rules = itertools.chain.from_iterable(
v for k, v in self.url_map._rules_by_endpoint.iteritems()
v for k, v in six.iteritems(self.url_map._rules_by_endpoint)
if k.startswith(u'{0}.'.format(blueprint.name))
)

Expand Down
3 changes: 2 additions & 1 deletion ckan/controllers/package.py
@@ -1,6 +1,7 @@
# encoding: utf-8

import logging
import six
from six.moves.urllib.parse import urlencode
import datetime
import mimetypes
Expand Down Expand Up @@ -648,7 +649,7 @@ def new_resource(self, id, data=None, errors=None, error_summary=None):

# see if we have any data that we are trying to save
data_provided = False
for key, value in data.iteritems():
for key, value in six.iteritems(data):
if ((value or isinstance(value, cgi.FieldStorage))
and key != 'resource_type'):
data_provided = True
Expand Down
4 changes: 3 additions & 1 deletion ckan/i18n/check_po_files.py
Expand Up @@ -11,6 +11,8 @@
import re
import paste.script.command

import six


def simple_conv_specs(s):
'''Return the simple Python string conversion specifiers in the string s.
Expand Down Expand Up @@ -79,7 +81,7 @@ def check_translation(validator, msgid, msgstr):
if entry.msgid_plural and entry.msgstr_plural:
for function in (simple_conv_specs, mapping_keys,
replacement_fields):
for key, msgstr in entry.msgstr_plural.iteritems():
for key, msgstr in six.iteritems(entry.msgstr_plural):
if key == '0':
check_translation(function, entry.msgid,
entry.msgstr_plural[key])
Expand Down
2 changes: 1 addition & 1 deletion ckan/lib/base.py
Expand Up @@ -217,7 +217,7 @@ def set_pylons_response_headers(allow_cache):
allow_cache = False
# Don't cache if we have extra vars containing data.
elif extra_vars:
for k, v in extra_vars.iteritems():
for k, v in six.iteritems(extra_vars):
allow_cache = False
break

Expand Down
5 changes: 3 additions & 2 deletions ckan/lib/dictization/__init__.py
Expand Up @@ -3,8 +3,9 @@
import datetime
from sqlalchemy.orm import class_mapper
import sqlalchemy

import six
from six import text_type
from ckan.common import config
from ckan.model.core import State

try:
Expand Down Expand Up @@ -146,7 +147,7 @@ def table_dict_save(table_dict, ModelClass, context):
if not obj:
obj = ModelClass()

for key, value in table_dict.iteritems():
for key, value in six.iteritems(table_dict):
if isinstance(value, list):
continue
setattr(obj, key, value)
Expand Down
4 changes: 2 additions & 2 deletions ckan/lib/dictization/model_dictize.py
Expand Up @@ -11,8 +11,8 @@
which builds the dictionary by iterating over the table columns.
'''
import datetime

import six
from six.moves.urllib.parse import urlsplit

from ckan.common import config
Expand Down Expand Up @@ -76,7 +76,7 @@ def resource_list_dictize(res_list, context):

def extras_dict_dictize(extras_dict, context):
result_list = []
for name, extra in extras_dict.iteritems():
for name, extra in six.iteritems(extras_dict):
dictized = d.table_dictize(extra, context)
if not extra.state == 'active':
continue
Expand Down
13 changes: 6 additions & 7 deletions ckan/lib/dictization/model_save.py
Expand Up @@ -5,11 +5,10 @@
import logging

from sqlalchemy.orm import class_mapper
import six
from six import string_types
from six.moves import map

import ckan.lib.dictization as d
import ckan.lib.helpers as h
import ckan.authz as authz

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -40,7 +39,7 @@ def resource_dict_save(res_dict, context):
# Resource extras not submitted will be removed from the existing extras
# dict
new_extras = {}
for key, value in res_dict.iteritems():
for key, value in six.iteritems(res_dict):
if isinstance(value, list):
continue
if key in ('extras', 'revision_timestamp', 'tracking_summary'):
Expand Down Expand Up @@ -451,7 +450,7 @@ def package_api_to_dict(api1_dict, context):

dictized = {}

for key, value in api1_dict.iteritems():
for key, value in six.iteritems(api1_dict):
new_value = value
if key == 'tags':
if isinstance(value, string_types):
Expand All @@ -466,7 +465,7 @@ def package_api_to_dict(api1_dict, context):

new_value = []

for extras_key, extras_value in updated_extras.iteritems():
for extras_key, extras_value in six.iteritems(updated_extras):
new_value.append({"key": extras_key,
"value": extras_value})

Expand All @@ -490,7 +489,7 @@ def group_api_to_dict(api1_dict, context):

dictized = {}

for key, value in api1_dict.iteritems():
for key, value in six.iteritems(api1_dict):
new_value = value
if key == 'packages':
new_value = [{"id": item} for item in value]
Expand Down Expand Up @@ -601,7 +600,7 @@ def resource_view_dict_save(data_dict, context):
if resource_view:
data_dict['id'] = resource_view.id
config = {}
for key, value in data_dict.iteritems():
for key, value in six.iteritems(data_dict):
if key not in model.ResourceView.get_columns():
config[key] = value
data_dict['config'] = config
Expand Down
2 changes: 1 addition & 1 deletion ckan/lib/helpers.py
Expand Up @@ -944,7 +944,7 @@ def build_extra_admin_nav():
admin_tabs_dict = config.get('ckan.admin_tabs')
output = ''
if admin_tabs_dict:
for k, v in admin_tabs_dict.iteritems():
for k, v in six.iteritems(admin_tabs_dict):
if v['icon']:
output += build_nav_icon(k, v['label'], icon=v['icon'])
else:
Expand Down
4 changes: 2 additions & 2 deletions ckan/lib/i18n.py
Expand Up @@ -380,7 +380,7 @@ def build_js_translations():
# the POT files for that, since they contain all translation entries
# (even those for which no translation exists, yet).
js_entries = set()
for i18n_dir, domain in i18n_dirs.iteritems():
for i18n_dir, domain in six.iteritems(i18n_dirs):
pot_file = os.path.join(i18n_dir, domain + u'.pot')
if os.path.isfile(pot_file):
js_entries.update(_get_js_translation_entries(pot_file))
Expand All @@ -395,7 +395,7 @@ def build_js_translations():
u'LC_MESSAGES',
domain + u'.po'
)
for i18n_dir, domain in i18n_dirs.iteritems()
for i18n_dir, domain in six.iteritems(i18n_dirs)
) if os.path.isfile(fn)
]
if not po_files:
Expand Down
1 change: 1 addition & 0 deletions ckan/lib/lazyjson.py
@@ -1,6 +1,7 @@
# encoding: utf-8

from simplejson import loads, RawJSON, dumps
import six
from six import text_type


Expand Down
7 changes: 4 additions & 3 deletions ckan/lib/navl/dictization_functions.py
Expand Up @@ -3,6 +3,7 @@
import copy
import json

import six
from six import text_type
from ckan.common import config, _

Expand Down Expand Up @@ -105,7 +106,7 @@ def flatten_schema(schema, flattened=None, key=None):
flattened = flattened or {}
old_key = key or []

for key, value in schema.iteritems():
for key, value in six.iteritems(schema):
new_key = old_key + [key]
if isinstance(value, dict):
flattened = flatten_schema(value, flattened, new_key)
Expand Down Expand Up @@ -152,7 +153,7 @@ def make_full_schema(data, schema):
for key in combination[::2]:
sub_schema = sub_schema[key]

for key, value in sub_schema.iteritems():
for key, value in six.iteritems(sub_schema):
if isinstance(value, list):
full_schema[combination + (key,)] = value

Expand Down Expand Up @@ -378,7 +379,7 @@ def flatten_dict(data, flattened=None, old_key=None):
flattened = flattened or {}
old_key = old_key or []

for key, value in data.iteritems():
for key, value in six.iteritems(data):
new_key = old_key + [key]
if isinstance(value, list) and value and isinstance(value[0], dict):
flattened = flatten_list(value, flattened, new_key)
Expand Down
3 changes: 2 additions & 1 deletion ckan/lib/navl/validators.py
@@ -1,5 +1,6 @@
# encoding: utf-8

import six
from six import text_type

import ckan.lib.navl.dictization_functions as df
Expand All @@ -17,7 +18,7 @@ def identity_converter(key, data, errors, context):
def keep_extras(key, data, errors, context):

extras = data.pop(key, {})
for extras_key, value in extras.iteritems():
for extras_key, value in six.iteritems(extras):
data[key[:-1] + (extras_key,)] = value

def not_missing(key, data, errors, context):
Expand Down
2 changes: 1 addition & 1 deletion ckan/lib/search/index.py
Expand Up @@ -221,7 +221,7 @@ def index_package(self, pkg_dict, defer_commit=False):
for rel in subjects:
type = rel['type']
rel_dict[type].append(model.Package.get(rel['object_package_id']).name)
for key, value in rel_dict.iteritems():
for key, value in six.iteritems(rel_dict):
if key not in pkg_dict:
pkg_dict[key] = value

Expand Down
9 changes: 5 additions & 4 deletions ckan/logic/__init__.py
Expand Up @@ -6,6 +6,7 @@
from collections import defaultdict

from werkzeug.local import LocalProxy
import six
from six import string_types, text_type

import ckan.model as model
Expand Down Expand Up @@ -93,7 +94,7 @@ def prettify(field_name):

summary = {}

for key, error in error_dict.iteritems():
for key, error in six.iteritems(error_dict):
if key == 'resources':
summary[_('Resources')] = _('Package resource(s) invalid')
elif key == 'extras':
Expand Down Expand Up @@ -194,7 +195,7 @@ def tuplize_dict(data_dict):
May raise a DataError if the format of the key is incorrect.
'''
tuplized_dict = {}
for key, value in data_dict.iteritems():
for key, value in six.iteritems(data_dict):
key_list = key.split('__')
for num, key in enumerate(key_list):
if num % 2 == 1:
Expand All @@ -209,7 +210,7 @@ def tuplize_dict(data_dict):
def untuplize_dict(tuplized_dict):

data_dict = {}
for key, value in tuplized_dict.iteritems():
for key, value in six.iteritems(tuplized_dict):
new_key = '__'.join([str(item) for item in key])
data_dict[new_key] = value
return data_dict
Expand Down Expand Up @@ -428,7 +429,7 @@ def get_action(action):
# This needs to be resolved later
action_function.auth_audit_exempt = True
fetched_actions[name] = action_function
for name, func_list in chained_actions.iteritems():
for name, func_list in six.iteritems(chained_actions):
if name not in fetched_actions and name not in _actions:
# nothing to override from plugins or core
raise NotFound('The action %r is not found for chained action' % (
Expand Down
4 changes: 3 additions & 1 deletion ckan/logic/action/__init__.py
Expand Up @@ -3,6 +3,8 @@
from copy import deepcopy
import re

import six

from ckan.logic import NotFound
from ckan.common import _

Expand Down Expand Up @@ -55,7 +57,7 @@ def prettify(field_name):
return _(field_name.replace('_', ' '))

summary = {}
for key, error in error_dict.iteritems():
for key, error in six.iteritems(error_dict):
if key == 'resources':
summary[_('Resources')] = _('Package resource(s) invalid')
elif key == 'extras':
Expand Down

0 comments on commit e352357

Please sign in to comment.