U
    ~dk                     @   s  d dl mZmZmZmZmZmZmZ ddlm	Z	 e	  d dl
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mZmZ d dlmZ d d	lmZ z,d d
lmZmZmZmZmZmZmZmZ W n4 ek
r   d Z Z Z Z Z Z ZZY nX d dl Z d dl!m"Z"m#Z#m$Z$ d dl%m&Z& d dl'm(Z( e)dZ*G dd de+Z,G dd de,Z-G dd de,Z.G dd de,Z/G dd de,Z0G dd deZ1dd Z2dd Z3dd  Z4dZ5e5fd!d"Z6e5fd#d$Z7e5fd%d&Z8e5fd'd(Z9d)d* Z:dS )+    )nested_scopes
generatorsdivisionabsolute_importwith_statementprint_functionunicode_literals   )backport)
native_strN)OrderedDict)copydeepcopy)chain)Number)OptionalDictSequenceTupleMappingUnionAnyList)qualified_nameproperties_valuescollections_abc)Model)Propertyz^\d+(\.\d+)*$c                   @   s.   e Zd Zdd Zd
ddZdd Zdd	 ZdS )Metac                 C   sH   |   }t| D ]2}|d dkrt| |}t|tjst||| q|S )Nr   _)	__class__dirgetattr
isinstancecollectionsCallablesetattr)selfnew_instanceav r+   H/var/www/html/myproject/myenv/lib/python3.8/site-packages/serial/meta.py__copy__#   s    
zMeta.__copy__Nc                 C   s2   |   }t| D ]\}}t||t||d q|S )Nmemo)r    r   r&   r   )r'   r/   r(   r)   r*   r+   r+   r,   __deepcopy__,   s    zMeta.__deepcopy__c                 C   s   dS )NTr+   r'   r+   r+   r,   __bool__3   s    zMeta.__bool__c                 C   s0   d dtt|  gdd t| D  dg S )N
z%s(c                 S   s    g | ]\}}d |t |f qS )z
    %s=%s,)repr).0pr*   r+   r+   r,   
<listcomp>9   s   z!Meta.__repr__.<locals>.<listcomp>))joinr   typer   r1   r+   r+   r,   __repr__6   s    zMeta.__repr__)N)__name__
__module____qualname__r-   r0   r2   r;   r+   r+   r+   r,   r   !   s   	
r   c                   @   s&   e Zd ZdddZdd Zdd ZdS )	VersionNc	           
      C   sf  t |tr>|d kr>|d kr>|d kr>|d kr>|d kr>|d kr>|d kr>d }|dD ]}	d|	kr||	d\}	}nd|	kr|	d\}	}nxd|	kr|	d\}	}n`d|	kr|	d\}	}nHd|	kr|	d\}	}n0d|	kr|	d\}	}nd|	kr|	d\}	}|r.|	|kr6td	t| q`|	r`|	}q`|| _|| _|| _|| _|| _	|| _
|| _d S )
N&==<=>=<>!==zXMultiple specifications cannot be associated with an instance of `serial.meta.Version`: )r#   strsplit
ValueErrorr4   specificationequals
not_equals	less_thanless_than_or_equal_togreater_thangreater_than_or_equal_to)
r'   version_numberrK   rL   rM   rN   rO   rP   rQ   sr+   r+   r,   __init__C   s^    	

zVersion.__init__c           
      C   s  dt jfdt jfdt jfdt jfdt jfdt jff}t|trHt	
|sZt|tjtfrZt|tttjfrtt|}t|tr|d}|dkrd	}qtd
d |dD }nt|}|D ]\}}t| |}|d k	rtdd |dD }t|}t|t| }	|	dk r(tt|dg|	  }n|	dkrFtt|dg|	 }|||s dS qn6|D ]0\}}t| |}|d k	r^|||s^ dS q^dS )NrL   rM   rN   rO   rP   rQ   z.0 )r   c                 s   s   | ]}t |V  qd S Nint)r5   Zother_componentr+   r+   r,   	<genexpr>   s     z!Version.__eq__.<locals>.<genexpr>.c                 s   s   | ]}t |V  qd S rV   rW   )r5   nr+   r+   r,   rY      s     r   FT)operatoreqneltlegtger#   rH   _DOT_SYNTAX_REmatchr   r   rX   r   bytesnumbersr   rstriptuplerI   r"   r   lenr   )
r'   otherZcompare_properties_functionsZother_componentsZcompare_propertyZcompare_functionZcompare_valueZcompare_valuesZother_valuesldr+   r+   r,   __eq__w   sL    









