Skip to content
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

[Python] Binary mode for file deserialization #6936

Conversation

g-bon
Copy link
Contributor

@g-bon g-bon commented Nov 12, 2017

PR checklist

  • Read the contribution guidelines.
  • Ran the shell script under ./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\.
  • Filed the PR against the correct branch: 3.0.0 branch for changes related to OpenAPI spec 3.0. Default: master.
  • Copied the technical committee to review the pull request if your PR is targeting a particular programming langauge.

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

@kenjones-cisco
Copy link
Contributor

LGTM!

Thanks for the contribution @g-bon

@wing328 wing328 merged commit 62444a7 into swagger-api:master Nov 13, 2017
@wing328
Copy link
Contributor

wing328 commented Nov 13, 2017

@g-bon thanks for the fix.

@kenjones-cisco thanks for reviewing the change.

@wing328 wing328 added this to the v2.3.0 milestone Nov 13, 2017
@wing328 wing328 changed the title Binary mode for file deserialization in python [Python] Binary mode for file deserialization Nov 13, 2017
@g-bon
Copy link
Contributor Author

g-bon commented Nov 13, 2017

Thanks to you for reviewing the change.

@g-bon g-bon deleted the binary-mode-for-file-deserialization-in-python branch November 13, 2017 08:22
jimschubert added a commit to jimschubert/swagger-codegen that referenced this pull request Nov 14, 2017
* master: (101 commits)
  [Swift4] Allow for custom dateformatter to be used (swagger-api#6672)
  [haskell-http-client] fix bug when generating models-only (swagger-api#6931)
  fix typo: crediential => credential
  minor typo fix
  [csharp] fix enum serialization of first value (swagger-api#6873)
  [PHP] Improve docs and README (swagger-api#6935)
  Binary mode for file deserialization in python (swagger-api#6936)
  add python tornado test to travis
  [Python/tornado] add integration tests and fix bugs (swagger-api#6925)
  Fix PHP passes response body to ApiException (swagger-api#6923)
  [TypeScript][Node] Resolve TS2532 error (swagger-api#6932)
  skip "all" shell script
  minor formatting change
  Fixes Issue swagger-api#6841, Map for accessing additionalProperties is generated. (swagger-api#6886)
  add tsloughter as owner erlang
  WIP: initial commit for Erlang client generator (swagger-api#6502)
  add back php client test
  Switch Travis image from MacOS to Linux (swagger-api#6937)
  add link to ebook
  [Scala] Default case class Option types to None for non-required fields (swagger-api#6790)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants