
    j@J                    .   d dl mZmZ d dlZd dlZd dlZd dlZd dlmZ d dl	Z	d dl
Z
d dlZd dlZd dlZd dlmZmZmZmZmZmZmZmZmZmZmZmZmZ 	 d dlmZ d dl m!c m"Z# d dl$Z$d dl%m&Z&m'Z' d dl(m)Z* ejV                  jY                  d	      Z- ed
d      Z.ee/ef   Z0 G d d      Z1 e
jd                  e3      Z4	 e5Z6 G d dejr                        Z:	 d dlm;Z< 	 d dlm;Z; e;jz                  Z> ej~                  d      Z@d ZAd ZBd ZCd'dZD G d d      ZEd ZF G d d      ZGd ZHd ZId ZJd  ZKd! ZLd" ZMd# ZNd$ ZO G d% d&      ZPy# e$ r	 d dlmZ Y w xY w# e7$ r e8Z6Y w xY w# e$ r  G d dejr                        Z<Y w xY w# e$ r
  e:       Z>Y w xY w)(    )	b64decode	b64encodeN)Enum)DictAnycastOptionalUnionAnyStrIOMappingCallableTypeVarMutableMappingTypeList)quote)DeserializationErrorSerializationError)NULLutf-8encoding	ModelTypeModel)boundc                       e Zd Z ej                  d      ZdZeddee	e
ef      dee   defd       Zedee	e
ef      d	edefd
       Zy)RawDeserializerz&^(application|text)/([a-z+.]+\+)?json$deserialized_dataNdatacontent_typereturnc                 J   t        |d      rt        t        |      j                         }t	        |t
              r|j                  d      }n%t        t        |      }|j                  t              }||S | j                  j                  |      r	 t        j                  |      S d|xs g v r9	 	 t	        |t"              r|j%                  d      }t)        j*                  |      S |j3                  d      r|S t        dj!                  |            # t        $ r!}t        dj!                  |      |      |d}~ww xY w# t&        $ r Y zw xY w# t(        j,                  $ r=}d } ||      \  }}|r|cY d}~S t.        j1                  d	       t        d
      |d}~ww xY w)a  Decode data according to content-type.

        Accept a stream of data as well, but will be load at once in memory for now.

        If no content-type, will return the string version (not bytes, not stream)

        :param data: Input, could be bytes or stream (will be decoded with UTF8) or text
        :type data: str or bytes or IO
        :param str content_type: The content type.
        :return: The deserialized data.
        :rtype: object
        readz	utf-8-sigr   NzJSON is invalid: {}xmlr   c                 P    	 dt        j                  |       fS # t        $ r Y yw xY w)NT)FN)jsonloads
ValueErrorr    s    m/root/aria/tools/markitdown-venv/lib/python3.12/site-packages/azure/ai/documentintelligence/_serialization.py_json_attempz;RawDeserializer.deserialize_from_text.<locals>._json_attemp   s-    +#TZZ%555% +*+s    	%%zWasn't XML not JSON, failingzXML is invalidztext/z#Cannot deserialize content-type: {})hasattrr   r   r$   
isinstancebytesdecodestrlstrip_BOMJSON_REGEXPmatchr'   r(   r)   r   formatunicodeencode	NameErrorET
fromstring
ParseError_LOGGERcritical
startswith)clsr    r!   data_as_strerrr,   successjson_results           r+   deserialize_from_textz%RawDeserializer.deserialize_from_textR   s    4 D>&&(DdE"++{+;K sD/K &,,T2KK??  .\zz+.. |)r*F!$0&1&8&8'&8&J }}[11* $$W-"#H#O#OP\#]^^G  \*+@+G+G+LcRX[[\ !  == F
+ (4D'9$&&
   !?@*+;<#E'FsZ   D 2"E E 	E D;;E 	EE EE F"%F6F"<!FF"
body_bytesheadersc                     d}d|v r4|d   j                  d      d   j                         j                         }nd}|r| j                  ||      S y)ay  Deserialize from HTTP response.

        Use bytes and headers to NOT use any requests/aiohttp or whatever
        specific implementation.
        Headers will tested for "content-type"

        :param bytes body_bytes: The body of the response.
        :param dict headers: The headers of the response.
        :returns: The deserialized data.
        :rtype: object
        Nzcontent-type;r   zapplication/json)splitstriplowerrE   )r@   rF   rG   r!   s       r+   deserialize_from_http_genericsz.RawDeserializer.deserialize_from_http_generics   s]     W$">288=a@FFHNNPL .L,,ZFF    N)__name__
__module____qualname__recompiler4   CONTEXT_NAMEclassmethodr	   r
   r   r   r1   r   rE   r   rM    rN   r+   r   r   J   s     "**FGK 'LC_%
2C)D C_T\]`Ta C_mp C_ C_J vrzAR8S ^e jm  rN   r   c                   "    e Zd ZdZd Zd Zd Zy)UTCzTime Zone info for handling UTCc                 ,    t        j                  d      S )zUTF offset for UTC is 0.

        :param datetime.datetime dt: The datetime
        :returns: The offset
        :rtype: datetime.timedelta
        r   datetime	timedeltaselfdts     r+   	utcoffsetzUTC.utcoffset   s     !!!$$rN   c                      y)zTimestamp representation.

        :param datetime.datetime dt: The datetime
        :returns: The timestamp representation
        :rtype: str
        ZrW   r^   s     r+   tznamez
UTC.tzname   s     rN   c                 .    t        j                  d      S )zNo daylight saving for UTC.

        :param datetime.datetime dt: The datetime
        :returns: The daylight saving time
        :rtype: datetime.timedelta
           )hoursr[   r^   s     r+   dstzUTC.dst   s     !!**rN   N)rP   rQ   rR   __doc__ra   rd   rh   rW   rN   r+   rY   rY      s    )%+rN   rY   )timezonec                   6    e Zd ZdZd	dZd Zd Zd Zd Zd Z	y)
_FixedOffsetzFixed offset in minutes east from UTC.
        Copy/pasted from Python doc
        :param datetime.timedelta offset: offset in timedelta format
        Nc                     || _         y rO   _FixedOffset__offset)r_   offsets     r+   __init__z_FixedOffset.__init__   s	    "DMrN   c                     | j                   S rO   rn   r^   s     r+   ra   z_FixedOffset.utcoffset   s    == rN   c                 N    t        | j                  j                         dz        S )Ni  )r1   ro   total_secondsr^   s     r+   rd   z_FixedOffset.tzname   s    t}}224t;<<rN   c                 B    dj                  | j                  d             S )Nz<FixedOffset {}>)r6   rd   r_   s    r+   __repr__z_FixedOffset.__repr__   s    %,,T[[->??rN   c                 ,    t        j                  d      S Nr   r[   r^   s     r+   rh   z_FixedOffset.dst   s    %%a((rN   c                     | j                   fS rO   rn   rv   s    r+   __getinitargs__z_FixedOffset.__getinitargs__   s    MM##rN   r"   N)
rP   rQ   rR   ri   rq   ra   rd   rw   rh   r{   rW   rN   r+   rl   rl      s&    	
	#	!	=	@	)	$rN   rl   z	(?<!\\)\.c                 
    | |fS )zA key transformer that returns the Python attribute.

    :param str key: The attribute name
    :param dict attr_desc: The attribute metadata
    :param object value: The value
    :returns: A key using attribute name
    :rtype: str
    rW   key	attr_descvalues      r+   attribute_transformerr     s     <rN   c                 r    t         j                  |d         }|D cg c]  }t        |       c}|fS c c}w )zA key transformer that returns the full RestAPI key path.

    :param str key: The attribute name
    :param dict attr_desc: The attribute metadata
    :param object value: The value
    :returns: A list of keys using RestAPI syntax.
    :rtype: list
    r   )_FLATTENrJ   _decode_attribute_map_key)r   r   r   keysks        r+   full_restapi_key_transformerr     s6     >>)E*+D378a&q)8%@@8s   4c                 0    t        | ||      \  } }| d   |fS )zA key transformer that returns the last RestAPI key.

    :param str key: The attribute name
    :param dict attr_desc: The attribute metadata
    :param object value: The value
    :returns: The last RestAPI key.
    :rtype: str
    )r   r~   s      r+   last_restapi_key_transformerr     s%     .c9eDJCGUrN   c                     |r|rt        j                  ||       |rt        j                  d|z   dz   | z         S t        j                  |       S )zCreate a XML node.

    :param str tag: The tag name
    :param str prefix: The prefix
    :param str ns: The namespace
    :return: The XML node
    :rtype: xml.etree.ElementTree.Element
    {})r:   register_namespaceElement)tagprefixnss      r+   _create_xml_noder   )  sF     "
fb)	zz#(S.3.//::c?rN   c                      e Zd ZU dZi Zeeeeef   f   ed<   i Z	eeeeef   f   ed<   i Z
eeeeef   f   ed<   deddfdZd	edefd
Zd	edefdZdefdZedd       Zedefd       Zed        Zd dededefdZdefdedeeeeef   egef   dedefdZed        Zed!dee   dedee   defd       Ze	 	 d"dee   dedeeeeeef   egef      dee   def
d       Zed        Zed        Z ed        Z!y)#r   zmMixin for all client request body/response body models to support
    serialization and deserialization.
    _subtype_map_attribute_map_validationkwargsr"   Nc                 >   i | _         |D ]  }|| j                  vr"t        j                  d|| j                         3|| j
                  v rA| j
                  |   j                  dd      r"t        j                  d|| j                         t        | |||           y )Nz;%s is not a known attribute of class %s and will be ignoredreadonlyFz1Readonly attribute %s will be ignored in class %s)additional_propertiesr   r=   warning	__class__r   getsetattr)r_   r   r   s      r+   rq   zModel.__init__B  s    ?A" 	,A+++ ]_`bfbpbpqd&&&4+;+;A+>+B+B:u+U SUVX\XfXfga+	,rN   otherc                 b    t        || j                        r| j                  |j                  k(  S y)zCompare objects by comparing all attributes.

        :param object other: The object to compare
        :returns: True if objects are equal
        :rtype: bool
        F)r.   r   __dict__r_   r   s     r+   __eq__zModel.__eq__L  s(     eT^^,==ENN22rN   c                 &    | j                  |       S )zCompare objects by comparing all attributes.

        :param object other: The object to compare
        :returns: True if objects are not equal
        :rtype: bool
        )r   r   s     r+   __ne__zModel.__ne__W  s     ;;u%%%rN   c                 ,    t        | j                        S rO   )r1   r   rv   s    r+   __str__zModel.__str__`  s    4==!!rN   c                 (    ddd| j                   d<   y )N z{object})r   typer   )r   r@   s    r+   $enable_additional_properties_sendingz*Model.enable_additional_properties_sendingc  s    >@*6U23rN   c                 <    	 | j                    y# t        $ r Y yw xY w)NFT)_xml_mapAttributeErrorr   s    r+   is_xml_modelzModel.is_xml_modelg  s'    	LL   		s    	c                     	 | j                   }t        |j                  d| j                        |j                  dd      |j                  dd            S # t        $ r i }Y Tw xY w)zgCreate XML node.

        :returns: The XML node
        :rtype: xml.etree.ElementTree.Element
        namer   Nr   )r   r   r   r   rP   )r@   xml_maps     r+   r   zModel._create_xml_nodeo  sb    	llG  FCLL A7;;xY]C^`g`k`klprv`wxx  	G	s   A A#"A#keep_readonlyc                 ^    t        | j                               } |j                  | fd|i|S )a  Return the JSON that would be sent to server from this model.

        This is an alias to `as_dict(full_restapi_key_transformer, keep_readonly=False)`.

        If you want XML serialization, you can pass the kwargs is_xml=True.

        :param bool keep_readonly: If you want to serialize the readonly attributes
        :returns: A dict JSON compatible object
        :rtype: dict
        r   
Serializer_infer_class_models
_serialize)r_   r   r   
serializers       r+   	serializezModel.serialize}  s?       8 8 :;
$z$$
 -
17
 	
rN   Tkey_transformerc                 `    t        | j                               } |j                  | f||d|S )aF  Return a dict that can be serialized using json.dump.

        Advanced usage might optionally use a callback as parameter:

        .. code::python

            def my_key_transformer(key, attr_desc, value):
                return key

        Key is the attribute name used in Python. Attr_desc
        is a dict of metadata. Currently contains 'type' with the
        msrest type and 'key' with the RestAPI encoded key.
        Value is the current value in this object.

        The string returned will be used to serialize the key.
        If the return type is a list, this is considered hierarchical
        result dict.

        See the three examples in this file:

        - attribute_transformer
        - full_restapi_key_transformer
        - last_restapi_key_transformer

        If you want XML serialization, you can pass the kwargs is_xml=True.

        :param bool keep_readonly: If you want to serialize the readonly attributes
        :param function key_transformer: A key transformer function.
        :returns: A dict JSON compatible object
        :rtype: dict
        )r   r   r   )r_   r   r   r   r   s        r+   as_dictzModel.as_dict  sB    J   8 8 :;
$z$$
"1
RX
 	
rN   c                 d   	 | j                   j                  dd      d   }t        j                  |   }|j                  j                         D ci c]  \  }}t        |t              s|| }}}| j                  |vrt        d      	 |S c c}}w # t        $ r | j                  | i}Y |S w xY w)N.rf   r   zNot Autorest generated code)rQ   rsplitsysmodulesr   itemsr.   r   rP   r)   	Exception)r@   
str_modelsmodelsr   vclient_modelss         r+   r   zModel._infer_class_models  s    	0..sA6q9J[[,F.4oo.C.C.E]daTUW[I\QT]M]||=0 !>?? 1
  ^  	0 \\3/M	0s*   AB B*B/B B B/.B/r@   r    r!   c                 ^    t        | j                               } || j                  ||      S )a]  Parse a str using the RestAPI syntax and return a model.

        :param str data: A str using RestAPI structure. JSON by default.
        :param str content_type: JSON by default, set application/xml if XML.
        :returns: An instance of this model
        :raises: DeserializationError if something went wrong
        :rtype: ModelType
        r!   )Deserializerr   rP   )r@   r    r!   deserializers       r+   deserializezModel.deserialize  s*     $C$;$;$=>CLL$\JJrN   key_extractorsc                     t        | j                               }|t        t        t        gn||_         || j                  ||      S )aF  Parse a dict using given key extractor return a model.

        By default consider key
        extractors (rest_key_case_insensitive_extractor, attribute_key_case_insensitive_extractor
        and last_rest_key_case_insensitive_extractor)

        :param dict data: A dict using RestAPI structure
        :param function key_extractors: A key extractor function.
        :param str content_type: JSON by default, set application/xml if XML.
        :returns: An instance of this model
        :raises: DeserializationError if something went wrong
        :rtype: ModelType
        r   )r   r   (attribute_key_case_insensitive_extractor#rest_key_case_insensitive_extractor(last_rest_key_case_insensitive_extractorr   rP   )r@   r    r   r!   r   s        r+   	from_dictzModel.from_dict  sQ    ( $C$;$;$=> %	 938   	# CLL$\JJrN   c                     d| j                   vri S t        | j                  |         }| j                  |   j                         D ]&  }|j	                  ||   j                  ||             ( |S )Nr   )r   dictr   valuesupdate_flatten_subtype)r@   r   objectsresult	valuetypes        r+   r   zModel._flatten_subtype  sp    -Ic&&s+,))#.557 	MIMM'),==c7KL	MrN   c                 T   | j                   j                  di       j                         D ]  }d}t        |t        j
                        s;| j                  |      d   }|j                  |d      xs |j                  |d      }nt        || j                  |   |      }|r0| j                  |k(  r| c S | j                  ||      }	 |||      c S t        j                  d|| j                          | S  | S # t        $ r& t        j                  d|| j                         Y  | S w xY w)a  Check the class _subtype_map for any child classes.
        We want to ignore any inherited _subtype_maps.

        :param dict response: The initial data
        :param dict objects: The class objects
        :returns: The class to be used
        :rtype: class
        r   Nr   z3Subtype value %s has no mapping, use base class %s.z6Discriminator %s is absent or null, use base class %s.)r   r   r   r.   r:   r   _get_rest_key_partsxml_key_extractorr   rP   r   KeyErrorr=   r   )r@   responser   subtype_keysubtype_valuerest_api_response_keyflatten_mapping_types          r+   	_classifyzModel._classify  s3    <<++NB?DDF 	K Mh

