-
-
Notifications
You must be signed in to change notification settings - Fork 381
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
Handle "+", fix file objects and refactor SmartOpenHttpTest #263
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thus it becomes possible to open a regular stream, specify
name
and read/write compressed data.
Can you expand on this? Who would specify name
and why?
Signed-off-by: Vadim Markovtsev <[email protected]>
Signed-off-by: Vadim Markovtsev <[email protected]>
@piskvorky CI passed, review suggestions addressed. Regarding the print(open("smart_open/tests/test_smart_open.py").name) does print the opened file name. I added comments at that line. |
As a nice side effect, this will work: with open("file.gz", "rb") as f:
decompressed_data = smart_open(f).read() or this with smart_open(open("file.gz", "wb"), "w") as f:
f.write("data") |
Thanks a lot! That "side effect" is awesome, love it :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your contribution! Left you some comments. Please have a look.
5e11016
to
d576123
Compare
Signed-off-by: Vadim Markovtsev <[email protected]>
@mpenkov Review applied, the controversial function removed, ready for the next round. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's my next round of comments, mostly questions about the tests.
Signed-off-by: Vadim Markovtsev <[email protected]>
Addressed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, getting there. Please see my next round of comments below.
Signed-off-by: Vadim Markovtsev <[email protected]>
Addressed |
@piskvorky Looks good enough to merge for me, WDYT? |
This PR has been heavily reviewed and is fairly low risk. In the interest of keeping the ball rolling, I'm going to merge it. @piskvorky Please let me know if there are any issues. |
@vmarkovtsev Thanks again for your contribution, keep them coming 👍 |
Signed-off-by: Vadim Markovtsev [email protected]
It all started with the refactoring suggestion in #260 (comment) and went a little bit too far:
read()
disregarding the actual open mode. I added_is_stream()
function and fixed that.name
attribute check to the file objects handler. Thus it becomes possible to open a regular stream, specifyname
and read/write compressed data. This was a prerequisite for the "file-less"SmartOpenHttpTest
-s.Then I started writing the tests and found a few minor bugs:
_compression_wrapper()
. All three compression codecs do not support reading and writing at the same time._encoding_wrapper()
: only the reader's encoder was applied. I changed that to chaining reader's and writer's encoders in rw modes.