3
‘^¹j  ã               @   s^  d dddddgZ ddlT ddlT dd	lZdd	lZdd	lZdd	lZdd	lZdd	l	Z	dd	l
Z
G d
d„ deƒZG dd „ d ƒZG dd„ deƒZejdejƒ ejdejƒ ejdejƒ ejdejƒ ejdejƒ ejdejƒ ejdejƒ ejdejƒ ejdejƒ ejdejƒ ejdejƒ ejdejƒ ejd	ejƒ G dd„ deƒZejdejƒ ejdejƒ ejdejƒ ejdejƒ ejdej ƒ ejdejƒ ejd ej!ƒ ejd!ejƒ ejd"ej"ƒ ejd#ejƒ ejd$ej#ƒ ejd%ejƒ ej$d&ej%ƒ ej$d'ej&ƒ ej$d(ej'ƒ ej$d)ej(ƒ G d*d„ deƒZ)e)j$d+e)j*ƒ G d,d„ de)ƒZ+d	S )-ÚBaseConstructorÚSafeConstructorÚFullConstructorÚUnsafeConstructorÚConstructorÚConstructorErroré   )Ú*é    Nc               @   s   e Zd ZdS )r   N)Ú__name__Ú
__module__Ú__qualname__© r   r   úC/home/yuhw/zmq/venv/lib/python3.6/site-packages/yaml/constructor.pyr      s   c               @   s„   e Zd Zi Zi Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Z	ddd„Z
dd„ Zddd„Zddd„Zddd„Zedd„ ƒZedd„ ƒZdS )r   c             C   s   i | _ i | _g | _d| _d S )NF)Úconstructed_objectsÚrecursive_objectsÚstate_generatorsÚdeep_construct)Úselfr   r   r   Ú__init__   s    zBaseConstructor.__init__c             C   s   | j ƒ S )N)Ú
check_node)r   r   r   r   Ú
check_data   s    zBaseConstructor.check_datac             C   s   | j ƒ r| j| jƒ ƒS d S )N)r   Úconstruct_documentZget_node)r   r   r   r   Úget_data"   s    zBaseConstructor.get_datac             C   s   | j ƒ }|d k	r| j|ƒS d S )N)Zget_single_noder   )r   Únoder   r   r   Úget_single_data'   s    
zBaseConstructor.get_single_datac             C   sT   | j |ƒ}x2| jr<| j}g | _x|D ]}x|D ]}q.W q$W qW i | _i | _d| _|S )NF)Úconstruct_objectr   r   r   r   )r   r   Údatar   Ú	generatorÚdummyr   r   r   r   .   s    


z"BaseConstructor.construct_documentFc       
      C   s   || j kr| j | S |r$| j}d| _|| jkr>td d d|jƒ‚d | j|< d }d }|j| jkrj| j|j }n²x°| jD ]6}|d k	rr|jj|ƒrr|jt	|ƒd … }| j| }P qrW d | jkrÈ|j}| jd  }nTd | jkrÞ| jd  }n>t
|tƒrò| jj}n*t
|tƒ�r| jj}nt
|tƒ�r| jj}|d k�r2|| |ƒ}n|| ||ƒ}t
|tjƒ�r~|}t|ƒ}| j�rrx|D ]}	�qfW n| jj|ƒ || j |< | j|= |�rœ|| _|S )NTz$found unconstructable recursive node)r   r   r   r   Ú
start_markÚtagÚyaml_constructorsÚyaml_multi_constructorsÚ
startswithÚlenÚ
isinstanceÚ
ScalarNodeÚ	__class__Úconstruct_scalarÚSequenceNodeÚconstruct_sequenceÚMappingNodeÚconstruct_mappingÚtypesÚGeneratorTypeÚnextr   Úappend)
r   r   ÚdeepZold_deepÚconstructorZ
tag_suffixÚ
tag_prefixr   r   r   r   r   r   r   ;   sX    