3(+(?(?(LR(P% (-BD I lX\\ZegkMl 1+s?Q?QR]?^`h i <<=0J'*';';K'Q$"#7#FGG  XZegjgsgst
5	4 
   OOM%
  
s   C88*D'&D'c                     t         j                  | j                  |   d         }|D cg c]  }t        |       c}S c c}w )zGet the RestAPI key of this attr, split it and decode part
        :param str attr_key: Attribute key must be in attribute_map.
        :returns: A list of RestAPI part
        :rtype: list
        r   )r   rJ   r   r   )r@   attr_keyrest_split_keykey_parts       r+   r   zModel._get_rest_key_parts   s<     "(:(:8(DU(KLDRS)(3SSSs   ?r|   )FrO   NN)"rP   rQ   rR   ri   r   r   r1   r   __annotations__r   r   rq   boolr   r   r   rV   r   r   r   JSONr   r   r   r   r   r   r   r	   r   r   r   r   r   rW   rN   r+   r   r   9  s[    /1L$sDcN*+002NDd38n,-2-/Kc4S>)*/, , ,	C 	D 	&C &D &" " V V T   y y
t 
s 
t 
$ #EZ(
(
 "3S#X"<c"AB(
 	(

 
(
T 
 
 
Ki 
K 
K8C= 
K\e 
K 
K  OS&*	K)_KK !3S#X*Dc*I!JKK sm	K
 
K K>   # #J T TrN   c                 &    | j                  dd      S )zThis decode a key in an _attribute_map to the actual key we want to look at
    inside the received data.

    :param str key: A key string from the generated code
    :returns: The decoded key
    :rtype: str
    z\.r   )replace)r   s    r+   r   r   +  s     ;;uc""rN   c                      e Zd ZdZedededediZdd iZ	ddd	d
ddddZ
dddddddddddddZd d d d d  d! d" d# d$ d% d& d'ZdCd)eeeef      d*d(fd+Z	 dCd,Zd- Zd. Zd/ Zd0 Zd1 Zed2        Zed3        Zed4        ZdCd5Zd6 Zd7 ZedCd8       Zed9        Z ed:        Z!ed;        Z"ed<        Z#ed=        Z$ed>        Z%ed?        Z&ed@        Z'edA        Z(edB        Z)y()Dr   z Request object model serializer.r1   intr   floatc                 4    t        |       j                         S rO   )r1   rL   xs    r+   <lambda>zSerializer.<lambda>;  s    c!flln rN   MonTueWedThuFriSatSun)r   rf                  JanFebMarAprMayJunJulAugSepOctNovDec)rf   r  r  r  r  r        	   
         c                     t        |       |k  S rO   lenr   ys     r+   r   zSerializer.<lambda>L      3q6A: rN   c                     t        |       |kD  S rO   r  r  s     r+   r   zSerializer.<lambda>M  r  rN   c                     | |k  S rO   rW   r  s     r+   r   zSerializer.<lambda>N  
    A rN   c                     | |kD  S rO   rW   r  s     r+   r   zSerializer.<lambda>O  r   rN   c                     | |k  S rO   rW   r  s     r+   r   zSerializer.<lambda>P  
    16 rN   c                     | |k\  S rO   rW   r  s     r+   r   zSerializer.<lambda>Q  r#  rN   c                     t        |       |k  S rO   r  r  s     r+   r   zSerializer.<lambda>R      #a&1* rN   c                     t        |       |kD  S rO   r  r  s     r+   r   zSerializer.<lambda>S  r&  rN   c                 N    t        j                  || t         j                         S rO   )rS   r5   UNICODEr  s     r+   r   zSerializer.<lambda>T  s    BHHQ2::$> > rN   c                 B    t        |       t        t        |             k7  S rO   )r  setr  s     r+   r   zSerializer.<lambda>U  s    s1vSV4 rN   c                     | |z  dk7  S ry   rW   r  s     r+   r   zSerializer.<lambda>V  s    Q! rN   )
min_length
max_lengthminimummaximum
minimum_ex
maximum_ex	min_items	max_itemspatternuniquemultipleNclassesr"   c                    t         j                  t         j                  t         j                  t         j                  t         j
                  t         j                  t         j                  t         j                  t         j                  t         j                  | j                  | j                  | j                  d| _        |rt        |      ni | _        t"        | _        d| _        y )Niso-8601zrfc-1123z	unix-timedurationdatetimedecimallong	bytearraybase64object[]{}T)r   serialize_isoserialize_rfcserialize_unixserialize_durationserialize_dateserialize_timeserialize_decimalserialize_longserialize_bytearrayserialize_base64serialize_objectserialize_iterserialize_dictserialize_typer   dependenciesr   r   client_side_validationr_   r8  s     r+   rq   zSerializer.__init__Y  s    "00"00#22"55----!33--#77 11++%%%%
 ?FT']2;&*#rN   c                 D   |j                  d| j                        }|j                  dd      }|yd}|j                  j                  }|r | j                  ||fi |S t        |d      sEt        |      j                  }|| j                  j                         v r | j                  ||fi |S 	 |d   }i }	|r|j                         }		 |j                  }
|
j                         D ]  \  }}|}|s-|j                  j                  |i       j                  dd      r8|dk(  r0|d	   d
k(  r(|j                   |	j#                  |j                          m	 t%        ||      }|rn0 |||j'                         |      \  }}t)        |t*              r|n|g}||d<    | j                  ||d   fi |}|r|j                  di       }|j                  d|d	         }|j                  dd      }|j                  dd      }|j                  dd      r>|r(t-        j.                  ||       dj1                  ||      }|	j3                  ||       g|j                  dd      r	||	_        t)        |t*              r|	j7                  |       nt)        |t,        j8                        rmdt%        |di       vrL|j:                  j=                  d      }t?        |      dk(  rdjA                  |d   |g      |_        n||_        |	jC                  |       nmt        |||      }tE        |      |_        |	jC                  |       n>tG              D ]  }||i} |}|	}|D ]!  }||vr|j#                  |       ||   }||   }#  	 |	S # t        $ r$ |j                  d|j                               }Y w xY w# tH        $ r}t)        |tJ              r Y d}~d}~ww xY w# tL        t        tN        f$ r-}dj1                  ||tE        |            }tK        |      |d}~ww xY w)a1  Serialize data into a string according to type.

        :param object target_obj: The data to be serialized.
        :param str data_type: The type to be serialized from.
        :rtype: str, dict
        :raises: SerializationError if serialization fails.
        :returns: The serialized data.
        r   r   FNr   is_xmlr   r   r   r   serialization_ctxtr   r%   r   r   r   attr{{{}}}{}textr   r   r  r   z2Attribute {} in object {} cannot be serialized.
{})(r   r   r   rP   serialize_datar-   r   basic_typesr   r   
setdefaultr   r   r   r   r   r   r   getattrcopyr.   listr:   r   r6   r+  r\  extendr   r   rJ   r  joinappendr1   reversedr)   r   r   	TypeError)r_   
target_obj	data_typer   r   r   	attr_name
class_nameis_xml_model_serialization
serialized
attributesrZ  r   	orig_attrr   new_attrxml_descxml_name
xml_prefixxml_nssplitted_tag
local_noder   	_new_attr_serializedrB   msgs                              r+   r   zSerializer._serializem  s=    !**%68L8LM

?E:	))22
&4&&z9GGGz#34Z(11ID,,3355*t**:yKFKK	`)/)9& 
%#446JI	3#22J#-#3#3#5 Ci 	$)?)?)C)Cr*#j%(*)  77Ie<LPR<R!77C"))**J*JK8 '
D 9I1*9$	@PR[*\i'1$'=tD63<F/02t229i>OZSYZH1#,==#;#+<<	%8H#I%-\\(D%A
!)dD!9#<<6% " 5 5j& I+5+<+<VX+N&NN8X>$#<<6.6JO$%h5&--h7'"**=  &WY
B-OO/7||/A/A#/F#&|#4#93688\!_h<W3XHL3;HL&--h7 *:(JPV)WJ.1(mJO&--j9!)$ 5A()8}H5 %-	&0!% 9A 3 + 2 29 =(1!I*5a.K	9yCP a  	`)/):):8ZE\E\E^)_&	`R " !#'9: ; )4 	3GNNyZdfijtfuvC$S)s2	3so   2N B	O C7N6O N6(O *DN6 O )N32N36	O?OO OO P2(PPc                 6   |j                  d      }| j                  j                  |d      }	 |d   }|rdt        |t              sT	 t        | j                        }d|_        |rt        g|_        nt        t        t        g|_        |j!                  ||      } | j(                  ||fi |S # t        $ r8 |r1t	        |t
              r!|j                  d|j                               }nd}Y w xY w# t"        $ r}t%        dt'        |      z         |d}~ww xY w)aU  Serialize data intended for a request body.

        :param object data: The data to be serialized.
        :param str data_type: The type to be serialized from.
        :rtype: dict
        :raises: SerializationError if serialization fails.
        :raises: ValueError if data is None
        :returns: The serialized request body
        []{}NrX  FzUnable to build a model: )rK   rT  r   r   
issubclassr   r_  r   r.   r   r   additional_properties_detectionr   r   r   r   _deserializer   r   r1   r   )	r_   r    ri  r   internal_data_type_strinternal_data_typerl  r   rB   s	            r+   bodyzSerializer.body  s.    "+!8!..223I4P	3)/)9& j1CT&JZ+D,=,=> @E<-@3L/
 <@@3L/
 $00DA ttY9&993  	3!j1CU&K-3->->xI[IhIhIj-k*-2*		3, ( Z()Ds3x)OPVYYZs*   B. AC2 .>C/.C/2	D;DDc                    	  | j                   ||fi |}|dk(  rt        j                  |      }|j                  d      du rAt	        |      }|j                  dt        d            j                  dt        d            }|S t        t	        |      d      }	 |S # t        $ r!}t        dj                  ||            |d	}~ww xY w)
a  Serialize data intended for a URL path.

        :param str name: The name of the URL path parameter.
        :param object data: The data to be serialized.
        :param str data_type: The type to be serialized from.
        :rtype: str
        :returns: The serialized URL path
        :raises: TypeError if serialization fails.
        :raises: ValueError if data is None
        r   
skip_quoteTr   r   r   safe{} must be type {}.N)
r]  r'   dumpsr   r1   r   r   r   rg  r6   )r_   r   r    ri  r   outputexcs          r+   urlzSerializer.url  s    	T(T((yCFCFF"F+zz,'4/VU3Z8@@eCjQ
  s6{4  " 	T188yIJPSS	Ts   B B B 	C&CCc                    	 |j                  d      r.|dd }|j                  dd       } | j                  ||fd|i|S  | j                  ||fi |}|dk(  rt	        j
                  |      }|j                  d      du rt        |      }nt        t        |      d	
      }t        |      S # t        $ r!}t        dj                  ||            |d}~ww xY w)a  Serialize data intended for a URL query.

        :param str name: The name of the query parameter.
        :param object data: The data to be serialized.
        :param str data_type: The type to be serialized from.
        :rtype: str, list
        :raises: TypeError if serialization fails.
        :raises: ValueError if data is None
        :returns: The serialized query parameter
        [rf   r   r  Fdo_quoter   Tr   r  r  N)r?   r   rQ  r]  r'   r  r1   r   r   rg  r6   )	r_   r   r    ri  r   r  r  r  r  s	            r+   queryzSerializer.query!  s    	T##C(%.q_"%zz,>>*t**41CahaZ`aa )T((yCFCFF"F+zz,'4/Vs6{4 6{ " 	T188yIJPSS	Ts   >B/ A#B/ /	C8CCc                    	 |dv r|D cg c]  }|dn|
 }} | j                   ||fi |}|dk(  rt        j                  |      }t        |      S c c}w # t        $ r!}t	        dj                  ||            |d}~ww xY w)ax  Serialize data intended for a request header.

        :param str name: The name of the header.
        :param object data: The data to be serialized.
        :param str data_type: The type to be serialized from.
        :rtype: str
        :raises: TypeError if serialization fails.
        :raises: ValueError if data is None
        :returns: The serialized header
        )z[str]Nr   r   r  )r]  r'   r  r   rg  r6   r1   )r_   r   r    ri  r   dr  r  s           r+   headerzSerializer.header?  s    	TI%8<=1aiQ.==(T((yCFCFF"F+ 6{ >
 " 	T188yIJPSS	Ts'   A A0A A 	B A<<Bc                 j   |t        d      	 |t        u ry|| j                  j                         v r | j                  ||fi |S || j
                  v r | j
                  |   |fi |S | j                  j                  ||j                        }t        |t              rt        j                  ||      S |d   |d   z   }|| j
                  v r | j
                  |   ||dd fi |S 	  | j                   |fi |S # t         t        f$ r#}d}t        |j                  ||            |d}~ww xY w)a  Serialize generic data according to supplied data type.

        :param object data: The data to be serialized.
        :param str data_type: The type to be serialized from.
        :raises: AttributeError if required data is None.
        :raises: ValueError if data is None
        :raises: SerializationError if serialization fails.
        :returns: The serialized data.
        :rtype: str, int, float, bool, dict, list
        NzNo value for given attribute)enum_objr   r   rf   z.Unable to serialize value: {!r} as type: {!r}.)r)   CoreNullr^  r   serialize_basicrS  rT  r   r   r|  r   r   serialize_enumrg  r   r6   r   )r_   r    ri  r   	enum_type	iter_typerB   ry  s           r+   r]  zSerializer.serialize_dataU  sX    <;<<	KxD,,3355+t++D)FvFFD///5t**95dEfEE ))--iHI)T*!00	0JJ!!y}4ID///5t**95dIaOVvVV 0 tt.v.. I& 	KBC$SZZi%@AsJ	Ks/   D  /D  #D  ,AD  92D   D2D--D2c                     |j                  di       j                  |      }|r|S |j                  dd      r| j                  j                  |      S y )Nbasic_types_serializersrX  F)r   _xml_basic_types_serializers)r@   ri  r   custom_serializers       r+   _get_custom_serializersz"Serializer._get_custom_serializers{  sR    "JJ'@"EII)T$$::h&3377	BB 'rN   c                      | j                   |fi |}|r ||      S |dk(  r| j                  |      S  t        |      |      S )a  Serialize basic builting data type.
        Serializes objects to str, int, float or bool.

        Possible kwargs:
        - basic_types_serializers dict[str, callable] : If set, use the callable as serializer
        - is_xml bool : If set, use xml_basic_types_serializers

        :param obj data: Object to be serialized.
        :param str data_type: Type of object in the iterable.
        :rtype: str, int, float, bool
        :return: serialized object
        r1   )r  serialize_unicodeeval)r@   r    ri  r   r  s        r+   r  zSerializer.serialize_basic  sT     8C77	LVL$T**((..tIt$$rN   c                     	 |j                   S # t        $ r Y nw xY w	 t        |t              r|S 	 t        |      S # t        $ r t        |      cY S w xY w)zSpecial handling for serializing unicode strings in Py2.
        Encode to UTF-8 if unicode, otherwise handle as a str.

        :param str data: Object to be serialized.
        :rtype: str
        :return: serialized object
        )r   r   r.   r7   r9   r1   )r@   r    s     r+   r  zSerializer.serialize_unicode  se    	:: 			$(  ) 4y  	t9	s    	< AAc           	      ,   t        |t              rt        d      |j                  di       }|j                  dd      }g }|D ]&  }	 |j	                   | j
                  ||fi |       ( |j                  dd      r'|D 
cg c]  }
|
dnt        t        |
      d       }}
|r-|D 
cg c]  }
|
dn
t        |
       }}
|j                  |      }d	|v s|r|j                  d	i       }|j                  d
      }|s|d   }|j                  dd      }|j                  d|      }|r.t        ||j                  dd      |j                  dd            }ng }|D ]o  }t        |t        j                        r|}n?t        ||j                  dd      |j                  dd            }|t        |      |_        |j	                  |       q |S |S # t        $ r-}	t        |	t              r |j	                  d       Y d}	~	d}	~	ww xY wc c}
w c c}
w )aa  Serialize iterable.

        Supported kwargs:
        - serialization_ctxt dict : The current entry of _attribute_map, or same format.
          serialization_ctxt['type'] should be same as data_type.
        - is_xml bool : If set, serialize as XML

        :param list data: Object to be serialized.
        :param str iter_type: Type of object in the iterable.
        :param str div: If set, this str will be used to combine the elements
         in the iterable into a combined string. Default is 'None'.
        Defaults to False.
        :rtype: list, str
        :return: serialized iterable
        z%Refuse str type as a valid iter type.rY  rX  FNr  r   r  r%   r   r   wrapped	itemsNamer   r   )r.   r1   r   r   re  r]  r)   r   rd  r   r:   r   r\  )r_   r    r  divr   rY  rX  rm  r  rB   srq  rr  
is_wrapped	node_namefinal_resultelel_nodes                     r+   rQ  zSerializer.serialize_iter  s!     dC $%LMM#ZZ(<bAHe,
 	(A(!!"5$"5"5a"Mf"MN	( ::j%(OYZ!	"uSV"/EEZJZ?IJ!	"s1v5JJJ*-J&&&)--eR8H||F+H-e4 "i7J [(;I/(,,xQU:VX`XdXdeikoXpq!  -b"**- G.y(,,xQU:VX`XdXdeikoXpqG~'*2w##G,-  I  (c#56!!$''( [ Ks$   #G!H,H	H	"HH	c                    |j                  di       }i }|j                         D ],  \  }}	  | j                  ||fi ||| j                  |      <   . d|v rl|d   }	|	d   }
t        |
|	j                  dd      |	j                  dd            }|j                         D ]   \  }}|t        j                  ||      _
        " |S |S # t        $ r/}t        |t              r d|| j                  |      <   Y d}~d}~ww xY w)zSerialize a dictionary of objects.

        :param dict attr: Object to be serialized.
        :param str dict_type: Type of object in the dictionary.
        :rtype: dict
        :return: serialized dictionary
        rY  Nr%   r   r   r   )r   r   r]  r  r)   r.   r   r   r:   
SubElementr\  )r_   rZ  	dict_typer   rY  rm  r   r   rB   rq  rr  r  s               r+   rR  zSerializer.serialize_dict  s    $ZZ(<bA
**, 	?JC?:M$:M:MeU^:ibh:i
411#67	? &&)%0H'H+Hhll8T6RT\T`T`aegkTlmL(..0 >
U8=lC05>  ?c#56:>
411#67?s   &C	C>%C99C>c                 n   |yt        |t        j                        r|S t        |      }|| j                  v r! | j
                  || j                  |   fi |S |t        u r| j                  |      S |t        u r| j                  |      S |t        j                  u r| j                  |      S |t        j                  u r| j                  |      S |t        j                  u r| j                  |      S |t        j                   u r| j#                  |      S |t$        j&                  u r| j)                  |      S || j*                  j-                         v st        |t.              r| j1                  |      S |t2        k(  rBi }|j5                         D ]+  \  }}	  | j6                  |fi ||| j                  |      <   - |S |t:        k(  r.g }|D ]%  }	 |j=                   | j6                  |fi |       ' |S t        |      S # t8        $ r d|| j                  |      <   Y w xY w# t8        $ r Y cw xY w)a:  Serialize a generic object.
        This will be handled as a dictionary. If object passed in is not
        a basic type (str, int, float, dict, list) it will simply be
        cast to str.

        :param dict attr: Object to be serialized.
        :rtype: dict or str
        :return: serialized object
        N)r.   r:   r   r   r^  r  
_long_typerM  r1   r  r\   rF  r=  rJ  r>  rK  r]   rI  r?  DecimalrL  rT  r   r   r   r   r   rP  r)   rb  re  )r_   rZ  r   obj_typerm  r   r   objs           r+   rP  zSerializer.serialize_object  s@    <dBJJ'K:t''''4''d.>.>x.HSFSSz!&&t,,s?))$//x(((%%d++x}}$&&t,,x}}$&&t,,x)))**400w&))$// t((//11Ze5L??4((tJ"jjl C
UC>Sd>S>STY>d]c>dJt55c:;C
 tJ %%&;d&;&;C&J6&JK
 4y " C>BJt55c:;C " s$   %H"H(H%$H%(	H43H4c                 N   	 | j                   }	  ||       |S # t        $ r | }Y w xY w# t        $ rq}|D ]I  }|j                   j                         t	        |       j                         k(  s8|j                   c cY d }~S  d}t        |j                  | |            |d }~ww xY w)Nz%{!r} is not valid value for enum {!r})r   r   r)   rL   r1   r   r6   )rZ  r  r   r  
enum_valueerrors         r+   r  zSerializer.serialize_enumD  s    	ZZF	LVM	  	F	
  	L& ,
##))+s4y/@@%+++, <E$U\\$%ABK	Ls2    	* ''	B$9B-B:B$ BB$c                 4    t        |       j                         S )zSerialize bytearray into base-64 string.

        :param str attr: Object to be serialized.
        :rtype: str
        :return: serialized base64
        )r   r0   rZ  r   s     r+   rN  zSerializer.serialize_bytearrayT  s     %%''rN   c                     t        |       j                  d      }|j                  d      j                  dd      j                  dd      S )zSerialize str into base-64 string.

        :param str attr: Object to be serialized.
        :rtype: str
        :return: serialized base64
        ascii=+-/_)r   r0   rK   r   )rZ  r   encodeds      r+   rO  zSerializer.serialize_base64^  sA     D/((1}}S!))#s3;;CEErN   c                     t        |       S )zSerialize Decimal object to float.

        :param decimal attr: Object to be serialized.
        :rtype: float
        :return: serialized decimal
        )r   r  s     r+   rL  zSerializer.serialize_decimali  s     T{rN   c                     t        |       S )zSerialize long (Py2) or int (Py3).

        :param int attr: Object to be serialized.
        :rtype: int/long
        :return: serialized long
        )r  r  s     r+   rM  zSerializer.serialize_longs  s     $rN   c                     t        | t              rt        j                  |       } dj	                  | j
                  | j                  | j                        }|S )zSerialize Date object into ISO-8601 formatted string.

        :param Date attr: Object to be serialized.
        :rtype: str
        :return: serialized date
        z{:04}-{:02}-{:02})r.   r1   isodate
parse_dater6   yearmonthdayrZ  r   ts      r+   rJ  zSerializer.serialize_date}  sC     dC %%d+D&&tyy$**dhhGrN   c                    t        | t              rt        j                  |       } dj	                  | j
                  | j                  | j                        }| j                  r|dj	                  | j                        z  }|S )zSerialize Time object into ISO-8601 formatted string.

        :param datetime.time attr: Object to be serialized.
        :rtype: str
        :return: serialized time
        z{:02}:{:02}:{:02}z.{:02})	r.   r1   r  
parse_timer6   hourminutesecondmicrosecondr  s      r+   rK  zSerializer.serialize_time  se     dC %%d+D&&tyy$++t{{K!1!122ArN   c                 v    t        | t              rt        j                  |       } t        j                  |       S )zSerialize TimeDelta object into ISO-8601 formatted string.

        :param TimeDelta attr: Object to be serialized.
        :rtype: str
        :return: serialized duration
        )r.   r1   r  parse_durationduration_isoformatr  s     r+   rI  zSerializer.serialize_duration  s/     dC ))$/D))$//rN   c           	         	 | j                   st        j                  d       | j                         }dj                  t        j                  |j                     |j                  t        j                  |j                     |j                  |j                  |j                  |j                         S # t        $ r}t        d      |d}~ww xY w)zSerialize Datetime object into RFC-1123 formatted string.

        :param Datetime attr: Object to be serialized.
        :rtype: str
        :raises: TypeError if format invalid.
        :return: serialized rfc
        /Datetime with no tzinfo will be considered UTC.z-RFC1123 object must be valid Datetime object.Nz({}, {:02} {} {:04} {:02}:{:02}:{:02} GMT)tzinfor=   r   utctimetupler   rg  r6   r   daystm_wdaytm_mdaymonthstm_montm_yeartm_hourtm_mintm_sec)rZ  r   utcr  s       r+   rG  zSerializer.serialize_rfc  s    	V;; QR##%C :@@OOCKK(KKcjj)KKKKJJJJ
 	
  	VKLRUU	Vs   1B2 2	C;CCc                    t        | t              rt        j                  |       } 	 | j                  st
        j                  d       | j                         }|j                  dkD  s|j                  dk  rt        d      t        | j                        j                  dd      j                  d      j                  dd      }|rd|z   }d	j                  |j                  |j                  |j                   |j"                  |j$                  |j&                        }||z   d
z   S # t(        t        f$ r}d}t+        |      |d}~wt,        $ r}d}t/        |      |d}~ww xY w)zSerialize Datetime object into ISO-8601 formatted string.

        :param Datetime attr: Object to be serialized.
        :rtype: str
        :raises: SerializationError if format invalid.
        :return: serialized iso
        r  '  rf   Hit max or min dater  0r  r   z#{:04}-{:02}-{:02}T{:02}:{:02}:{:02}rc   z$Unable to serialize datetime object.Nz.ISO-8601 object must be valid Datetime object.)r.   r1   r  parse_datetimer  r=   r   r  r  OverflowErrorr  rjustrstripljustr6   r  r  r  r  r  r)   r   r   rg  )rZ  r   r  microsecondsr=  rB   ry  s          r+   rF  zSerializer.serialize_iso  s3    dC ))$/D	*;; QR##%C{{T!S[[1_#$9::t//066q#>EEcJPPQRTWXL"\18??SZZckk3::szzD ,&,,M* 	38C$S)s2 	*BCC.c)	*s$   C>D& &E"5EE"EE"c                     t        | t              r| S 	 | j                  st        j	                  d       t        t        j                  | j                                     S # t        $ r}t        d      |d}~ww xY w)a  Serialize Datetime object into IntTime format.
        This is represented as seconds.

        :param Datetime attr: Object to be serialized.
        :rtype: int
        :raises: SerializationError if format invalid
        :return: serialied unix
        r  z/Unix time object must be valid Datetime object.N)
r.   r   r  r=   r   calendartimegmr  r   rg  )rZ  r   r  s      r+   rH  zSerializer.serialize_unix  sk     dC K	X;; QRxt'8'8':;<< 	XMNTWW	Xs   AA! !	A;*A66A;rO   )*rP   rQ   rR   ri   r1   r   r   r   r^  r  r  r  
validationr	   r   r   rq   r   r  r  r  r  r]  rV   r  r  r  rQ  rR  rP  staticmethodr  rN  rO  rL  rM  rJ  rK  rI  rG  rF  rH  rW   rN   r+   r   r   6  s	   *sE4HK$*,D#E 5Uu5QDF .-%%)),,>4+J+d); < + +* %)n`):V2<,$/L C C % %(  ,>@<5n L L ( ( F F       
 
   	0 	0 
 
2 * *> X XrN   r   c                 @   |d   }|}d|v rt        t        t           t        j	                  |            }t        |      dk(  rt        |d         }n<t        |d         }|j                  ||      }|y dj                  |dd        }d|v r|j                  |      S Nr   r   rf   r   )	r   r   r1   r   rJ   r  r   r   rd  rZ  r   r    r   working_data	dict_keysworking_keys          r+   rest_key_extractorr    s    
E
CL
*cHNN3$78	y>Q+IaL9C/	!=#''T: hhy}% * C  rN   c                 
   |d   }|}d|v rit         j                  |      }t        |      dk(  rt        |d         }n7t        |d         }t	        |d |      }|y dj                  |dd        }d|v ri|rt	        |d |      S y r  )r   rJ   r  r   r   rd  r  s          r+   r   r     s     E
CL
*NN3'	y>Q+IaL9C/	!=?TS_` hhy}% * 7T<PP rN   c                 V    |d   }t         j                  |      }t        |d   d|      S )a  Extract the attribute in "data" based on the last part of the JSON path key.

    :param str attr: The attribute to extract
    :param dict attr_desc: The attribute description
    :param dict data: The data to extract from
    :rtype: object
    :returns: The extracted attribute
    r   r   N)r   rJ   attribute_key_extractorrZ  r   r    r   r  s        r+   last_rest_key_extractorr    s/     E
Cs#I"9R=$==rN   c                 V    |d   }t         j                  |      }t        |d   d|      S )ac  Extract the attribute in "data" based on the last part of the JSON path key.

    This is the case insensitive version of "last_rest_key_extractor"
    :param str attr: The attribute to extract
    :param dict attr_desc: The attribute description
    :param dict data: The data to extract from
    :rtype: object
    :returns: The extracted attribute
    r   r   N)r   rJ   r   r  s        r+   r   r   -  s/     E
