From db5941379f1b6d55075a7a8d85b63cde3e149eb8 Mon Sep 17 00:00:00 2001 From: Justin Niessner Date: Sun, 26 Apr 2020 16:33:42 -0400 Subject: [PATCH] [Python] Fix Python UTF-8 Encoding Issue (#5679) * Try decoding but don't bail on error * Switch binary and ByteArray to bytes * Read content type and parse appropriately * Remove response parsing * Remove response parsing and just return the data * Update petshop examples w/ new generator code * Fix copy/paste error with naming * Update petstore examples * Move response decoding to inside _preload_content block * Update the clients again * Use a raw string for the regex pattern * Regenerate petstore clients * Add bytes to python primitives as it's supported in 2.7 and 3 * Add bytes to the exports from model_utils * Import bytes from model_utils * Add conditional typing for regex pattern to match variable type * Regenerate petstore clients * Use read() instead of text() for asyncio * Regenerate petstore clients * Remove unused six import * Regenerate petstore clients * Add newline to kick Circle to re-run * Remove whitespace from tox.ini * Update more examples after ensure_updated * Add sample updates that didn't run with the --batch flag * Remove extra bracket in regex to remove warning * Stop printing debug messages * Add bytes examples to python doc generators * Update generated FakeApi docs * Regenerate api_client.py * Remove print statements from generated clients * Update bytes example in FakeApi.md. Again. I swear. * Add yet another seemingly missing doc update * Catch the error, decode the body, and re-throw * Remove the updates now that the change is non-breaking * Regenerate client * Add bytes deserialization test * Update exception parsing * Add exception parsing for python-experimental * Regenerate client with minor changes * Revert test changes * Regenerate model_utils.py * Update confusing test name * Remove bytes from mapping and examples * Add back in the old binary/ByteArray to str mapping * Update docs and api_client template * Add experimental api_client changes * Regenerate samples again * Add Tornado handling to early return * Try fixing Tornado python returns * More documentation changes * Re-generate the client code * Remove bytes from test_format_test * Remove more leftover bytes usages * Switch bytes validation back to string * Fix format_test template and regenerate * Remove unused bytes var * Remove bytes import from models and regenerate * Remove bytes import from test_deserialization * Reduce nested ifs * Remove byte logic for now * Regenerate client after latest changes * Remove another bytes usage * Regenerate after removing dangling byte string usage * Reduce the scope of the try/catch in api_client * Regenerate after try/catch cleanup * Swap catch for except * Regenerate Python client after api_client change * Fix lint error on the generated api_client * Add binary format test back in w/ string * Add decoding to python-experimental and regenerate * Import re into python-experimental api_client * Ensure file upload json response is utf-8 encoded bytes --- docs/generators/python-experimental.md | 1 + docs/generators/python.md | 1 + .../languages/PythonClientCodegen.java | 3 +- .../PythonClientExperimentalCodegen.java | 4 +- .../main/resources/python/api_client.mustache | 47 ++++++++++----- .../resources/python/asyncio/rest.mustache | 2 +- .../python-experimental/api_client.mustache | 57 +++++++++++++------ .../src/main/resources/python/rest.mustache | 5 -- .../resources/python/tornado/rest.mustache | 7 +-- .../python-asyncio/petstore_api/api_client.py | 42 +++++++++----- .../python-asyncio/petstore_api/rest.py | 2 +- .../petstore_api/api_client.py | 52 +++++++++++------ .../python-experimental/petstore_api/rest.py | 5 -- .../test/test_format_test.py | 2 +- .../tests/test_api_exception.py | 1 + .../tests/test_deserialization.py | 30 ++++++++++ .../python-experimental/tests/test_pet_api.py | 2 +- .../python-tornado/petstore_api/api_client.py | 42 +++++++++----- .../python-tornado/petstore_api/rest.py | 7 +-- .../python/petstore_api/api_client.py | 42 +++++++++----- .../petstore/python/petstore_api/rest.py | 5 -- .../petstore/python/test/test_format_test.py | 26 ++++----- .../python/tests/test_api_exception.py | 1 + .../petstore_api/api_client.py | 52 +++++++++++------ .../python-experimental/petstore_api/rest.py | 5 -- .../python/petstore_api/api_client.py | 42 +++++++++----- .../petstore/python/petstore_api/rest.py | 5 -- .../php-slim4/lib/Model/EnumClass.php | 4 +- 28 files changed, 319 insertions(+), 175 deletions(-) diff --git a/docs/generators/python-experimental.md b/docs/generators/python-experimental.md index 8f3b02c7e56..546dcc22542 100644 --- a/docs/generators/python-experimental.md +++ b/docs/generators/python-experimental.md @@ -31,6 +31,7 @@ sidebar_label: python-experimental