z BaseConstructor.construct_objectc             C   s&   t |tƒs td d d|j |jƒ‚|jS )Nz$expected a scalar node, but found %s)r%   r&   r   Úidr   Úvalue)r   r   r   r   r   r(   m   s
    
z BaseConstructor.construct_scalarc                s6   t |tƒs td d d|j |jƒ‚‡ ‡fdd„|jD ƒS )Nz&expected a sequence node, but found %sc                s   g | ]}ˆj |ˆ d �‘qS ))r1   )r   )Ú.0Úchild)r1   r   r   r   ú
<listcomp>y   s   z6BaseConstructor.construct_sequence.<locals>.<listcomp>)r%   r)   r   r4   r   r5   )r   r   r1   r   )r1   r   r   r*   t   s    
z"BaseConstructor.construct_sequencec             C   s€   t |tƒs td d d|j |jƒ‚i }xV|jD ]L\}}| j||d�}t |tjj	ƒsbtd|jd|jƒ‚| j||d�}|||< q,W |S )Nz%expected a mapping node, but found %s)r1   zwhile constructing a mappingzfound unhashable key)
r%   r+   r   r4   r   r5   r   ÚcollectionsÚabcÚHashable)r   r   r1   ÚmappingÚkey_nodeÚ
value_nodeÚkeyr5   r   r   r   r,   |   s    

z!BaseConstructor.construct_mappingc             C   sf   t |tƒs td d d|j |jƒ‚g }x<|jD ]2\}}| j||d�}| j||d�}|j||fƒ q,W |S )Nz%expected a mapping node, but found %s)r1   )r%   r+   r   r4   r   r5   r   r0   )r   r   r1   Úpairsr=   r>   r?   r5   r   r   r   Úconstruct_pairs‹   s    
zBaseConstructor.construct_pairsc             C   s$   d| j kr| jjƒ | _|| j|< d S )Nr!   )Ú__dict__r!   Úcopy)Úclsr    r2   r   r   r   Úadd_constructor—   s    
zBaseConstructor.add_constructorc             C   s$   d| j kr| jjƒ | _|| j|< d S )Nr"   )rB   r"   rC   )rD   r3   Zmulti_constructorr   r   r   Úadd_multi_constructor�   s    
z%BaseConstructor.add_multi_constructorN)F)F)F)F)r
   r   r   r!   r"   r   r   r   r   r   r   r(   r*   r,   rA   ÚclassmethodrE   rF   r   r   r   r   r      s   
2


c                   sê   e Zd Z‡ fdd„Zdd„ Zd(‡ fdd„	Zdd	„ Zd
dd
dd
ddœZdd„ Zdd„ Z	dZ
xe
e
e
 krpe
e
9 Z
qZW e
 e
 Zdd„ Zdd„ ZejdejƒZdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd d!„ Zd"d#„ Zd$d%„ Zd&d'„ Z‡  ZS ))r   c                s>   t |tƒr2x&|jD ]\}}|jdkr| j|ƒS qW tƒ j|ƒS )Nztag:yaml.org,2002:value)r%   r+   r5   r    r(   Úsuper)r   r   r=   r>   )r'   r   r   r(   ¥   s
    

z SafeConstructor.construct_scalarc       	      C   s.  g }d}�x|t |jƒk �r|j| \}}|jdkrð|j|= t|tƒr^| j|ƒ |j|jƒ n�t|tƒrÖg }xF|jD ]<}t|tƒsštd|j	d|j
 |j	ƒ‚| j|ƒ |j|jƒ qtW |jƒ  x0|D ]}|j|ƒ qÂW ntd|j	d|j
 |j	ƒ‚q|jdk�rd|_|d7 }q|d7 }qW |�r*||j |_d S )	Nr	   ztag:yaml.org,2002:mergezwhile constructing a mappingz,expected a mapping for merging, but found %sz@expected a mapping or list of mappings for merging, but found %sztag:yaml.org,2002:valueztag:yaml.org,2002:strr   )r$   r5   r    r%   r+   Úflatten_mappingÚextendr)   r   r   r4   r0   Úreverse)	r   r   ÚmergeÚindexr=   r>   ZsubmergeÚsubnoder5   r   r   r   rI   ¬   s>    







zSafeConstructor.flatten_mappingFc                s$   t |tƒr| j|ƒ tƒ j||d�S )N)r1   )r%   r+   rI   rH   r,   )r   r   r1   )r'   r   r   r,   Ï   s    

