-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Py 2to3 #420
Py 2to3 #420
Conversation
ckanext/iati/archiver.py
Outdated
@@ -292,14 +292,14 @@ def archive_package(package_id, context, consecutive_errors=0): | |||
else: | |||
new_extras['data_updated'] = None | |||
|
|||
for key, value in new_extras.iteritems(): | |||
if value and (key not in extras_dict or unicode(value) != unicode(extras_dict.get(key, ''))): | |||
for key, value in list(new_extras.items()): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally, you don't need the list() when iterating over it. 2to3 adds this on .items()
(and keys & values) just to be sure.
ckanext/iati/helpers.py
Outdated
@@ -124,7 +124,7 @@ def get_publisher_obj_extra_fields(group_dict): | |||
} | |||
|
|||
for ex in group_dict.get("extras", []): | |||
if ex.get("key", None) in formatter_map.keys(): | |||
if ex.get("key", None) in list(formatter_map.keys()): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
iteration
ckanext/iati/helpers.py
Outdated
@@ -139,7 +139,7 @@ def get_publisher_obj_extra_fields_pub_ids(group_dict): | |||
'publisher_first_publish_date': render_first_published_date_parse | |||
} | |||
for ex in group_dict: | |||
if ex in formatter_map.keys(): | |||
if ex in list(formatter_map.keys()): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
iteration
ckanext/iati/logic/action.py
Outdated
@@ -75,7 +75,7 @@ def package_create(context, data_dict): | |||
created_package = create_core.package_create(context, data_dict) | |||
|
|||
# Part of first publisher date patch - after package create patch the organization | |||
if 'owner_org' in data_dict.keys(): | |||
if 'owner_org' in list(data_dict.keys()): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if 'owner_org' in list(data_dict.keys()): | |
if 'owner_org' in data_dict: |
ckanext/iati/logic/action.py
Outdated
@@ -280,7 +280,7 @@ def issues_report_csv(context, data_dict): | |||
result = logic.get_action('package_search')(context, data_dict) | |||
if result['count'] > 0: | |||
publishers = result['facets']['organization'] | |||
for publisher_name, count in publishers.iteritems(): | |||
for publisher_name, count in list(publishers.items()): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
iteration
ckanext/iati/views/admin.py
Outdated
@@ -50,7 +50,7 @@ def _active_publisher_data(from_dt, to_dt): | |||
log.info(query) | |||
conn = model.Session.connection() | |||
rows = conn.execute(query) | |||
active_publishers = [{key: value for (key, value) in row.items()} for row in rows] | |||
active_publishers = [{key: value for (key, value) in list(row.items())} for row in rows] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
iterator
@@ -1,5 +1,5 @@ | |||
from flask import Blueprint | |||
from ckan.lib.base import request, response, render, abort | |||
from ckan.lib.base import request, render, abort |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this intended?
ckanext/iati/views/spreadsheet.py
Outdated
iati_keys = dict([(f[2], f[0]) for f in PublisherRecordsUpload.CSV_MAPPING]) | ||
for key, msgs in e.error_dict.iteritems(): | ||
for key, msgs in list(e.error_dict.items()): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
iterator
@@ -1,5 +1,5 @@ | |||
from flask import Blueprint, make_response | |||
from ckan.lib.base import response, render, abort | |||
from ckan.lib.base import render, abort |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check
@@ -1,5 +1,5 @@ | |||
from flask import Blueprint, make_response | |||
from ckan.lib.base import request, response, render, abort | |||
from ckan.lib.base import request, render, abort |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check
with open(saved_file, 'r') as f: | ||
content = f.read() | ||
content = re.sub(r'generated-datetime="[^"]+"', '', content) | ||
with open(saved_file, 'rb') as f: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these were actually equivalent, because opening in text mode assumes UTF-8 character encoding.
But then the hash needs to have binary data, so you could either revert this bit and do the encode on 538, or just do the hash of content_bytes
, so you didn't have to encode again.
@@ -179,7 +180,12 @@ def json(self): | |||
_org_data = PublishersListDownload._get_publisher_data() | |||
for org in _org_data: | |||
if org.Group.state == 'active' and int(org.package_count) > 0: | |||
json_data.append(OrderedDict(list(zip(self._headers, self._prepare(org))))) | |||
ordered_dict = OrderedDict(zip(self._headers, self._prepare(org))) | |||
for key, value in ordered_dict.items(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would make sense to do in the _prepare method, I think.
Actually, I'm really unclear how that can end up as bytes, since it should be an array?
ckanext/iati/views/spreadsheet.py
Outdated
@@ -226,7 +226,8 @@ def csv_upload_datasets(): | |||
vars['file_name'] = csv_file.filename | |||
data = io.BytesIO(_data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a complicated version of:
reader = csv.DictReader(data)
for row in reader:
task={}
task['title'] = row.get('title', '') or "No Title"
task['task_id'] = str(uuid.uuid4())
job = jobs.enqueue(records_upload_process,
[json.dumps([row], ensure_ascii=False).encode('utf-8'), c.user])
task['task_id'] = str(job.id)
tasks.append(json.dumps(task))
Except I really don't understand enqueuing an array of [bytes, object], where the bytes is a json string of an array of a single dict. But I guess that's what's required upstream.
Do we have any test files that are hitting these various encodes/decodes?
No description provided.