Cs#I3IbM4NNrN   c                 $    |j                  |       S rO   )r   )rZ  r  r    s      r+   r  r  <  s    88D>rN   c                     d }| j                         }|D ]  }||j                         k(  s|} n |j                  |      S rO   )rL   r   )rZ  r  r    	found_key
lower_attrr   s         r+   r   r   @  sH    IJ $I
 88IrN   c                     t        | di       }|j                  d| j                        }|j                  dd      }|rdj                  ||      }|S )zGiven an internal type XML description, extract correct XML name with namespace.

    :param dict internal_type: An model type
    :rtype: tuple
    :returns: A tuple XML name + namespace dict
    r   r   r   Nr[  )r`  r   rP   r6   )internal_typeinternal_type_xml_maprr  rt  s       r+    _extract_name_from_internal_typer  K  sW     $M:rB$((1G1GHH"&&tT2F$$VX6OrN   c                    t        |t              ry t        |t        j                        sy |j	                  di       }|j	                  d|d         }|d   j                  d      }|j	                  dd      }|j	                  dd       }t        |d	i       }|j	                  d
|j	                  d
d             }	|	rdj                  |	|      }|j	                  dd      r|j	                  |      S |j	                  dd      r|j                  S |s|r&t        |t              sd|vr|j                  |      }
nV|s#|r!d|v rt        |      }|j                  |      }
n1|rt        |      }n|j	                  d|      }|j                  |      }
t        |
      dk(  r|r|ry g S y |r:|s|
S t        |
      dk7  rt        dj                  |            t        |
d         S t        |
      dkD  rt        dj                  |            |
d   S )Nr%   r   r   r   r  r  FinternalTyper   r   r[  rZ  r\  r  r   rf   zxTried to deserialize an array not wrapped, and found several nodes '{}'. Maybe you should declare this array as wrapped?z/Find several XML '{}' where it was not expected)r.   r   r:   r   r   r?   r`  r6   r\  r|  r   findallr  r  r   rb  )rZ  r   r    rq  rr  is_iter_typer  r  r  rt  children
items_names               r+   r   r   Z  s   $ dBJJ'}}UB'H||FIe$45H V$//4Li/JMM.$7M#M:rB \\$ 5 9 9$ EFF$$VX6 ||FE"xx!! ||FE"yy mM4)HFZoLo<<)m:O0O3MB<<) 9-HJ!k8<J<<
+
8}I Ox=A& K  R  R 
 HQK   8}q"#T#[#[\d#effA;rN   c                      e Zd ZdZedededediZ e	j                  d      Zd#deeeef      d	dfd
