Skip to content

Reading history file fails with non-latin chars on Windows - #6

Merged
brgirgis merged 5 commits into
pyreadline3:masterfrom
ankostis:redisplay2
Sep 11, 2024
Merged

brgirgis merged 5 commits into
pyreadline3:masterfrom
ankostis:redisplay2

Conversation

@ankostis

Copy link
Copy Markdown
Contributor

A band-aid PR that fixes pyreadline/pyreadline#49 and pyreadline/pyreadline/#55 on non-latin commands in history-file.

@eabase

eabase commented Jan 26, 2022 •

Copy link
Copy Markdown
Contributor

oh, this one look tricky! I know @brgirgis already did some fixes in just about these same places.

@ankostis
Can you explain what the encoding=pyreadline_codepage, errors='replace' parts does? (And why they are needed?)
I've been preaching to just consistently use utf-8, so what is pyreadline_codepage doing? I think we need to be careful with trying to outsmart what our Python, OS and terminals use for code pages. From the Windows side of things, there have been amazing improvements in this handling, since pyreadline was last updated...

@ankostis

ankostis commented Jan 26, 2022 •

Copy link
Copy Markdown
Contributor Author

The _pyreadline_codepage is the fallback encoding "constant" set to utf-8 as you said - it's just there not to duplicate references to the string "utf-8" in the code, and open opportunities for discrepancies,
to signify the developer that this should be the same encoding used throughout all these places.

The "replace" error handling is a safety measure not to crash in case of invalid utf-8 sequences.

@ankostis

Copy link
Copy Markdown
Contributor Author

I've also had written the above this in the docstring of the "private" constant.

Comment thread readline.py Resolved
Comment thread pyreadline3/unicode_helper.py Resolved
@eabase

eabase commented Jan 26, 2022 •

Copy link
Copy Markdown
Contributor

@ankostis
Ok, I see what you're doing. Generally a good idea. However, here I am a bit ambivalent as it make it less clear when looking at the code, what the character-set actually is. At this point I am not sure what is better. I'm usually for code clarity/transparency, but if someone (god forbid) need to change the default character-set to something different than UTF-8 then it would be good. However, i think that is a fringe case at this point, and leaning toward clarity (and in favor of Windows handling terminal code page translation correctly.)

@ankostis

Copy link
Copy Markdown
Contributor Author

I didn't chang the fall-back logic - simply changed it from ASCI -> UTF-8. I believe you agree ion that.

Additionally replaced read/write history-files, from binary --> text when opening them, in a context-manager.
It would be nice to review the codebase and apply the same fix & enslavement to all cases where files are read.

Finally, i introduced an intermediate fall-back variable, used when opening textual files.
I agree with you, that was a mistake.
Better leave default encodins when reading writing textual files.

I will push a fix commit able the last point.

ankostis added a commit to ankostis/pyreadline3 that referenced this pull request Jan 28, 2022
without explicetely forcing any encoding,
as discussed at pyreadline3#6 (comment)
@ankostis

ankostis commented Jan 28, 2022 •

Copy link
Copy Markdown
Contributor Author

Done.
And blindly applied the same (default encoding) for al str.conversion utility functions.

You still have to aprove me, for the CI workflow to kick in.
image

+ Use io.open() to pass `encoding='utf-8'` when opening history-file.
+ Use `with ...` resource management not to leak file-handles.
+ The errors was: UnicodeDecodeError: 'charmap' codec can't decode byte
  0x8f in position 1818: character maps to <undefined>

- In PR: brgirgis/pyreadline3#1
- Old PR: pyreadline/pyreadline3#51
- FIX: pyreadline/pyreadline#55
- Overcome encoding errors when reading/writing textual streams.
- Stop writting bin-streams but rely on `io.open()` for converting encodings.
  Probably a simplicfication to apply elsewhere in code.

- In PR: brgirgis/pyreadline3#1
- Old PR: pyreadline/pyreadline3#51
- enh: pyreadline/pyreadline#55
ankostis added a commit to ankostis/pyreadline3 that referenced this pull request Jan 28, 2022
Introduced a new `_pyreadline_fallback_codepage` constant,
probably should reuse throughout code instead of 'ascii' sttring.

UNVALIDATED if this change breaks stuff in edge cases!!

- In PR: brgirgis/pyreadline3#1
- Old PR: pyreadline/pyreadline3#51
- FIX: pyreadline/pyreadline#55
ankostis added a commit to ankostis/pyreadline3 that referenced this pull request Jan 28, 2022
without explicetely forcing any encoding,
as discussed at pyreadline3#6 (comment)
ankostis added a commit to ankostis/pyreadline3 that referenced this pull request Jan 28, 2022
@eabase

eabase commented Jan 28, 2022

Copy link
Copy Markdown
Contributor

@ankostis You still didn't fix the typo I first reported above.

@ankostis

Copy link
Copy Markdown
Contributor Author

I'm cluless to where your report is? Did i react to it? ... have no recollection of it.

@eabase

eabase commented Jan 30, 2022 •

Copy link
Copy Markdown
Contributor

@ankostis
At the top of this page in my review of line 12. 😄

You coded:
_pyreadline_fallback_codepage = 'urf-8'

but should be:
_pyreadline_fallback_codepage = 'utf-8'

@ankostis

Copy link
Copy Markdown
Contributor Author

I can't see anything at line 12.
Could it be at a rewritten commit, and hence lost?

@eabase

eabase commented Jan 30, 2022 •

Copy link
Copy Markdown
Contributor

@ankostis
Ok, I see the problem. It's wicked that my reviews can only be seen by myself!
Check your typo here:

Introduced a new `_pyreadline_fallback_codepage` constant,
probably should reuse throughout code instead of 'ascii' sttring.

UNVALIDATED if this change breaks stuff in edge cases!!

- In PR: brgirgis/pyreadline3#1
- Old PR: pyreadline/pyreadline3#51
- FIX: pyreadline/pyreadline#55

rebase  UTF
without explicetely forcing any encoding,
as discussed at pyreadline3#6 (comment)
@ankostis

Copy link
Copy Markdown
Contributor Author

Thank you, fixed it.
Bad that no tests captured this (but it's hard to enable the fallback encoding).

Regarding your review-comment, the comments accumulate until you submit the review, you're sure you had clicked this?

@ankostis

Copy link
Copy Markdown
Contributor Author

Again its needs your workflow-approval; could it be that i'm rewriting commits, instead of appending?

@eabase

eabase commented Jan 31, 2022 •

Copy link
Copy Markdown
Contributor

@ankostis
Yeah, I never used the review before and there is nothing for me to click here.

I believe the "maintainer" of this repo @brgirgis could involve himself a little bit more... or at least consider giving us some more rights do do what's necessary to help maintain it.

I see you force pushed, which is normally not a good idea as it messes up the git for everyone else.

In addition Bassem should probably create a dev branch for these things, so that things can get merged and tested more easily without breaking stuff. Otherwise I have to clone also your fork...

@eabase

eabase commented Feb 2, 2022

Copy link
Copy Markdown
Contributor

@brgirgis
Please accept my review, so they can be visible to everyone.
Can you also give us some feedback on the PR's?

@brgirgis
brgirgis requested a review from a team February 2, 2022 23:39
@brgirgis

Copy link
Copy Markdown
Contributor

Please add a couple of test cases to cover this change.

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.

AttributeError: module 'readline' has no attribute 'redisplay'

3 participants