Skip to content

fix broken support to py2.7 #256 - #257

Open
ccancellieri wants to merge 2 commits into
ckan:masterfrom
ccancellieri:fix-encoding-with-py2.7
Open

fix broken support to py2.7 #256#257
ccancellieri wants to merge 2 commits into
ckan:masterfrom
ccancellieri:fix-encoding-with-py2.7

Conversation

@ccancellieri

Copy link
Copy Markdown
Contributor

This may fix #256

@ccancellieri ccancellieri changed the title fix encoding problem on py2.7 #256 fix broken support to py2.7 #256 Oct 25, 2021

log = logging.getLogger(__name__)

# Py2 vs Py3 encoding

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you use six for the python version checking? eg

import six

if six.PY3:
    # ...
else:
    # ...

or even

_encoding = 'utf-8' if six.PY3 else str

But looking at the documentation it looks like the most portable solution would be to pass
record["xml"] = etree.tostring(mdtree, pretty_print=True, encoding='utf-8') regardless of the Python version. Does this work as expected on Python 2.7 (and 3)?


Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It was 'unicode' and have been change into 'str' by:
e063522#diff-db75a495bf76416216c3b4fe8cc1038bc53d22a19cb0990cbd823b17c2d67364R104

Now I can't be sure about py3 (don't have a working environment) but you could be right.
To avoid causing problem I proposed encoding='utf-8' for py2 and 'as it is' (futurized) for py3.

Can someone confirm about py3?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It seems ok to me.
There are tests now, so such change could be made, and we see how the CI tests go :)

@amercader

Copy link
Copy Markdown
Member

@ccancellieri The aim is to support Python 2 for versions of CKAN <= 2.9, and the tests are run against these versions (see eg https://github.com/ckan/ckanext-spatial/actions/runs/1394064993). If there is a Python 2 failure it means that test coverage is lacking there and something slipped through the cracks.

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.

Broken compatibility with py2.7

3 participants