Skip to content

Commit

Permalink
fix long issue in python3
Browse files Browse the repository at this point in the history
  • Loading branch information
wing328 committed Jul 7, 2016
1 parent 41e8273 commit 89befeb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ except ImportError:
# for python2
from urllib import quote

# special handling of `long` (python2 only)
try:
# Python 2
long
except NameError:
# Python 3
long = int

from .configuration import Configuration


Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ This Python package is automatically generated by the [Swagger Codegen](https://

- API version: 1.0.0
- Package version: 1.0.0
- Build date: 2016-07-06T16:27:27.842+08:00
- Build date: 2016-07-07T22:03:52.761+08:00
- Build package: class io.swagger.codegen.languages.PythonClientCodegen

## Requirements.
Expand Down
18 changes: 13 additions & 5 deletions samples/client/petstore/python/petstore_api/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@
# for python2
from urllib import quote

# special handling of `long` (python2 only)
try:
# Python 2
long
except NameError:
# Python 3
long = int

from .configuration import Configuration


Expand Down Expand Up @@ -183,7 +191,7 @@ def sanitize_for_serialization(self, obj):
Builds a JSON POST object.
If obj is None, return None.
If obj is str, int, float, bool, return directly.
If obj is str, int, long, float, bool, return directly.
If obj is datetime.datetime, datetime.date
convert to string in iso8601 format.
If obj is list, sanitize each element in the list.
Expand All @@ -193,7 +201,7 @@ def sanitize_for_serialization(self, obj):
:param obj: The data to serialize.
:return: The serialized form of data.
"""
types = (str, int, float, bool, tuple)
types = (str, int, long, float, bool, tuple)
if sys.version_info < (3, 0):
types = types + (unicode,)
if isinstance(obj, type(None)):
Expand Down Expand Up @@ -269,14 +277,14 @@ def __deserialize(self, data, klass):

# convert str to class
# for native types
if klass in ['int', 'float', 'str', 'bool',
if klass in ['int', 'long', 'float', 'str', 'bool',
"date", 'datetime', "object"]:
klass = eval(klass)
# for model types
else:
klass = eval('models.' + klass)

if klass in [int, float, str, bool]:
if klass in [int, long, float, str, bool]:
return self.__deserialize_primitive(data, klass)
elif klass == object:
return self.__deserialize_object(data)
Expand Down Expand Up @@ -505,7 +513,7 @@ def __deserialize_primitive(self, data, klass):
:param data: str.
:param klass: class literal.
:return: int, float, str, bool.
:return: int, long, float, str, bool.
"""
try:
value = klass(data)
Expand Down

0 comments on commit 89befeb

Please sign in to comment.