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

implements more safe print function #298

Merged
merged 2 commits into from Feb 13, 2019

Conversation

Projects
None yet
3 participants
@DZamataev
Copy link
Contributor

DZamataev commented Feb 1, 2019

which wont cause exceptions on windows like the following:

File "elodie.py", line 66, in import_file
print('%s -> %s' % (_file, dest_path))
File "C:\Python27\lib\encodings\cp866.py", line 12, in encode
return codecs.charmap_encode(input,errors,encoding_map)
UnicodeEncodeError: 'charmap' codec can't encode character u'\xe8' in position 97: character maps to <undefined>
implements more safe print function which wont cause exceptions on wi…
…ndows like the following:

File "elodie.py", line 66, in import_file
print('%s -> %s' % (_file, dest_path))
File "C:\Python27\lib\encodings\cp866.py", line 12, in encode
return codecs.charmap_encode(input,errors,encoding_map)
UnicodeEncodeError: 'charmap' codec can't encode character u'\xe8' in position 97: character maps to <undefined>
@coveralls

This comment has been minimized.

Copy link

coveralls commented Feb 1, 2019

Coverage Status

Coverage remained the same at 91.768% when pulling 7e0a4b8 on DZamataev:feature/safe-print into 086c26c on jmathai:master.

@coveralls

This comment has been minimized.

Copy link

coveralls commented Feb 1, 2019

Coverage Status

Coverage decreased (-1.6%) to 90.185% when pulling 6a21bc9 on DZamataev:feature/safe-print into 086c26c on jmathai:master.

@DZamataev

This comment has been minimized.

Copy link
Contributor Author

DZamataev commented Feb 1, 2019

So basically on windows some characters won't show in a PowerShell console properly and cause encoding exceptions. More here: https://stackoverflow.com/a/32176732
I had to wrap the elodie in a while $true { <run> } to continue running after accidentally facing bad file in my library, before I ended up fixing this issue.
Maybe if you want tests use this example string from SO

This is an Е乂αmp١ȅ testing Unicode support using Arabic, Latin, Cyrillic, Greek, Hebrew and CJK code points.

@jmathai

This comment has been minimized.

Copy link
Owner

jmathai commented Feb 1, 2019

Can we somehow move this logic over into the log module and probably expose a log.print() function which calls log._print()?

https://github.com/jmathai/elodie/blob/master/elodie/log.py#L44

moves safe print implementation to log submodule.
changes direct print calls to log.all calls which stangs for log level ALL. Seems legit after log.info which only outputs with --debug. So log.ALL outputs all the times as the direct print call, but safer.
@DZamataev

This comment has been minimized.

Copy link
Contributor Author

DZamataev commented Feb 1, 2019

Yea, I've moved it. More details in commit message.

@jmathai jmathai merged commit 283611a into jmathai:master Feb 13, 2019

4 checks passed

Scrutinizer Analysis: 4 new issues, 2 updated code elements – Tests: passed
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
coverage/coveralls Coverage decreased (-1.6%) to 90.185%
Details
license/cla Contributor License Agreement is signed.
Details
@jmathai

This comment has been minimized.

Copy link
Owner

jmathai commented Feb 13, 2019

Thanks @DZamataev

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment