-
-
Notifications
You must be signed in to change notification settings - Fork 16.2k
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
Issue 3358 fix #3419
Closed
Closed
Issue 3358 fix #3419
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
davidism
requested changes
Nov 7, 2019
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.
Needs tests and changelog as well
Will refactor code to avoid repetition, and will check the test cases
…On Thu, Nov 7, 2019 at 2:10 PM David Lord ***@***.***> wrote:
***@***.**** requested changes on this pull request.
Needs tests and changelog as well
------------------------------
In src/flask/helpers.py
<#3419 (comment)>:
> @@ -41,6 +41,10 @@
from .globals import session
from .signals import message_flashed
+if sys.version_info >= (3, 0):
This is already handled in flask._compat
------------------------------
In src/flask/helpers.py
<#3419 (comment)>:
> @@ -630,6 +634,21 @@ def send_file(
mtime = os.path.getmtime(filename)
fsize = os.path.getsize(filename)
headers["Content-Length"] = fsize
+
+ elif isinstance(file,io.StringIO):
+ """
+ Reaches String IO parsing to BytesIO
+ """
+ mem = BytesIO()
+ mem.write(file.getvalue().encode('utf-8'))
+ mem.seek(0)
+ file = mem
Just do file = BytesIO initially
------------------------------
In src/flask/helpers.py
<#3419 (comment)>:
> @@ -630,6 +634,21 @@ def send_file(
mtime = os.path.getmtime(filename)
fsize = os.path.getsize(filename)
headers["Content-Length"] = fsize
+
+ elif isinstance(file,io.StringIO):
+ """
+ Reaches String IO parsing to BytesIO
+ """
+ mem = BytesIO()
+ mem.write(file.getvalue().encode('utf-8'))
+ mem.seek(0)
+ file = mem
+ try:
+ fsize = file.getbuffer().nbytes
Duplicates code below, if/elif/elif needs to be refactored to avoid that.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#3419?email_source=notifications&email_token=AD3TCQBSV7AFDZV6RUBXTUTQSRR2PA5CNFSM4JKL4YS2YY3PNVWWK3TUL52HS4DFWFIHK3DMKJSXC5LFON2FEZLWNFSXPKTDN5WW2ZLOORPWSZGOCKYKLVI#pullrequestreview-313566677>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AD3TCQHH4QPENWAEDB5VBDLQSRR2PANCNFSM4JKL4YSQ>
.
|
Hi David,
the reason I need to do the version check, is because in python2.7 stringio
is imported from StringIO and not from io. I have fixed the repetition. In
my new pull request I did fail one test,
"stylecheck: commands failed"
Could you please assist me on fixing it? Also are there any other changes I
need to make/include?
Best,
Anirudh
On Thu, Nov 7, 2019 at 2:11 PM Anirudh Narayanan <anirudh95@gmail.com>
wrote:
… Will refactor code to avoid repetition, and will check the test cases
On Thu, Nov 7, 2019 at 2:10 PM David Lord ***@***.***>
wrote:
> ***@***.**** requested changes on this pull request.
>
> Needs tests and changelog as well
> ------------------------------
>
> In src/flask/helpers.py
> <#3419 (comment)>:
>
> > @@ -41,6 +41,10 @@
> from .globals import session
> from .signals import message_flashed
>
> +if sys.version_info >= (3, 0):
>
> This is already handled in flask._compat
> ------------------------------
>
> In src/flask/helpers.py
> <#3419 (comment)>:
>
> > @@ -630,6 +634,21 @@ def send_file(
> mtime = os.path.getmtime(filename)
> fsize = os.path.getsize(filename)
> headers["Content-Length"] = fsize
> +
> + elif isinstance(file,io.StringIO):
> + """
> + Reaches String IO parsing to BytesIO
> + """
> + mem = BytesIO()
> + mem.write(file.getvalue().encode('utf-8'))
> + mem.seek(0)
> + file = mem
>
> Just do file = BytesIO initially
> ------------------------------
>
> In src/flask/helpers.py
> <#3419 (comment)>:
>
> > @@ -630,6 +634,21 @@ def send_file(
> mtime = os.path.getmtime(filename)
> fsize = os.path.getsize(filename)
> headers["Content-Length"] = fsize
> +
> + elif isinstance(file,io.StringIO):
> + """
> + Reaches String IO parsing to BytesIO
> + """
> + mem = BytesIO()
> + mem.write(file.getvalue().encode('utf-8'))
> + mem.seek(0)
> + file = mem
> + try:
> + fsize = file.getbuffer().nbytes
>
> Duplicates code below, if/elif/elif needs to be refactored to avoid that.
>
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub
> <#3419?email_source=notifications&email_token=AD3TCQBSV7AFDZV6RUBXTUTQSRR2PA5CNFSM4JKL4YS2YY3PNVWWK3TUL52HS4DFWFIHK3DMKJSXC5LFON2FEZLWNFSXPKTDN5WW2ZLOORPWSZGOCKYKLVI#pullrequestreview-313566677>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AD3TCQHH4QPENWAEDB5VBDLQSRR2PANCNFSM4JKL4YSQ>
> .
>
|
davidism
force-pushed
the
ISSUE_3358_FIX
branch
from
November 19, 2019 05:40
de40e55
to
c84e1da
Compare
Thanks for working on this. After reviewing the issue, I've decided |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
fixes #3358