Skip to content
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

Merged
merged 10 commits into from
Jan 17, 2024
Merged

Py 2to3 #420

merged 10 commits into from
Jan 17, 2024

Conversation

cormachallinanderilinx
Copy link
Collaborator

No description provided.

@@ -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()):
Copy link
Collaborator

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.

@@ -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()):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iteration

@@ -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()):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iteration

@@ -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()):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if 'owner_org' in list(data_dict.keys()):
if 'owner_org' in data_dict:

@@ -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()):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iteration

@@ -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]
Copy link
Collaborator

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this intended?

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()):
Copy link
Collaborator

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
Copy link
Collaborator

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
Copy link
Collaborator

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:
Copy link
Collaborator

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():
Copy link
Collaborator

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?

@@ -226,7 +226,8 @@ def csv_upload_datasets():
vars['file_name'] = csv_file.filename
data = io.BytesIO(_data)
Copy link
Collaborator

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants