From 5552739893036faeab10c8ae1c4561ea03011e54 Mon Sep 17 00:00:00 2001 From: David Read Date: Fri, 8 Nov 2019 21:08:16 +0000 Subject: [PATCH] 'map' usage made python3 compatible Used automated tool: python-modernize --fix=map . As suggested: https://github.com/ckan/ckan/pull/5062#issuecomment-551903816 And did a little manual tidying. --- ckan/controllers/api.py | 3 ++- ckan/include/rjsmin.py | 1 + ckan/lib/dictization/model_save.py | 3 ++- ckan/lib/helpers.py | 6 +++--- ckan/lib/search/index.py | 1 + ckan/model/license.py | 4 +++- ckan/tests/legacy/functional/test_package.py | 2 +- ckanext/datastore/backend/postgres.py | 2 +- ckanext/example_idatastorebackend/example_sqlite.py | 5 +++-- 9 files changed, 17 insertions(+), 10 deletions(-) diff --git a/ckan/controllers/api.py b/ckan/controllers/api.py index 22be5c687d9..a2b5d0834c7 100644 --- a/ckan/controllers/api.py +++ b/ckan/controllers/api.py @@ -19,6 +19,7 @@ from ckan.views import identify_user from ckan.common import _, c, request, response +from six.moves import map log = logging.getLogger(__name__) @@ -287,7 +288,7 @@ def convert_to_dict(user): return out query = query.limit(limit) - out = map(convert_to_dict, query.all()) + out = list(map(convert_to_dict, query.all())) return out @jsonp.jsonpify diff --git a/ckan/include/rjsmin.py b/ckan/include/rjsmin.py index 13e66e0e421..b88f3b4356c 100644 --- a/ckan/include/rjsmin.py +++ b/ckan/include/rjsmin.py @@ -62,6 +62,7 @@ __all__ = ['jsmin'] import re as _re +from six.moves import map def _make_jsmin(python_only=False): diff --git a/ckan/lib/dictization/model_save.py b/ckan/lib/dictization/model_save.py index f306ca6517d..58030a48f11 100644 --- a/ckan/lib/dictization/model_save.py +++ b/ckan/lib/dictization/model_save.py @@ -6,6 +6,7 @@ from sqlalchemy.orm import class_mapper from six import string_types +from six.moves import map import ckan.lib.dictization as d import ckan.lib.helpers as h @@ -419,7 +420,7 @@ def group_dict_save(group_dict, context, prevent_packages_update=False): package_ids.extend( pkgs_edited['added'] ) if package_ids: session.commit() - map( rebuild, package_ids ) + list(map(rebuild, package_ids)) return group diff --git a/ckan/lib/helpers.py b/ckan/lib/helpers.py index 94ad7144a47..a27b640a514 100644 --- a/ckan/lib/helpers.py +++ b/ckan/lib/helpers.py @@ -37,6 +37,7 @@ from six.moves.urllib.parse import ( urlencode, quote, unquote, urlparse, urlunparse ) +from six.moves import map import jinja2 import ckan.exceptions @@ -186,8 +187,7 @@ def redirect_to(*args, **kw): kw['__no_cache__'] = True # Routes router doesn't like unicode args - uargs = map(lambda arg: str(arg) if isinstance(arg, text_type) else arg, - args) + uargs = [str(arg) if isinstance(arg, text_type) else arg for arg in args] _url = '' skip_url_parsing = False @@ -1512,7 +1512,7 @@ def date_str_to_datetime(date_str): microseconds = int(m.groupdict(0).get('microseconds')) time_tuple = time_tuple[:5] + [seconds, microseconds] - return datetime.datetime(*map(int, time_tuple)) + return datetime.datetime(*list(map(int, time_tuple))) @core_helper diff --git a/ckan/lib/search/index.py b/ckan/lib/search/index.py index 1370e5acec9..486487c1df5 100644 --- a/ckan/lib/search/index.py +++ b/ckan/lib/search/index.py @@ -14,6 +14,7 @@ from ckan.common import config from ckan.common import asbool from six import text_type +from six.moves import map from common import SearchIndexError, make_connection from ckan.model import PackageRelationship diff --git a/ckan/model/license.py b/ckan/model/license.py index f70394c0c84..efecc02578b 100644 --- a/ckan/model/license.py +++ b/ckan/model/license.py @@ -8,6 +8,7 @@ from ckan.common import config from ckan.common import asbool from six import text_type, string_types +from six.moves import map from ckan.common import _, json import ckan.lib.maintain as maintain @@ -33,7 +34,8 @@ def __init__(self, data): for (key, value) in self._data.items(): if key == 'date_created': # Parse ISO formatted datetime. - value = datetime.datetime(*map(int, re.split('[^\d]', value))) + value = datetime.datetime( + *list(map(int, re.split('[^\d]', value)))) self._data[key] = value elif isinstance(value, str): # Convert str to unicode (keeps Pylons and SQLAlchemy happy). diff --git a/ckan/tests/legacy/functional/test_package.py b/ckan/tests/legacy/functional/test_package.py index 473e7637a69..faf638cb31a 100644 --- a/ckan/tests/legacy/functional/test_package.py +++ b/ckan/tests/legacy/functional/test_package.py @@ -127,7 +127,7 @@ def check_form_filled_correctly(self, res, **params): self.check_tag_and_data(main_res, prefix+'notes', params['notes']) self.check_tag_and_data(main_res, 'selected', params['license_id']) if isinstance(params['tags'], (str, unicode)): - tags = map(lambda s: s.strip(), params['tags'].split(',')) + tags = [s.strip() for s in params['tags'].split(',')] else: tags = params['tags'] for tag in tags: diff --git a/ckanext/datastore/backend/postgres.py b/ckanext/datastore/backend/postgres.py index d8601e7da5a..82966dc33a4 100644 --- a/ckanext/datastore/backend/postgres.py +++ b/ckanext/datastore/backend/postgres.py @@ -820,7 +820,7 @@ def create_indexes(context, data_dict): name=_generate_index_name(data_dict['resource_id'], fields_string), fields=fields_string)) - sql_index_strings = map(lambda x: x.replace('%', '%%'), sql_index_strings) + sql_index_strings = [x.replace('%', '%%') for x in sql_index_strings] current_indexes = _get_index_names(context['connection'], data_dict['resource_id']) for sql_index_string in sql_index_strings: diff --git a/ckanext/example_idatastorebackend/example_sqlite.py b/ckanext/example_idatastorebackend/example_sqlite.py index 985818c27b9..17f35d70fb4 100644 --- a/ckanext/example_idatastorebackend/example_sqlite.py +++ b/ckanext/example_idatastorebackend/example_sqlite.py @@ -2,6 +2,7 @@ import logging from sqlalchemy import create_engine +from six.moves import map from ckanext.datastore.backend import DatastoreBackend @@ -40,7 +41,7 @@ def configure(self, config): def create(self, context, data_dict): columns = str(u', '.join( - map(lambda e: e['id'] + u' text', data_dict['fields']))) + [e['id'] + u' text' for e in data_dict['fields']])) engine = self._get_engine() engine.execute( u' CREATE TABLE IF NOT EXISTS "{name}"({columns});'.format( @@ -67,7 +68,7 @@ def search(self, context, data_dict): data_dict.get(u'limit', 10) )) - data_dict['records'] = map(dict, result.fetchall()) + data_dict['records'] = list(map(dict, result.fetchall())) data_dict['total'] = len(data_dict['records']) fields_info = []