z!SafeConstructor.construct_mappingc             C   s   | j |ƒ d S )N)r(   )r   r   r   r   r   Úconstruct_yaml_nullÔ   s    
z#SafeConstructor.construct_yaml_nullT)ÚyesÚnoÚtrueÚfalseÚonÚoffc             C   s   | j |ƒ}| j|jƒ  S )N)r(   Úbool_valuesÚlower)r   r   r5   r   r   r   Úconstruct_yaml_boolá   s    
z#SafeConstructor.construct_yaml_boolc             C   s  | j |ƒ}|jddƒ}d}|d dkr*d}|d dkrB|dd … }|dkrNdS |jdƒrn|t|d	d … d	ƒ S |jd
ƒrŽ|t|d	d … dƒ S |d dkr¨|t|dƒ S d|k�r dd„ |jdƒD ƒ}|jƒ  d}d}x |D ]}||| 7 }|d9 }qÜW || S |t|ƒ S d S )NÚ_Ú r   r	   ú-z+-Ú0Z0bé   Ú0xé   é   ú:c             S   s   g | ]}t |ƒ‘qS r   )Úint)r6   Úpartr   r   r   r8   ö   s    z6SafeConstructor.construct_yaml_int.<locals>.<listcomp>é<   r   éÿÿÿÿ)r(   Úreplacer#   rb   ÚsplitrK   )r   r   r5   ÚsignÚdigitsÚbaseÚdigitr   r   r   Úconstruct_yaml_intå   s2    




z"SafeConstructor.construct_yaml_intgœu ˆ<ä7~c             C   sÌ   | j |ƒ}|jddƒjƒ }d}|d dkr.d}|d dkrF|dd … }|dkrX|| j S |dkrf| jS d	|kr¼d
d„ |jd	ƒD ƒ}|jƒ  d}d}x |D ]}||| 7 }|d9 }q˜W || S |t|ƒ S d S )NrY   rZ   r   r	   r[   z+-z.infz.nanra   c             S   s   g | ]}t |ƒ‘qS r   )Úfloat)r6   rc   r   r   r   r8     s    z8SafeConstructor.construct_yaml_float.<locals>.<listcomp>g        rd   r   re   )r(   rf   rW   Ú	inf_valueÚ	nan_valuerg   rK   rm   )r   r   r5   rh   ri   rj   rk   r   r   r   Úconstruct_yaml_float  s*    


z$SafeConstructor.construct_yaml_floatc             C   s¬   y| j |ƒjdƒ}W n6 tk
rJ } ztd d d| |jƒ‚W Y d d }~X nX y"ttdƒrbtj|ƒS tj|ƒS W n8 t	j
k
r¦ } ztd d d| |jƒ‚W Y d d }~X nX d S )NÚasciiz,failed to convert base64 data into ascii: %sÚdecodebytesz failed to decode base64 data: %s)r(   ÚencodeÚUnicodeEncodeErrorr   r   ÚhasattrÚbase64rr   ÚdecodestringÚbinasciiÚError)r   r   r5   Úexcr   r   r   Úconstruct_yaml_binary  s    

z%SafeConstructor.construct_yaml_binarya´  ^(?P<year>[0-9][0-9][0-9][0-9])
                -(?P<month>[0-9][0-9]?)
                -(?P<day>[0-9][0-9]?)
                (?:(?:[Tt]|[ \t]+)
                (?P<hour>[0-9][0-9]?)
                :(?P<minute>[0-9][0-9])
                :(?P<second>[0-9][0-9])
                (?:\.(?P<fraction>[0-9]*))?
                (?:[ \t]*(?P<tz>Z|(?P<tz_sign>[-+])(?P<tz_hour>[0-9][0-9]?)
                (?::(?P<tz_minute>[0-9][0-9]))?))?)?$c          
   C   s@  | j |ƒ}| jj|jƒ}|jƒ }t|d ƒ}t|d ƒ}t|d ƒ}|d sZtj|||ƒS t|d ƒ}t|d ƒ}	t|d ƒ}
d}d }|d rÀ|d d d	… }xt|ƒd	k r¶|d
7 }q W t|ƒ}|d �rt|d ƒ}t|d pâdƒ}tj	||d�}|d dk�r| }tj
|ƒ}n|d �r&tj
j}tj|||||	|
||d�S )NÚyearÚmonthÚdayÚhourÚminuteÚsecondr	   Úfractioné   r\   Ztz_signÚtz_hourÚ	tz_minute)ÚhoursÚminutesr[   Útz)Útzinfo)r(   Útimestamp_regexpÚmatchr5   Ú	groupdictrb   ÚdatetimeÚdater$   Ú	timedeltaÚtimezoneÚutc)r   r   r5   r‹   Úvaluesr|   r}   r~   r   r€   r�   r‚   r‰   r„   r…   Údeltar   r   r   Úconstruct_yaml_timestamp:  s:    


z(SafeConstructor.construct_yaml_timestampc             c   s¼   g }|V  t |tƒs,td|jd|j |jƒ‚xŠ|jD ]€}t |tƒsZtd|jd|j |jƒ‚t|jƒdkr„td|jdt|jƒ |jƒ‚|jd \}}| j|ƒ}| j|ƒ}|j	||fƒ q4W d S )Nz!while constructing an ordered mapz!expected a sequence, but found %sz,expected a mapping of length 1, but found %sr   z2expected a single mapping item, but found %d itemsr	   )
r%   r)   r   r   r4   r5   r+   r$   r   r0   )r   r   ZomaprN   r=   r>   r?   r5   r   r   r   Úconstruct_yaml_omapY  s$    



z#SafeConstructor.construct_yaml_omapc             c   s¼   g }|V  t |tƒs,td|jd|j |jƒ‚xŠ|jD ]€}t |tƒsZtd|jd|j |jƒ‚t|jƒdkr„td|jdt|jƒ |jƒ‚|jd \}}| j|ƒ}| j|ƒ}|j	||fƒ q4W d S )Nzwhile constructing pairsz!expected a sequence, but found %sz,expected a mapping of length 1, but found %sr   z2expected a single mapping item, but found %d itemsr	   )
r%   r)   r   r   r4   r5   r+   r$   r   r0   )r   r   r@   rN   r=   r>   r?   r5   r   r   r   Úconstruct_yaml_pairso  s$    



z$SafeConstructor.construct_yaml_pairsc             c   s$   t ƒ }|V  | j|ƒ}|j|ƒ d S )N)Úsetr,   Úupdate)r   r   r   r5   r   r   r   Úconstruct_yaml_set„  s    
z"SafeConstructor.construct_yaml_setc             C   s
   | j |ƒS )N)r(   )r   r   r   r   r   Úconstruct_yaml_strŠ  s    z"SafeConstructor.construct_yaml_strc             c   s   g }|V  |j | j|ƒƒ d S )N)rJ   r*   )r   r   r   r   r   r   Úconstruct_yaml_seq�  s    z"SafeConstructor.construct_yaml_seqc             c   s"   i }|V  | j |ƒ}|j|ƒ d S )N)r,   r˜   )r   r   r   r5   r   r   r   Úconstruct_yaml_map’  s    
z"SafeConstructor.construct_yaml_mapc             c   sN   |j |ƒ}|V  t|dƒr4| j|dd�}|j|ƒ n| j|ƒ}|jj|ƒ d S )NÚ__setstate__T)r1   )Ú__new__ru   r,   r�   rB   r˜   )r   r   rD   r   Ústater   r   r   Úconstruct_yaml_object˜  s    


z%SafeConstructor.construct_yaml_objectc             C   s   t d d d|j |jƒ‚d S )Nz0could not determine a constructor for the tag %r)r   r    r   )r   r   r   r   r   Úconstruct_undefined¢  s    z#SafeConstructor.construct_undefined)F)r
   r   r   r(   rI   r,   rO   rV   rX   rl   rn   ro   rp   r{   ÚreÚcompileÚXrŠ   r”   r•   r–   r™   rš   r›   rœ   r    r¡   Ú__classcell__r   r   )r'   r   r   £   s:   #



ztag:yaml.org,2002:nullztag:yaml.org,2002:boolztag:yaml.org,2002:intztag:yaml.org,2002:floatztag:yaml.org,2002:binaryztag:yaml.org,2002:timestampztag:yaml.org,2002:omapztag:yaml.org,2002:pairsztag:yaml.org,2002:setztag:yaml.org,2002:strztag:yaml.org,2002:seqztag:yaml.org,2002:mapc               @   sŒ   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zd!dd„Z	d"dd„Z
dd„ Zdd„ Zd#dd„Zdd„ Zdd„ Zd$dd„Zdd „ ZdS )%r   c             C   s
   | j |ƒS )N)r(   )r   r   r   r   r   Úconstruct_python_strÜ  s    z$FullConstructor.construct_python_strc             C   s
   | j |ƒS )N)r(   )r   r   r   r   r   Úconstruct_python_unicodeß  s    z(FullConstructor.construct_python_unicodec             C   s¬   y| j |ƒjdƒ}W n6 tk
