Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Conversation

@radarhere
Copy link
Member

Alternative to #4192

That PR changes ContainerIO to return bytes instead of strings.
This PR changes ContainerIO to return strings if the file object is a string object, and bytes if the file object is a bytestring object.

break
s = s + c
if c == b"\n":
if c in [b"\n", "\n"]:
Copy link
Contributor

Choose a reason for hiding this comment

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

This line results in a BytesWarning when running with the Python -b argument:

Tests/test_file_tar.py::TestFileTar::test_sanity
.../Pillow/.tox/py38/lib/python3.8/site-packages/PIL/ContainerIO.py:101: BytesWarning: Comparison between bytes and string
    if c in [b"\n", "\n"]:

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks. I've updated the commit.

@jdufresne
Copy link
Contributor

Overall, the approach makes sense. Do you have a use case in mind where the file would be opened in text mode?

@radarhere
Copy link
Member Author

No. Feel free to argue that bytes mode is correct. I'm just thinking about backwards compatibility.

break
s = s + c
if c == "\n":
if c == (b"\n" if "b" in self.fh.mode else "\n"):
Copy link
Contributor

Choose a reason for hiding this comment

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

This could be pulled out of the loop so it doesn't need to be recalculated every iteration of the loop.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea. I've pushed a commit for this.

jdufresne and others added 3 commits February 15, 2020 22:13
Image data is expected to be read in bytes mode, not text mode so
ContainerIO should return bytes in all methods. The passed in file
handler is expected to be opened in bytes mode (as TarIO already does).
@hugovk hugovk merged commit cc3c743 into python-pillow:master Feb 15, 2020
@radarhere radarhere deleted the container branch February 15, 2020 12:30
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

Morty Proxy This is a proxified and sanitized view of the page, visit original site.