zVersion.__eq__c                 C   sB   g }dD ].\}}t | |}|d k	r|| j| |  qd|S )N))rL   rA   )rM   rF   )rP   rE   )rQ   rC   )rN   rD   )rO   rB   r@   )r"   appendrK   r9   )r'   representationpropertyr\   r*   r+   r+   r,   __str__   s    
zVersion.__str__)NNNNNNNN)r<   r=   r>   rT   rl   rp   r+   r+   r+   r,   r?   A   s           
4.r?   c                   @   s0   e Zd ZdddZedd Zejdd ZdS )ObjectNc                 C   s   d | _ || _d S rV   )_properties
properties)r'   rs   r+   r+   r,   rT      s    zObject.__init__c                 C   s   | j S rV   )rr   r1   r+   r+   r,   rs      s    zObject.propertiesc                 C   s   t || _d S rV   )
Propertiesrr   )r'   properties_r+   r+   r,   rs      s    )N)r<   r=   r>   rT   ro   rs   setterr+   r+   r+   r,   rq      s    

rq   c                   @   s0   e Zd ZdddZedd Zejdd ZdS )
DictionaryNc                 C   s   d | _ || _d S rV   )_value_typesvalue_typesr'   ry   r+   r+   r,   rT      s    zDictionary.__init__c                 C   s   | j S rV   )rx   r1   r+   r+   r,   ry      s    zDictionary.value_typesc                    s   |d k	rt |ttfr|f}ttk	rlt |tjrB|  fdd}n*t|krlttk	rlt|krltdd |D  }t |tjst	|}|| _
d S )Nc                    s:    | }|d k	r6t |kr6t|kr6ttdd |D  }|S )Nc                 s   s$   | ]}|t kr|tfn|fV  qd S rV   rH   r   r5   tr+   r+   r,   rY      s   z>Dictionary.value_types.<locals>.value_types.<locals>.<genexpr>rH   r   rh   r   dts_typesr+   r,   ry      s    

z+Dictionary.value_types.<locals>.value_typesc                 s   s$   | ]}|t kr|tfn|fV  qd S rV   r{   r|   r+   r+   r,   rY      s   z)Dictionary.value_types.<locals>.<genexpr>)r#   r:   r   r   rH   r$   r%   r   r   rh   rx   rz   r+   r   r,   ry      s    )N)r<   r=   r>   rT   ro   ry   rv   r+   r+   r+   r,   rw      s    

rw   c                   @   s0   e Zd ZdddZedd Zejdd ZdS )ArrayNc                 C   s   d | _ || _d S rV   )_item_types
item_typesr'   r   r+   r+   r,   rT     s    zArray.__init__c                 C   s   | j S rV   )r   r1   r+   r+   r,   r     s    zArray.item_typesc                    s   |d k	r|t |ttfr|f}ttk	rlt |tjrB|  fdd}n*t|krlttk	rlt|krltdd |D  }t|s|t	|}|| _
d S )Nc                    s:    | }|d k	r6t |kr6t|kr6ttdd |D  }|S )Nc                 s   s$   | ]}|t kr|tfn|fV  qd S rV   r{   r|   r+   r+   r,   rY   !  s   z7Array.item_types.<locals>.item_types.<locals>.<genexpr>r~   r   r   r+   r,   r     s    

z$Array.item_types.<locals>.item_typesc                 s   s$   | ]}|t kr|tfn|fV  qd S rV   r{   r|   r+   r+   r,   rY   '  s   z#Array.item_types.<locals>.<genexpr>)r#   r:   r   r   rH   r$   r%   r   callablerh   r   r   r+   r   r,   r     s    	)N)r<   r=   r>   rT   ro   r   rv   r+   r+   r+   r,   r     s    

r   c                       sD   e Zd Zd fdd	Z fddZdd Zddd	Zd
d Z  ZS )rt   Nc                    sN   |d krt    n6t|tr(| }nt|tr>t| }t  | d S rV   )superrT   r#   r   itemsdictsorted)r'   r   r    r+   r,   rT   2  s    


zProperties.__init__c                    s$   t |tst|t || d S rV   )r#   r   rJ   r   __setitem__)r'   keyvaluer   r+   r,   r   A  s    
zProperties.__setitem__c                 C   s
   |  | S rV   r   r1   r+   r+   r,   r-   G  s    zProperties.__copy__c                    s    |  t fdd|  D S )Nc                 3   s"   | ]\}}|t | d fV  qdS )r.   N)r   )r5   kr*   r.   r+   r,   rY   N  s   z*Properties.__deepcopy__.<locals>.<genexpr>)r    rh   r   )r'   r/   r+   r.   r,   r0   K  s
    zProperties.__deepcopy__c           	      C   s4  t t| d g}t|  }t|dkr|d  d7  < |D ]\}}t|trXt |nt|}|d}t|dkr|d g}|dd  D ]}|d|  qd	|}|ddt| d	| d
g7 }q>|dt||f  q>|d d d |d< |d |d  d7  < t|dkr&d	|S d	|S d S )N(r   [r3   r	   z        z    (z        %s,z
        %sz    ),z    (%s, %s),]r8      rU   )
r   r:   rh   r   ri   r#   r4   rI   rm   r9   )	r'   rn   r   r   r*   rvZrvlsZrvsZrvlr+   r+   r,   r;   T  s@    




zProperties.__repr__)N)N)	r<   r=   r>   rT   r   r-   r0   r;   __classcell__r+   r+   r   r,   rt   0  s    
	rt   c                 C   s   t | tr| jptt| S t | tr6t| tr6| jS zt| }W n   t| }Y nX t	dt
j ttd|kr|d| nd| f d S )NH%s requires a parameter which is an instance or sub-class of `%s`, not%sr3   :
 `%s`)r#   r   _metareadr:   
issubclassr4   objectr;   	TypeErrorserial	utilitiescalling_function_qualified_namer   )model
repr_modelr+   r+   r,   r   {  s(    
r   c                 C   s   t | tr(| jd krttt| | _nt | trt| tr| jd krt| tjj	rZt	 n*t| tjj
rnt
 nt| tjjrt nd | _q| jD ]*}t|dr| j|jkrt| j| _ qqn8t| }tdtj ttd|krd| nd| f | jS )Nr   r   r3   r   r   )r#   r   r   r   writabler:   r   r   r   rq   r   rw   	__bases__hasattrr4   r   r   r   r   )r   br   r+   r+   r,   r     s8    





r   c                 C   s   t | trt| }nRt | tr.t| tr.| }n8t| }tdtj t	td|krXd| nd| f t|tj
jrxtn&t|tj
jrtnt|tj
jrtnd }t ||stdt	|t	|f || _d S )Nz^%s requires a value for the parameter `model` which is an instance or sub-class of `%s`, not%sr3   r   r   z.Metadata assigned to `%s` must be of type `%s`)r#   r   r:   r   r4   r   r   r   r   r   r   rq   r   rw   rJ   r   )r   metaZ
model_typer   Zmetadata_typer+   r+   r,   write  s<    


	
r   c                 C   sJ  t | ts"tdttt| f |tk	rDt |tsZt |trJt|}ntdt| || _t | t	j
jr|  D ]$\}}t |trvt|d||f  qvnt | t	j
jrt| j D ]8\}}|jp|}t| |}t |trt|d||f  qnNt | t	j
jrDtt| D ]0}| | }t |trt|d|t|f  q| jS )z
    Return the xpath at which the element represented by this object was found, relative to the root document. If
    the parameter `xpath_` is provided--set the value
    ,`model` must be an instance of `%s`, not %s.z!`xpath_` must be a `str`, not %s.%s/%s%s[%s])r#   r   r   r   r4   _UNIDENTIFIEDrH   r   Z_xpathr   r   rw   r   xpathrq   r   rs   namer"   r   rangeri   )r   Zxpath_r   r*   pnr6   ir+   r+   r,   r     s8    









r   c              	   C   sf  t | ts"tdttt| f |tk	r`t |ttfsTtdt|t|j	f || _
t | tjjr|  D ]4\}}t |trpt|d||ddddf  qpnt | tjjrt| j D ]H\}}|jp|}t| |}t |trt|d||ddddf  qnNt | tjjr`tt| D ]0}| | }t |tr.t|d|t|f  q.| j
S )	Nr   z2`pointer_` must be a `str`, not %s (of type `%s`).r   ~z~0/z~1r   )r#   r   r   r   r4   r   rH   r   r:   r<   Z_pointerr   r   rw   r   pointerreplacerq   r   rs   r   r"   r   r   ri   )r   Zpointer_r   r*   r   ro   r   r+   r+   r,   r   !  s4    


&


&r   c                 C   s   t | tjjjs(tdttt| f |tk	rt |t	sJtdt| || _
t | tjjr|  D ]}t |trft|| qfnnt | tjjrt| j D ]"}t| |}t |trt|| qn,t | tjjr| D ]}t |trt|| q| j
S )Nr   z`url_` must be a `str`, not %s.)r#   r   abcr   r   r   r   r4   r   rH   _urlrw   valuesurlrq   r   rs   keysr"   r   )r   Zurl_r*   r   r+   r+   r,   r   N  s0    





r   c                 C   s  t | ts"tdttt| f |tk	rt |tsXt |trHt|}ntdt| || _t | t	j
jr|  D ]}t |trtt|| qtnnt | t	j
jrt| j D ]"}t| |}t |trt|| qn,t | t	j
jr| D ]}t |trt|| q| jS )Nr   z/`serialization_format` must be a `str`, not %s.)r#   r   r   r   r4   r   rH   r   _formatr   r   rw   r   format_rq   r   rs   r   r"   r   )r   Zserialization_formatr*   r   r+   r+   r,   r   j  s4    








r   c              
      s(  t | tjjjs tdt|   fddfddfddt| }tt| }t | tjjj	r:t
|j D ]}|j| }|r|}||k	r||krt| }||j|< nR||krt| }|j|= t| |}|dk	rtjd	tt| | t| f t| |}	t |	tjjjr|t|	  q|nt | tjjjr|r|jr|j}
|
r||kr|t| }|
|_|  D ]$}	t |	tjjjrt|	  qnrt | tjjjr$|r|jr|j}|r||krt| }||_| D ]$}t |tjjjrt|  qdS )
a  
    Recursively alters model class or instance metadata based on version number metadata associated with an
    object's properties. This allows one data model to represent multiple versions of a specification and dynamically
    change based on the version of a specification represented.

    Arguments:

        - data (serial.abc.model.Model)

        - specification (str):

            The specification to which the `version_number` argument applies.

        - version_number (str|int|[int]):

            A version number represented as text (in the form of integers separated by periods), an integer, or a
            sequence of integers.
    z@The data provided is not an instance of serial.abc.model.Model: c                    sL   | j d k	rHd}d}| j D ]"}|j krd}|krd} q<q|rH|sHdS dS NFT)versionsrK   )Z	property_Zversion_matchedZspecification_matchedZapplicable_version)rK   rR   r+   r,   version_match  s    


zversion.<locals>.version_matchc                    sl   d}g }| D ]J}t |tjjrL |rF|}||k	r:d}|| qVd}q|| q|rdt|S d S d S r   )r#   r   rs   r   rm   rh   )ru   changedZnpsro   np)r   version_propertyr+   r,   version_properties  s    z#version.<locals>.version_propertiesc                    s   d}t | tjjrF| jd k	rF | j}|d k	r|s:t| } || _d}n@t | tjjr| jd k	r | j}|d k	r|s|t| } || _d}| jd k	r | j}|d k	r|st| } || _| S r   )	r#   r   rs   r   r   r   rw   ry   types)ro   r   r   ry   r   )r   r+   r,   r     s,    



z!version.<locals>.version_propertyNz=%s - the property `%s` is not applicable in %s version %s:
%s)r#   r   r   r   r   r   r4   r   r:   rq   rh   rs   r   r   r"   errorsZVersionErrorr   rH   versionrw   ry   r   r   r   )datarK   rR   Zinstance_metaZ
class_metaZproperty_namero   r   Zversion_r   Znew_value_typesZnew_item_typesitemr+   )rK   r   rR   r   r   r,   r     sn    










r   );
__future__r   r   r   r   r   r   r   Zutilities.compatibilityr
   Zfuture.utilsr   rf   r\   rer$   r   r   r   	itertoolsr   r   typingr   r   r   r   r   r   r   r   ImportErrorr   Zserial.utilitiesr   r   r   Zserial.abc.modelr   Zserial.abc.propertiesr   compilerc   r   r   r?   rq   rw   r   rt   r   r   r   r   r   r   r   r   r   r+   r+   r+   r,   <module>   sJ   $,& v7*K''),-'