@@ -69,7 +69,7 @@ class ApiClient(object):
6969 to the API
7070 """
7171
72- PRIMITIVE_TYPES = (float , bool , bytes , six .text_type ) + six .integer_types
72+ PRIMITIVE_TYPES = (float , bool , bytes , bytearray , six .text_type ) + six .integer_types
7373 NATIVE_TYPES_MAPPING = {
7474 "int" : int ,
7575 "long" : int if six .PY3 else long , # noqa: F821
@@ -207,7 +207,7 @@ def __call_api(
207207 if _return_http_data_only :
208208 return return_data
209209 else :
210- return ( return_data , response_data .status , response_data .getheaders () )
210+ return return_data , response_data .status , response_data .getheaders ()
211211
212212 def sanitize_for_serialization (self , obj ):
213213 """Builds a JSON POST object.
@@ -285,7 +285,7 @@ def __deserialize(self, data, klass):
285285
286286 if type (klass ) == str :
287287 if klass .startswith ("list[" ):
288- sub_kls = re .match (r"list\[(.*)\ ]" , klass ).group (1 )
288+ sub_kls = re .match (r"list\[(.*)]" , klass ).group (1 )
289289 return [self .__deserialize (sub_data , sub_kls ) for sub_data in data ]
290290
291291 if klass .startswith ("dict(" ):
@@ -338,13 +338,13 @@ def call_api(
338338 :param header_params: Header parameters to be
339339 placed in the request header.
340340 :param body: Request body.
341- :param post_params dict: Request post form parameters,
341+ :param post_params: dict: Request post form parameters,
342342 for 'application/x-www-form-urlencoded', 'multipart/form-data'.
343- :param auth_settings list: Auth Settings names for the request .
344- :param response: Response data type .
345- :param files dict: key -> filename, value -> filepath,
343+ :param response_type: Response data type .
344+ :param auth_settings: list: Auth Settings names for the request .
345+ :param files: dict: key -> filename, value -> filepath,
346346 for 'multipart/form-data'.
347- :param async_req bool: execute request asynchronously
347+ :param async_req: bool: execute request asynchronously
348348 :param _return_http_data_only: response data without head status code
349349 and headers
350350 :param collection_formats: dict of collection formats for path, query,
@@ -511,24 +511,21 @@ def parameters_to_tuples(self, params, collection_formats):
511511 new_params .append ((k , v ))
512512 return new_params
513513
514- def is_not_ascii (self , string ):
515- return any (ord (c ) >= 128 for c in string )
516-
517514 def prepare_one_file (self , file_data ):
518515 # type: (Union[bytes, str, file, pathlib.Path, io.BytesIO]) -> FileFieldData # noqa: F821
519516
520- # Python 2 has no difference between Bytes and Str
521- # So decide non-ascii string is Bytes
522- if isinstance (file_data , bytes ) and (not six .PY2 or self .is_not_ascii (file_data )):
523- return FileFieldData ("data.bin" , file_data , "application/octet-stream" )
524-
525517 if isinstance (file_data , str ) or (not six .PY2 and isinstance (file_data , pathlib .PurePath )):
526518 with open (file_data , "rb" ) as f :
527519 fname = os .path .basename (f .name )
528520 file_bytes = f .read ()
529521 mime_type = mimetypes .guess_type (fname )[0 ] or "application/octet-stream"
530522 return FileFieldData (fname , file_bytes , mime_type )
531523
524+ # Python 2 has no difference between bytes and str
525+ # Use bytearray in Python 2 to make a difference with str
526+ if isinstance (file_data , bytes ) or isinstance (file_data , bytearray ):
527+ return FileFieldData ("data.bin" , file_data , "application/octet-stream" )
528+
532529 if isinstance (file_data , io .BytesIO ):
533530 return FileFieldData ("data.bin" , file_data .read (), "application/octet-stream" )
534531
@@ -687,8 +684,8 @@ def __deserialize_datetime(self, string):
687684 except ValueError :
688685 raise ApiException (reason = ("Failed to parse '{0}' as datetime object" .format (string )))
689686
690- def __hasattr (self , object , name ):
691- return name in object .__class__ .__dict__
687+ def __hasattr (self , obj , name ):
688+ return name in obj .__class__ .__dict__
692689
693690 def __deserialize_model (self , data , klass ):
694691 """Deserializes list or dict to model.
0 commit comments