1- # coding: utf-8
2-
31"""
42 Fiscal document service API
53
1210""" # noqa: E501
1311
1412
13+
1514import datetime
1615from dateutil .parser import parse
1716from enum import Enum
2120import os
2221import re
2322import tempfile
23+ import uuid
2424
2525from urllib .parse import quote
2626from typing import Tuple , Optional , List , Dict , Union
@@ -90,7 +90,7 @@ def __init__(
9090 self .default_headers [header_name ] = header_value
9191 self .cookie = cookie
9292 # Set default User-Agent.
93- self .user_agent = 'OpenAPI-Generator/1.20 .0/python'
93+ self .user_agent = 'OpenAPI-Generator/1.21 .0/python'
9494 self .client_side_validation = configuration .client_side_validation
9595
9696 def __enter__ (self ):
@@ -311,7 +311,7 @@ def response_deserialize(
311311 return_data = self .__deserialize_file (response_data )
312312 elif response_type is not None :
313313 match = None
314- content_type = response_data .getheader ('content-type' )
314+ content_type = response_data .headers . get ('content-type' )
315315 if content_type is not None :
316316 match = re .search (r"charset=([a-zA-Z\-\d]+)[\s;]?" , content_type )
317317 encoding = match .group (1 ) if match else "utf-8"
@@ -328,7 +328,7 @@ def response_deserialize(
328328 return ApiResponse (
329329 status_code = response_data .status ,
330330 data = return_data ,
331- headers = response_data .getheaders () ,
331+ headers = response_data .headers ,
332332 raw_data = response_data .data
333333 )
334334
@@ -356,6 +356,8 @@ def sanitize_for_serialization(self, obj):
356356 return obj .get_secret_value ()
357357 elif isinstance (obj , self .PRIMITIVE_TYPES ):
358358 return obj
359+ elif isinstance (obj , uuid .UUID ):
360+ return str (obj )
359361 elif isinstance (obj , list ):
360362 return [
361363 self .sanitize_for_serialization (sub_obj ) for sub_obj in obj
@@ -382,6 +384,10 @@ def sanitize_for_serialization(self, obj):
382384 else :
383385 obj_dict = obj .__dict__
384386
387+ if isinstance (obj_dict , list ):
388+ # here we handle instances that can either be a list or something else, and only became a real list by calling to_dict()
389+ return self .sanitize_for_serialization (obj_dict )
390+
385391 return {
386392 key : self .sanitize_for_serialization (val )
387393 for key , val in obj_dict .items ()
@@ -404,7 +410,7 @@ def deserialize(self, response_text: str, response_type: str, content_type: Opti
404410 data = json .loads (response_text )
405411 except ValueError :
406412 data = response_text
407- elif re .match (r'^application/(json|[\w!#$&.+-^_]+\+json)\s*(;|$)' , content_type , re .IGNORECASE ):
413+ elif re .match (r'^application/(json|[\w!#$&.+\ -^_]+\+json)\s*(;|$)' , content_type , re .IGNORECASE ):
408414 if response_text == "" :
409415 data = ""
410416 else :
@@ -453,13 +459,13 @@ def __deserialize(self, data, klass):
453459
454460 if klass in self .PRIMITIVE_TYPES :
455461 return self .__deserialize_primitive (data , klass )
456- elif klass == object :
462+ elif klass is object :
457463 return self .__deserialize_object (data )
458- elif klass == datetime .date :
464+ elif klass is datetime .date :
459465 return self .__deserialize_date (data )
460- elif klass == datetime .datetime :
466+ elif klass is datetime .datetime :
461467 return self .__deserialize_datetime (data )
462- elif klass == decimal .Decimal :
468+ elif klass is decimal .Decimal :
463469 return decimal .Decimal (data )
464470 elif issubclass (klass , Enum ):
465471 return self .__deserialize_enum (data , klass )
@@ -694,14 +700,16 @@ def __deserialize_file(self, response):
694700 os .close (fd )
695701 os .remove (path )
696702
697- content_disposition = response .getheader ("Content-Disposition" )
703+ content_disposition = response .headers . get ("Content-Disposition" )
698704 if content_disposition :
699705 m = re .search (
700706 r'filename=[\'"]?([^\'"\s]+)[\'"]?' ,
701707 content_disposition
702708 )
703709 assert m is not None , "Unexpected 'content-disposition' header value"
704- filename = m .group (1 )
710+ filename = os .path .basename (m .group (1 )) # Strip any directory traversal
711+ if filename in ("" , "." , ".." ): # fall back to tmp filename
712+ filename = os .path .basename (path )
705713 path = os .path .join (os .path .dirname (path ), filename )
706714
707715 with open (path , "wb" ) as f :
0 commit comments