[Python] Binary mode for file deserialization #6936
Merged
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.
PR checklist
./bin/
to update Petstore sample so that CIs can verify the change. (For instance, only need to run./bin/{LANG}-petstore.sh
and./bin/security/{LANG}-petstore.sh
if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in.\bin\windows\
.3.0.0
branch for changes related to OpenAPI spec 3.0. Default:master
.Description of the PR
PR created on @wing328 suggestion on #2305
This changes the file deserialization function to open the destination file in byte mode "wb" instead of text mode "w".
Using "w" mode can corrupt binary file because it replaces the bytes that represents new lines in text to make it platform specific.
See https://docs.python.org/2/tutorial/inputoutput.html
and https://docs.python.org/3/tutorial/inputoutput.html
Being a generic file deserialization that needs to handle both formats I guess it's more appropriate to leave the file exactly as it is.
Notes:
My changes were limited to what is described above, the rest of the changes were generated when running security/python-petstore.sh. Made 2 separate commits to make it easier to revert if the auto generate-part of security/python-petstore.sh is not correct or it has to be reverted.
@taxpon @frol @mbohlool @cbornet @kenjones-cisco