Skip to content

Commit

Permalink
'map' usage made python3 compatible
Browse files Browse the repository at this point in the history
Used automated tool:

    python-modernize --fix=map .

As suggested: #5062 (comment)
And did a little manual tidying.
  • Loading branch information
David Read committed Nov 8, 2019
1 parent 66effbd commit 5552739
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 10 deletions.
3 changes: 2 additions & 1 deletion ckan/controllers/api.py
Expand Up @@ -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__)
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions ckan/include/rjsmin.py
Expand Up @@ -62,6 +62,7 @@
__all__ = ['jsmin']

import re as _re
from six.moves import map


def _make_jsmin(python_only=False):
Expand Down
3 changes: 2 additions & 1 deletion ckan/lib/dictization/model_save.py
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions ckan/lib/helpers.py
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions ckan/lib/search/index.py
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion ckan/model/license.py
Expand Up @@ -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
Expand All @@ -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).
Expand Down
2 changes: 1 addition & 1 deletion ckan/tests/legacy/functional/test_package.py
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion ckanext/datastore/backend/postgres.py
Expand Up @@ -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:
Expand Down
5 changes: 3 additions & 2 deletions ckanext/example_idatastorebackend/example_sqlite.py
Expand Up @@ -2,6 +2,7 @@

import logging
from sqlalchemy import create_engine
from six.moves import map

from ckanext.datastore.backend import DatastoreBackend

Expand Down Expand Up @@ -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(
Expand All @@ -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 = []
Expand Down

0 comments on commit 5552739

Please sign in to comment.