Zd#dZd Zd Zd Zd#dZed#d       Zd#dZd Zd Zd Zd Zd Zed        Zed        Zed        Zed        Z ed        Z!ed        Z"ed        Z#ed        Z$ed        Z%ed         Z&ed!        Z'ed"        Z(y)$r   zResponse object model deserializer.

    :param dict classes: Class type dictionary for deserializing complex types.
    :ivar list key_extractors: Ordered list of extractors to be used by this deserializer.
    r1   r   r   r   zF\d{4}[-]\d{2}[-]\d{2}T\d{2}:\d{2}:\d{2}\.?\d*Z?[-+]?[\d{2}]?:?[\d{2}]?Nr8  r"   c                 F   t         j                  t         j                  t         j                  t         j                  t         j
                  t         j                  t         j                  t         j                  t         j                  t         j                  | j                  | j                  | j                  d| _        t        j                   t"        j$                  ft"        j"                  d| _        |rt)        |      ni | _        t,        t.        g| _        d| _        y )Nr:  )r<  r;  T)r   deserialize_isodeserialize_rfcdeserialize_unixdeserialize_durationdeserialize_datedeserialize_timedeserialize_decimaldeserialize_longdeserialize_bytearraydeserialize_base64deserialize_objectdeserialize_iterdeserialize_dictdeserialize_typer  Durationr\   r]   deserialize_expected_typesr   rT  r  r   r   r}  rV  s     r+   rq   zDeserializer.__init__  s    $44$44%66$99 11 11#77 11%;;"55--''''!
  !))8+=+=>!**+
' ?FT']213DE 04,rN   c                 J    | j                  ||      }| j                  ||      S )a  Call the deserializer to process a REST response.

        :param str target_obj: Target data type to deserialize to.
        :param requests.Response response_data: REST response object.
        :param str content_type: Swagger "produces" if available.
        :raises: DeserializationError if deserialization fails.
        :return: Deserialized object.
        :rtype: object
        )_unpack_contentr~  )r_   rh  response_datar!   r    s        r+   __call__zDeserializer.__call__  s)     ##M<@  T22rN   c           	         t        |d      rt        |di       j                         D cg c]  \  }}|j                  d      s| }}}	 |j                  j                         D ]k  \  }}||v rt        ||      }||d   }	|	j                  d      }
|
| j                  vst        |
t              rOt        ||| j                  |	|             m |S | j                  ||      \  }}t        |t              r| j                  ||      S t        |t              r"t!        |t              r| j#                  ||      S ||t$        u r|S 	 |j                  }i }|j                         D ]  \  }}|dk(  r	|d   d	k(  rd}|j'                         }|d   j                  d      }
|
| j                  v r| j                  |
   |d
<   | j(                  D ]3  } ||||      }|| ||k7  rd}t*        j-                  ||||       2|}5 | j                  ||d         }|||<    	 | j5                  ||      }| j7                  |||      S c c}}w # t        $ r Y yw xY w# t        t.        t0        f$ r}d|z   }t3        |      |d}~ww xY w)ah  Call the deserializer on a model.

        Data needs to be already deserialized as JSON or XML ElementTree

        :param str target_obj: Target data type to deserialize to.
        :param object data: Object to deserialize.
        :raises: DeserializationError if deserialization fails.
        :return: Deserialized object.
        :rtype: object
        r   r   constantNr   r{  r   r   r   r  zbIgnoring extracted value '%s' from %s for key '%s' (duplicate extraction, follow extractors order)z!Unable to deserialize to object: )r-   r`  r   r   r   rK   rT  r.   r   r   r~  r   _classify_targetr1   deserialize_datar   r|  deserialize_enumr  ra  r   r=   r   rg  r   r   _build_additional_properties_instantiate_model)r_   rh  r    r   config	constantsrZ  	mapconfigr   
local_typer  r   rk  rn  d_attrsr   	raw_valuekey_extractorfound_valuery  rB   r   s                         r+   r~  zDeserializer._deserialize  s    4)*29$r2R2X2X2Zu,$^d^h^his^tuIu'+':':'@'@'B 
NOD)y( #D$/E} !*6!2J)3)9)9&)A&)1B1BBjQceiFj D$(9(9*e(LM
N   $44ZF*h$((x88h%*Xt*D((x88<48+K	5!00JG#-#3#3#5 &i22y7G27M 	%NN,	%.v%6%<%<V%D"%):)::040A0ABT0UIn-%)%8%8 
0M"/i"FK".$0Y+5M!S   $OOCmTR$$/	
0 --i69JK %1&8 !% A A*d S&&x:OPPu v " P 	84 	55
BC&s+4	5s>   I	I	B	I BI !AI 	IIJ2JJc           	         | j                   sy d|v r%|j                  di       j                  d      dk7  ry t        |t        j                        r$|D ci c]  }|j
                  |j                   }}|j                         D ch c].  }|d   dk7  r$t        t        j                  |d         d         0 }}t        |j                               }||z
  }|D ci c]  }|||   
 c}S c c}w c c}w c c}w )Nr   r   r   r   )r}  r   r.   r:   r   r   r\  r   r   r   rJ   r+  r   )	r_   attribute_mapr    r  desc
known_keyspresent_keysmissing_keysr   s	            r+   r'  z)Deserializer._build_additional_properties#  s    33"m38I8IJace8f8j8jkp8quw8wdBJJ'.23BFFBGGO3D3 &,,.
E{b  &hnnT%[&A!&DE

 

 499;'#j0*673T#Y77 4
 8s   C.3C3C8c                     |yt        |t              r	 | j                  |   }	 |j	                  || j                        }||j                  j                  fS # t        $ r ||fcY S w xY w# t
        $ r Y 6w xY w)a  Check to see whether the deserialization target object can
        be classified into a subclass.
        Once classification has been determined, initialize object.

        :param str target: The target object type to deserialize to.
        :param str/dict data: The response data to deserialize.
        :return: The classified target object and its class name.
        :rtype: tuple
        r   )r.   r1   rT  r   r   r   r   rP   )r_   targetr    s      r+   r$  zDeserializer._classify_target5  s     >fc"&**62	%%dD,=,=>F v''0000  &v~%&
  		s"   A A, A)(A),	A87A8c                 V    	  | |||      S #  t         j                  dd       Y yxY w)a,  Ignores any errors encountered in deserialization,
        and falls back to not deserializing the object. Recommended
        for use in error deserialization, as we want to return the
        HttpResponseError to users, and not have them deal with
        a deserialization error.

        :param str target_obj: The target object type to deserialize to.
        :param str/dict data: The response data to deserialize.
        :param str content_type: Swagger "produces" if available.
        :return: Deserialized object.
        :rtype: object
        r   zQRan into a deserialization error. Ignoring since this is failsafe deserializationT)exc_infoN)r=   debug)r_   rh  r    r!   s       r+   failsafe_deserializez!Deserializer.failsafe_deserializeN  s9    	
D|DD	MMcnr   s   
 (c                    t        | di       }|r0t        j                  |v r|t        j                     S t        d      t	        | d      r.t        j                  | j                         | j                        S t	        | d      r*t        j                  | j                  | j                        S t        | t        t        f      st	        | d      rt        j                  | |      S | S )a  Extract the correct structure for deserialization.

        If raw_data is a PipelineResponse, try to extract the result of RawDeserializer.
        if we can't, raise. Your Pipeline should have a RawDeserializer.

        If not a pipeline response and raw_data is bytes or string, use content-type
        to decode it. If no content-type, try JSON.

        If raw_data is something else, bypass all logic and return it directly.

        :param obj raw_data: Data to be processed.
        :param str content_type: How to parse if raw_data is a string/bytes.
        :raises JSONDecodeError: If JSON is requested and parsing is impossible.
        :raises UnicodeDecodeError: If bytes is not UTF8
        :rtype: object
        :return: Unpacked content.
        contextzGThis pipeline didn't have the RawDeserializer policy; can't deserializer  _content_consumedr$   )r`  r   rU   r)   r-   rM   r\  rG   r.   r1   r/   rE   )raw_datar!   r>  s      r+   r  zDeserializer._unpack_contentc  s    ( (Ir2++w6;;<<fgg 8V$"AA(--/S[ScScdd 801"AA(--QYQaQabbhe-61J"88<PPrN   c                 X   t        |      rt        |di       }	 |j                  j                         D cg c]  \  }}|j	                  d      r| }}}|j                  j                         D cg c]  \  }}|j	                  d      r| }}}|j                         D ci c]  \  }}||vs|||z   vs|| }	}} |di |	}
|D ]  }t        |
||j	                  |               |r||
_        |
S 	 |j                         D ]  \  }}t        |||        |S c c}}w c c}}w c c}}w # t        $ r/}dj                  	|      }t        |t        |      z         |d}~ww xY w# t        $ r1}d}|dj                  t        |      |      z  }t        |      |d}~ww xY w)	aX  Instantiate a response model passing in deserialized args.

        :param Response response: The response model class.
        :param dict attrs: The deserialized response attributes.
        :param dict additional_properties: Additional properties to be set.
        :rtype: Response
        :return: The instantiated response model.
        r   r   r#  z(Unable to deserialize {} into model {}. Nz#Unable to populate response model. zType: {}, Error: {}rW   )callabler`  r   r   r   r   r   rg  r6   r   r1   r   r   )r_   r   attrsr   subtyper   r   r   constr   response_objrZ  rB   ry  r   exps                   r+   r(  zDeserializer._instantiate_model  s    Hh;GD !) 4 4 : : <1uuZ(   !) 4 4 : : <1uuZ(  
 ,1;;=k41aAW<LQRZbejZjQj!Q$kk'1&1$ ADL$		$@A(9NL6##
9#(;;= 3KD%HdE231

 l  D@GGPXY*3S>:CD  9;,33DNCHH*3/S89sd   D4 D" D4 4D(D4 'D.4D.<D.8D4 ;&E/ "D4 4	E,=*E''E,/	F)8,F$$F)c                 4   ||S 	 |s|S || j                   j                         v r| j                  ||      S || j                  v ryt	        || j
                  j                  |t                           r|S d }t	        |t        j                        r ||      r|j                  sy | j                  |   |      }|S |d   |d   z   }|| j                  v r | j                  |   ||dd       S | j                  |   }t        |t              r8t	        |t        j                        r|j                  }| j                  ||      S 	 | j)                  ||      S # t        t         t"        f$ r(}d}|dj%                  ||      z  }t'        |      |d}~ww xY w)a:  Process data for deserialization according to data type.

        :param str data: The response string to be deserialized.
        :param str data_type: The type to deserialize to.
        :raises: DeserializationError if deserialization fails.
        :return: Deserialized object.
        :rtype: object
        Nc                 
    | dvS )N)rC  rD  rE  rW   r   s    r+   r   z/Deserializer.deserialize_data.<locals>.<lambda>  s    1 = 4 rN   r   r   rf   z$Unable to deserialize response data.z Data: {}, {})r^  r   deserialize_basicr  r.   r  r   tupler:   r   r\  rT  r|  r   r&  r)   rg  r   r6   r   r~  )	r_   r    ri  is_a_text_parsing_typedata_valr  r  rB   ry  s	            r+   r%  zDeserializer.deserialize_data  s    <K 	5D,,3355--dI>>D111dD$C$C$G$G	SXSZ$[\K*&
 dBJJ/4J94U^b^g^g;400;DA!!y}4ID1117t,,Y7i"oNN((3H(D)dBJJ/99D,,T8<< *   400	 I~6 	58C?))$	::C&s+4	5s:   E -E =E 61E (E ?1E 1AE F/#FFc                    |yt        |t        j                        rt        |      }t        |t        t        f      s$t        dj                  |t        |                  |D cg c]  }| j                  ||       c}S c c}w )zDeserialize an iterable.

        :param list attr: Iterable to be deserialized.
        :param str iter_type: The type of object in the iterable.
        :return: Deserialized iterable.
        :rtype: list
        Nz/Cannot deserialize as [{}] an object of type {})	r.   r:   r   rb  r+  r   r6   r   r%  )r_   rZ  r  as       r+   r  zDeserializer.deserialize_iter  ss     <dBJJ':D$s,&'X'_'_`ikoptku'vww=AB%%a3BBBs   'Bc           	      t   t        |t              r'|D ci c]  }|d   | j                  |d   |       c}S t        |t        j                        r$|D ci c]  }|j
                  |j                   }}|j                         D ci c]  \  }}|| j                  ||       c}}S c c}w c c}w c c}}w )a   Deserialize a dictionary.

        :param dict/list attr: Dictionary to be deserialized. Also accepts
         a list of key, value pairs.
        :param str dict_type: The object type of the items in the dictionary.
        :return: Deserialized dictionary.
        :rtype: dict
        r   r   )r.   rb  r%  r:   r   r   r\  r   )r_   rZ  r  r   r  r   r   s          r+   r  zDeserializer.deserialize_dict  s     dD!TXYqAeHd33AgJ	JJYYdBJJ'.23BFFBGGO3D3CG::<P41a4((I66PP Z 4Ps    B*B/	B4c                    |yt        |t        j                        r|S t        |t              r| j	                  |d      S t        |      }|| j                  v r| j	                  || j                  |         S |t        u r| j                  |      S |t        k(  r3i }|j                         D ]  \  }}	  | j                  |fi |||<    |S |t        k(  r.g }|D ]%  }	 |j                   | j                  |fi |       ' |S d}t        |t        |      z         # t        $ r d||<   Y w xY w# t        $ r Y bw xY w)a	  Deserialize a generic object.
        This will be handled as a dictionary.

        :param dict attr: Dictionary to be deserialized.
        :return: Deserialized object.
        :rtype: dict
        :raises: TypeError if non-builtin datatype encountered.
        Nr1   z-Cannot deserialize generic object with type: )r.   r:   r   r1   rJ  r   r^  r  r  r   r   r  r)   rb  re  rg  )	r_   rZ  r   r  deserializedr   r   r  r  s	            r+   r  zDeserializer.deserialize_object  sj    <dBJJ'KdC ))$66:t'''))$0@0@0JKKz!((..tL"jjl -
U-(?(?(?(P(PL%-
  tL  ''(?(?(?(Nv(NO
  ?H-.. " -(,L%- " s$   5D "D3D0/D03	D?>D?c                 v   t        |t        j                        r|j                  }|s|dk(  ryy|dk(  r_|dv rt	        |      S t        |t
              r&|j                         dv ry|j                         dv ry	t        d
j                  |            |dk(  r| j                  |      S  t        |      |      S )a  Deserialize basic builtin data type from string.
        Will attempt to convert to str, int, float and bool.
        This function will also accept '1', '0', 'true' and 'false' as
        valid bool values.

        :param str attr: response string to be deserialized.
        :param str data_type: deserialization data type.
        :return: Deserialized basic type.
        :rtype: str, int, float or bool
        :raises: TypeError if string format is not valid.
        r1   r   Nr   )TFrf   r   )true1T)falser  FzInvalid boolean value: {})r.   r:   r   r\  r   r1   rL   rg  r6   deserialize_unicoder  )r_   rZ  ri  s      r+   rJ  zDeserializer.deserialize_basic.  s     dBJJ'99D% **Dz!$$::<=0::<>1 7>>tDEE++D11tIt$$rN   c                     t        | t              r| S 	 t        | t              r| S 	 t	        |       S # t        $ r t	        |       cY S w xY w)zPreserve unicode objects in Python 2, otherwise return data
        as a string.

        :param str data: response string to be deserialized.
        :return: Deserialized string.
        :rtype: str or unicode
        )r.   r   r7   r9   r1   r*   s    r+   rW  z Deserializer.deserialize_unicodeT  sS     dD!K	$( ) 4y  	t9	s   2 A	A	c                 B   t        | |      s| | S t        | t              r| j                  } t        | t              r'	 t	        |j
                  j                               |    S 	  |t        |             S # t        $ r#}d}t        |j                  | |            |d}~ww xY w# t        $ rp |D ]<  }|j                  j                         t        |       j                         k(  s8|c cY S  t        j                  d| |       t        j!                  |       cY S w xY w)a  Deserialize string into enum object.

        If the string is not a valid enum value it will be returned as-is
        and a warning will be logged.

        :param str data: Response string to be deserialized. If this value is
         None or invalid it will be returned as-is.
        :param Enum enum_obj: Enum object to deserialize to.
        :return: Deserialized enum object.
        :rtype: Enum
        Nz'{!r} is not a valid index for enum {!r}z7Deserializer is not able to find %s as valid enum in %s)r.   r   r   r   rb  __members__r   
IndexErrorr   r6   r1   r)   rL   r=   r   r   rW  )r    r  r  r  r  s        r+   r&  zDeserializer.deserialize_enumj  s    dH%KdD!::DdC RH00779:4@@	:CI&&	  RA*5<<h+GHcQR
  	:& &
##))+s4y/@@%%& OOUW[]ef33D99	:s6   %A6 %B% 6	B"?BB"%AD(D.-DDc                 v    t        | t        j                        r| j                  } t	        t        |             S )zDeserialize string into bytearray.

        :param str attr: response string to be deserialized.
        :return: Deserialized bytearray
        :rtype: bytearray
        :raises: TypeError if string format invalid.
        )r.   r:   r   r\  rA  r   rZ  s    r+   r  z"Deserializer.deserialize_bytearray  s*     dBJJ'99D4))rN   c                     t        | t        j                        r| j                  } ddt	        |       dz   dz  z
  z  }| |z   } | j                  dd      j                  dd      }t        |      S )zDeserialize base64 encoded string into string.

        :param str attr: response string to be deserialized.
        :return: Deserialized base64 string
        :rtype: bytearray
        :raises: TypeError if string format invalid.
        r  r  r  r  r  r  r  )r.   r:   r   r\  r  r   r   )rZ  paddingr  s      r+   r  zDeserializer.deserialize_base64  sh     dBJJ'99Dc$i!mq001g~,,sC(00c:!!rN   c                     t        | t        j                        r| j                  } 	 t	        j
                  t        |             S # t        j                  $ r"}dj                  |       }t        |      |d}~ww xY w)zDeserialize string into Decimal object.

        :param str attr: response string to be deserialized.
        :return: Deserialized decimal
        :raises: DeserializationError if string format invalid.
        :rtype: decimal
        zInvalid decimal {}N)