rJ } ztd d d| |jƒ‚W Y d d }~X nX y"ttdƒrbtj|ƒS tj|ƒS W n8 t	j
k
r¦ } ztd d d| |jƒ‚W Y d d }~X nX d S )Nrq   z,failed to convert base64 data into ascii: %srr   z failed to decode base64 data: %s)r(   rs   rt   r   r   ru   rv   rr   rw   rx   ry   )r   r   r5   rz   r   r   r   Úconstruct_python_bytesâ  s    

z&FullConstructor.construct_python_bytesc             C   s
   | j |ƒS )N)rl   )r   r   r   r   r   Úconstruct_python_longò  s    z%FullConstructor.construct_python_longc             C   s   t | j|ƒƒS )N)Úcomplexr(   )r   r   r   r   r   Úconstruct_python_complexõ  s    z(FullConstructor.construct_python_complexc             C   s   t | j|ƒƒS )N)Útupler*   )r   r   r   r   r   Úconstruct_python_tupleø  s    z&FullConstructor.construct_python_tupleFc             C   s‚   |st d|d|ƒ‚|r\yt|ƒ W n8 tk
rZ } zt d|d||f |ƒ‚W Y d d }~X nX |tjkrxt d|d| |ƒ‚tj| S )Nz"while constructing a Python modulez+expected non-empty name appended to the tagzcannot find module %r (%s)zmodule %r is not imported)r   Ú
__import__ÚImportErrorÚsysÚmodules)r   ÚnameÚmarkÚunsaferz   r   r   r   Úfind_python_moduleû  s    "
z"FullConstructor.find_python_modulec             C   sÐ   |st d|d|ƒ‚d|kr,|jddƒ\}}nd}|}|r~yt|ƒ W n8 tk
r| } zt d|d||f |ƒ‚W Y d d }~X nX |tjkršt d|d| |ƒ‚tj| }t||ƒsÆt d|d||jf |ƒ‚t||ƒS )	Nz"while constructing a Python objectz+expected non-empty name appended to the tagÚ.r   Úbuiltinszcannot find module %r (%s)zmodule %r is not importedzcannot find %r in the module %r)	r   Úrsplitr®   r¯   r°   r±   ru   r
   Úgetattr)r   r²   r³   r´   Úmodule_nameZobject_namerz   Úmoduler   r   r   Úfind_python_name
  s,    "


z FullConstructor.find_python_namec             C   s2   | j |ƒ}|r$td|jd| |jƒ‚| j||jƒS )Nz while constructing a Python namez&expected the empty value, but found %r)r(   r   r   r¼   )r   Úsuffixr   r5   r   r   r   Úconstruct_python_name#  s
    
z%FullConstructor.construct_python_namec             C   s2   | j |ƒ}|r$td|jd| |jƒ‚| j||jƒS )Nz"while constructing a Python modulez&expected the empty value, but found %r)r(   r   r   rµ   )r   r½   r   r5   r   r   r   Úconstruct_python_module*  s
    
z'FullConstructor.construct_python_moduleNc             C   st   |sg }|si }| j ||jƒ}|p*t|tƒsFtd|jdt|ƒ |jƒ‚|rft|tƒrf|j|f|ž|ŽS |||ŽS d S )Nz$while constructing a Python instancezexpected a class, but found %r)r¼   r   r%   Útyper   rž   )r   r½   r   ÚargsÚkwdsÚnewobjr´   rD   r   r   r   Úmake_python_instance1  s    
z$FullConstructor.make_python_instancec             C   s„   t |dƒr|j|ƒ nji }t|tƒr8t|ƒdkr8|\}}t |dƒrP|jj|ƒ n|r^|j|ƒ x |jƒ D ]\}}t|||ƒ qhW d S )Nr�   r]   rB   )	ru   r�   r%   r¬   r$   rB   r˜   ÚitemsÚsetattr)r   ÚinstancerŸ   Ú	slotstater?   r5   r   r   r   Úset_python_instance_stateA  s    


