Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Drop six string types
  • Loading branch information
cognifloyd committed Dec 4, 2019
commit 11d05aab3f0ce0d1a4f12fce7edda8a744a1164c
8 changes: 4 additions & 4 deletions connexion/apis/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ def get_connexion_response(cls, response, mimetype=None):
if isinstance(response, ConnexionResponse):
# If body in ConnexionResponse is not byte, it may not pass schema validation.
# In this case, rebuild response with aiohttp to have consistency
if response.body is None or isinstance(response.body, six.binary_type):
if response.body is None or isinstance(response.body, bytes):
return response
else:
response = cls._build_response(
Expand Down Expand Up @@ -395,10 +395,10 @@ def _prepare_body_and_status_code(cls, data, mimetype, status_code=None):

@classmethod
def _jsonify_data(cls, data, mimetype):
if not isinstance(data, six.binary_type):
if isinstance(mimetype, six.string_types) and is_json_mimetype(mimetype):
if not isinstance(data, bytes):
if isinstance(mimetype, str) and is_json_mimetype(mimetype):
body = cls.jsonifier.dumps(data)
elif isinstance(data, six.text_type):
elif isinstance(data, str):
body = data
else:
body = str(data)
Expand Down
4 changes: 2 additions & 2 deletions connexion/apis/flask_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ def _build_response(cls, mimetype, content_type=None, headers=None, status_code=
@classmethod
def _jsonify_data(cls, data, mimetype):
# TODO: to discuss: Using jsonifier for all type of data, even when mimetype is not json is strange. Why ?
if (isinstance(mimetype, six.string_types) and is_json_mimetype(mimetype)) \
or not (isinstance(data, six.binary_type) or isinstance(data, six.text_type)):
if (isinstance(mimetype, str) and is_json_mimetype(mimetype)) \
or not (isinstance(data, bytes) or isinstance(data, str)):
return cls.jsonifier.dumps(data)

return data
Expand Down
4 changes: 2 additions & 2 deletions connexion/jsonifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ def loads(self, data):
""" Central point where JSON deserialization happens inside
Connexion.
"""
if isinstance(data, six.binary_type):
if isinstance(data, bytes):
data = data.decode()

try:
return self.json.loads(data)
except Exception:
if isinstance(data, six.string_types):
if isinstance(data, str):
return data