r.   r:   r   r\  r?  r  r1   DecimalExceptionr6   r   )rZ  rB   ry  s      r+   r  z Deserializer.deserialize_decimal  sf     dBJJ'99D	5??3t9--'' 	5&--d3C&s+4	5s   A A;A66A;c                 d    t        | t        j                        r| j                  } t	        |       S )zDeserialize string into long (Py2) or int (Py3).

        :param str attr: response string to be deserialized.
        :return: Deserialized int
        :rtype: long or int
        :raises: ValueError if string format invalid.
        )r.   r:   r   r\  r  r]  s    r+   r  zDeserializer.deserialize_long  s&     dBJJ'99D$rN   c                     t        | t        j                        r| j                  } 	 t	        j
                  |       }|S # t        t        t        f$ r}d}t        |      |d}~ww xY w)a  Deserialize ISO-8601 formatted string into TimeDelta object.

        :param str attr: response string to be deserialized.
        :return: Deserialized duration
        :rtype: TimeDelta
        :raises: DeserializationError if string format invalid.
        z#Cannot deserialize duration object.N)
r.   r:   r   r\  r  r  r)   r  r   r   )rZ  r<  rB   ry  s       r+   r  z!Deserializer.deserialize_duration  sb     dBJJ'99D	5--d3H  M>: 	57C&s+4	5s   ? A&A!!A&c                    t        | t        j                        r| j                  } t	        j
                  d| t        j                  t        j                  z         rt        d| z        t        j                  | dd      S )zDeserialize ISO-8601 formatted string into Date object.

        :param str attr: response string to be deserialized.
        :return: Deserialized date
        :rtype: Date
        :raises: DeserializationError if string format invalid.
        [^\W\d_].Date must have only digits and -. Received: %sr   )defaultmonth
defaultday)r.   r:   r   r\  rS   searchIUr   r  r  r]  s    r+   r  zDeserializer.deserialize_date  s^     dBJJ'99D99[$rtt4&'WZ^'^__!!$Q1EErN   c                     t        | t        j                        r| j                  } t	        j
                  d| t        j                  t        j                  z         rt        d| z        t        j                  |       S )zDeserialize ISO-8601 formatted string into time object.

        :param str attr: response string to be deserialized.
        :return: Deserialized time
        :rtype: datetime.time
        :raises: DeserializationError if string format invalid.
        re  rf  )r.   r:   r   r\  rS   ri  rj  rk  r   r  r  r]  s    r+   r  zDeserializer.deserialize_time  sZ     dBJJ'99D99[$rtt4&'WZ^'^__!!$''rN   c           
         t        | t        j                        r| j                  } 	 t        j
                  j                  |       }t        j                  |dd dt        t        j                  |d   xs ddz              i}|j                  s|j                  t              }|S # t        $ r}d	}t        |      |d}~ww xY w)
a  Deserialize RFC-1123 formatted string into Datetime object.

        :param str attr: response string to be deserialized.
        :return: Deserialized RFC datetime
        :rtype: Datetime
        :raises: DeserializationError if string format invalid.
        Nr  r  r  r   <   )minutes)tzz*Cannot deserialize to rfc datetime object.)r.   r:   r   r\  emailutilsparsedate_tzr\   rl   r]   r  
astimezoneTZ_UTCr)   r   )rZ  parsed_datedate_objrB   ry  s        r+   r  zDeserializer.deserialize_rfc  s     dBJJ'99D		5++2248K((Ra)5h6H6HR]^_R`RedeikQk6l)mH ??#..&.9   	5>C&s+4	5s   B B* *	C3CCc                    t        | t        j                        r| j                  } 	 | j	                         } t
        j                  j                  |       }|st        d| z         | j                  d      }t        |      dkD  rFd}|d   D ]  }|j                         r||z  } n t        |      dkD  r| j                  ||dd       } t        j                  |       }|j                         }|j                   dkD  s|j                   dk  rt#        d      	 |S # t        t"        t$        f$ r}d	}t'        |      |d
}~ww xY w)a  Deserialize ISO-8601 formatted string into Datetime object.

        :param str attr: response string to be deserialized.
        :return: Deserialized ISO datetime
        :rtype: Datetime
        :raises: DeserializationError if string format invalid.
        zInvalid datetime string: r   rf   r   r  r   r  r  z#Cannot deserialize datetime object.N)r.   r:   r   r\  upperr   
valid_dater5   r)   rJ   r  isdigitr   r  r  r  r  r  r   r   )	rZ  r5   check_decimaldecimal_strdigitrw  test_utcrB   ry  s	            r+   r  zDeserializer.deserialize_iso  s@    dBJJ'99D	5::<D ++11$7E !<t!CDD JJsOM=!A% *1- E}}#u,	
 {#a'<<[15EFD--d3H,,.H$&(*:*:Q*>#$9:: +?
  M>: 	57C&s+4	5s   C2D E1D??Ec                    t        | t        j                        rt        | j                        } 	 t        |       } t
        j
                  j                  | t              }|S # t        $ r}d}t        |      |d}~ww xY w)a
  Serialize Datetime object into IntTime format.
        This is represented as seconds.

        :param int attr: Object to be serialized.
        :return: Deserialized datetime
        :rtype: Datetime
        :raises: DeserializationError if format invalid
        z+Cannot deserialize to unix datetime object.N)
r.   r:   r   r   r\  r\   fromtimestampru  r)   r   )rZ  rw  rB   ry  s       r+   r  zDeserializer.deserialize_unix4  sp     dBJJ'tyy>D	5t9D((66tVDH   	5?C&s+4	5s   /A" "	A>+A99A>rO   ))rP   rQ   rR   ri   r1   r   r   r   r^  rS   rT   rz  r	   r   r   rq   r!  r~  r'  r$  r<  r  r  r(  r%  r  r  r  rJ  rW  r&  r  r  r  r  r  r  r  r  r  r  rW   rN   r+   r   r     s    sE4HKefJ4d); < 4 4<3GQR8$12* # #J(9T-1^C Q")/V$%L  * : :B 
* 
* " " 5 5  
  
   " F F ( (  , " "H  rN   r   r   )QrB  r   r   r  r\   r?  rq  enumr   r'   loggingrS   r   codecstypingr   r   r   r	   r
   r   r   r   r   r   r   r   r   urllibr   ImportErrorurllib.parsexml.etree.ElementTreeetreeElementTreer:   r  azure.core.exceptionsr   r   azure.core.serializationr   r  BOM_UTF8r0   r3   r   r1   r   r   	getLoggerrP   r=   r@  r  r9   r   r  rY   rj   rl   r  ru  rT   r   r   r   r   r   r   r   r   r  r   r  r   r  r   r  r   r   rW   rN   r+   <module>r     s  < (        	 
     # # "  J 5w/Kw/	c3hh hV '

H
%J
+(// +>$18!\\F 2::l#	
A
 oT oTd#z
X z
Xz!*Q.>OGTb
 b
S+  #"#|  JJ  $$x $$>  UFsH   E =E E% F EEE"!E"%FFFF