Skip to content

make TextIOBase writable, handle malformed utf-8 in read() #1119

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

Merged
merged 3 commits into from
Jul 9, 2019

Conversation

silmeth
Copy link
Contributor

@silmeth silmeth commented Jul 8, 2019

This:

  • adds UnicodeError and subtypes,
  • makes TextIOWrapper throw a UnicodeDecodeError on malformed utf-8 in a file,
  • makes TextIOWrapper writable if underlying buffer is writable,
  • makes TextIOWrapper not readable if underlying buffer is writable.

When the wrapper is not readable/writable, CPython throws an io.UnsupportedOperation which inherits from both OSError and ValueError. I just throw ValueError here – do we have multiple inheritance yet to do a proper UnsupportedOperation?

Also, all the UnicodeError types in CPython have more internal structure than the simple exceptions I added here.

Some more things to be done to close the rest of #547 are:

  • implement closing files, buffers, text wrappers,
  • perhaps make file a separate PyObjectPayload to hide the underlying Rust File internally and no longer depend on fileno?,
  • make fileno just an accessor method.

But I’d rather try to do them in separate pull requests (or let somebody else do them if anyone gets to it before me).

@windelbouwman windelbouwman merged commit e5d0a02 into RustPython:master Jul 9, 2019
@silmeth silmeth deleted the text_file_io branch July 9, 2019 09:57
@silmeth silmeth mentioned this pull request Jul 9, 2019
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.

3 participants