z)FullConstructor.set_python_instance_statec             c   s>   | j ||dd�}|V  t|dƒ}| j||d�}| j||ƒ d S )NT)rÃ   r�   )r1   )rÄ   ru   r,   rÉ   )r   r½   r   rÇ   r1   rŸ   r   r   r   Úconstruct_python_objectO  s
    
z'FullConstructor.construct_python_objectc             C   sÆ   t |tƒr*| j|dd�}i }i }g }i }nJ| j|dd�}	|	jdg ƒ}|	jdi ƒ}|	jdi ƒ}|	jdg ƒ}|	jdi ƒ}| j|||||ƒ}
|r–| j|
|ƒ |r¤|
j|ƒ |rÂx|D ]}|| |
|< q®W |
S )NT)r1   rÁ   rÂ   rŸ   Ú	listitemsÚ	dictitems)r%   r)   r*   r,   ÚgetrÄ   rÉ   rJ   )r   r½   r   rÃ   rÁ   rÂ   rŸ   rË   rÌ   r5   rÇ   r?   r   r   r   Úconstruct_python_object_applyX  s*    


z-FullConstructor.construct_python_object_applyc             C   s   | j ||dd�S )NT)rÃ   )rÎ   )r   r½   r   r   r   r   Úconstruct_python_object_new{  s    z+FullConstructor.construct_python_object_new)F)F)NNFF)F)r
   r   r   r¦   r§   r¨   r©   r«   r­   rµ   r¼   r¾   r¿   rÄ   rÉ   rÊ   rÎ   rÏ   r   r   r   r   r   Ú  s   


	
#ztag:yaml.org,2002:python/noneztag:yaml.org,2002:python/boolztag:yaml.org,2002:python/strz tag:yaml.org,2002:python/unicodeztag:yaml.org,2002:python/bytesztag:yaml.org,2002:python/intztag:yaml.org,2002:python/longztag:yaml.org,2002:python/floatz tag:yaml.org,2002:python/complexztag:yaml.org,2002:python/listztag:yaml.org,2002:python/tupleztag:yaml.org,2002:python/dictztag:yaml.org,2002:python/name:z tag:yaml.org,2002:python/module:z tag:yaml.org,2002:python/object:z$tag:yaml.org,2002:python/object/new:c                   s6   e Zd Z‡ fdd„Z‡ fdd„Zd	‡ fdd„	Z‡  ZS )
r   c                s   t t| ƒj||dd�S )NT)r´   )rH   r   rµ   )r   r²   r³   )r'   r   r   rµ   À  s    z$UnsafeConstructor.find_python_modulec                s   t t| ƒj||dd�S )NT)r´   )rH   r   r¼   )r   r²   r³   )r'   r   r   r¼   Ã  s    z"UnsafeConstructor.find_python_nameNFc                s   t t| ƒj|||||dd�S )NT)r´   )rH   r   rÄ   )r   r½   r   rÁ   rÂ   rÃ   )r'   r   r   rÄ   Æ  s    
z&UnsafeConstructor.make_python_instance)NNF)r
   r   r   rµ   r¼   rÄ   r¥   r   r   )r'   r   r   ¾  s   z&tag:yaml.org,2002:python/object/apply:c               @   s   e Zd ZdS )r   N)r
   r   r   r   r   r   r   r   Ð  s   ),Ú__all__ÚerrorÚnodesÚcollections.abcr9   r�   rv   rx   r¢   r°   r-   ZMarkedYAMLErrorr   r   r   rE   rO   rX   rl   rp   r{   r”   r•   r–   r™   rš   r›   rœ   r¡   r   r¦   r§   r¨   r©   r«   r­   rF   r¾   r¿   rÊ   rÏ   r   rÎ   r   r   r   r   r   Ú<module>   sÖ   8    %