a
    QfXc                     @   s6  g d 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dej edej edej edej edej edej edej edej edej edej edej edej edej G dd deZedej edej edej edej edej edej edej  ed ej ed!ej! ed"ej ed#ej" ed$ej e#d%ej$ e#d&ej% e#d'ej& e#d(ej' e#d)ej( dS )*)BaseConstructorSafeConstructorConstructorConstructorError   )*    Nc                   @   s   e Zd ZdS )r   N)__name__
__module____qualname__ r   r   g/oak/stanford/groups/akundaje/marinovg/programs/SPAdes-3.13.0-Linux/share/spades/pyyaml3/constructor.pyr   
   s   r   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   |   S N)
check_noder   r   r   r   
check_data   s    zBaseConstructor.check_datac                 C   s   |   r| |  S d S r   )r   construct_documentget_noder   r   r   r   get_data   s    zBaseConstructor.get_datac                 C   s   |   }|d ur| |S d S r   )get_single_noder   r   noder   r   r   get_single_data!   s    
zBaseConstructor.get_single_datac                 C   sH   |  |}| jr2| j}g | _|D ]}|D ]}q(q q
i | _i | _d| _|S r   )construct_objectr   r   r   r   )r   r   datar   	generatordummyr   r   r   r   (   s    
z"BaseConstructor.construct_documentFc           
      C   s  || j v r| j | S |r$| j}d| _|| jv r>td d d|jd | j|< d }d }|j| jv rj| j|j }n| jD ]2}|j|rp|jt	|d  }| j| } qqpd | jv r|j}| jd  }nRd | jv r| jd  }n<t
|tr| jj}n(t
|tr| jj}nt
|tr| jj}|d u r(|| |}n|| ||}t
|tjrp|}t|}| jrd|D ]}	qZn| 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   5   sZ    













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#   valuer   r   r   r   r,   g   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 )r5   )r   ).0childr5   r   r   r   
<listcomp>s   s   z6BaseConstructor.construct_sequence.<locals>.<listcomp>)r)   r-   r   r8   r#   r9   r   r   r5   r   r=   r   r.   n   s    
z"BaseConstructor.construct_sequencec                 C   sz   t |ts td d d|j |ji }|jD ]J\}}| j||d}t |tjs^td|jd|j| j||d}|||< q*|S )N%expected a mapping node, but found %sr:   while constructing a mappingzfound unhashable key)	r)   r/   r   r8   r#   r9   r   collectionsHashable)r   r   r5   mappingkey_node
value_nodekeyr9   r   r   r   r0   v   s    

z!BaseConstructor.construct_mappingc                 C   sb   t |ts td d d|j |jg }|jD ]2\}}| j||d}| j||d}|||f q*|S )Nr@   r:   )r)   r/   r   r8   r#   r9   r   r4   )r   r   r5   pairsrE   rF   rG   r9   r   r   r   construct_pairs   s    
zBaseConstructor.construct_pairsc                 C   s$   d| j vr| j | _|| j|< d S )Nr%   )__dict__r%   copy)clsr$   r6   r   r   r   add_constructor   s    
zBaseConstructor.add_constructorc                 C   s$   d| j vr| j | _|| j|< d S )Nr&   )rJ   r&   rK   )rL   r7   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.   r0   rI   classmethodrM   rO   r   r   r   r   r      s    
2



r   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
e
e
e
 krne
e
9 Z
qXe
 e
 Zdd Zdd Ze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r2|jD ] \}}|jdkr| |  S qt |S )Ntag:yaml.org,2002:value)r)   r/   r9   r$   r,   super)r   r   rE   rF   r+   r   r   r,      s
    

z SafeConstructor.construct_scalarc           	      C   s  g }d}|t |jk r|j| \}}|jdkr|j|= t|trZ| | ||j nt|trg }|jD ]<}t|tstd|j	d|j
 |j	| | ||j qn|  |D ]}|| qntd|j	d|j
 |j	q|jdkrd|_|d7 }q|d7 }q|r||j |_d S )	Nr   ztag:yaml.org,2002:mergerA   z,expected a mapping for merging, but found %sz@expected a mapping or list of mappings for merging, but found %srQ   tag:yaml.org,2002:strr   )r(   r9   r$   r)   r/   flatten_mappingextendr-   r   r#   r8   r4   reverse)	r   r   mergeindexrE   rF   Zsubmergesubnoder9   r   r   r   rU      sJ    









zSafeConstructor.flatten_mappingFc                    s$   t |tr| | t j||dS )Nr:   )r)   r/   rU   rR   r0   r?   rS   r   r   r0      s    

z!SafeConstructor.construct_mappingc                 C   s   |  | d S r   r,   r   r   r   r   construct_yaml_null   s    
z#SafeConstructor.construct_yaml_nullT)yesnotruefalseonoffc                 C   s   |  |}| j|  S r   )r,   bool_valueslower)r   r   r9   r   r   r   construct_yaml_bool   s    
z#SafeConstructor.construct_yaml_boolc                 C   s  |  |}|dd}d}|d dkr*d}|d dv rB|dd  }|dkrNdS |d	rn|t|d
d  d
 S |dr|t|d
d  d S |d dkr|t|d S d|v  rdd |dD }|  d}d}|D ]}||| 7 }|d9 }q|| S |t| S d S )N_ r   r   -+-0Z0b   0x      :c                 S   s   g | ]}t |qS r   )intr;   partr   r   r   r>          z6SafeConstructor.construct_yaml_int.<locals>.<listcomp><   )r,   replacer'   rq   splitrW   r   r   r9   signdigitsbaseZdigitr   r   r   construct_yaml_int   s2    




z"SafeConstructor.construct_yaml_intgu <7~c                 C   s   |  |}|dd }d}|d dkr.d}|d dv rF|dd  }|dkrX|| j S |d	krf| jS d
|v rdd |d
D }|  d}d}|D ]}||| 7 }|d9 }q|| S |t| S d S )Nrf   rg   r   r   rh   ri   rj   z.infz.nanrp   c                 S   s   g | ]}t |qS r   )floatrr   r   r   r   r>     rt   z8SafeConstructor.construct_yaml_float.<locals>.<listcomp>g        ru   )r,   rv   rd   	inf_value	nan_valuerw   rW   r}   rx   r   r   r   construct_yaml_float   s*    


z$SafeConstructor.construct_yaml_floatc              
   C   s   z|  |d}W n8 tyL } z td d d| |jW Y d }~n
d }~0 0 z&ttdrft|W S t|W S W n: t	j
y } z td d d| |jW Y d }~n
d }~0 0 d S Nasciiz,failed to convert base64 data into ascii: %sdecodebytesz failed to decode base64 data: %sr,   encodeUnicodeEncodeErrorr   r#   hasattrbase64r   decodestringbinasciiErrorr   r   r9   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}| }t|d }t|d }t|d }|d sZt|||S t|d }t|d }	t|d }
d}|d r|d d d	 }t|d	k r|d
7 }qt|}d }|d rt|d }t|d pd}tj	||d}|d dkr| }t|||||	|
|}|r(||8 }|S )Nyearmonthdayhourminutesecondr   fraction   rk   Ztz_signtz_hour	tz_minute)hoursminutesrh   )
r,   timestamp_regexpmatchr9   	groupdictrq   datetimedater(   	timedelta)r   r   r9   r   valuesr   r   r   r   r   r   r   deltar   r   r    r   r   r   construct_yaml_timestamp4  s8    


z(SafeConstructor.construct_yaml_timestampc                 c   s   g }|V  t |ts,td|jd|j |j|jD ]}t |tsXtd|jd|j |jt|jdkrtd|jdt|j |j|jd \}}| |}| |}|	||f q2d S )Nz!while constructing an ordered map!expected a sequence, but found %s,expected a mapping of length 1, but found %sr   2expected a single mapping item, but found %d itemsr   
r)   r-   r   r#   r8   r9   r/   r(   r   r4   )r   r   ZomaprZ   rE   rF   rG   r9   r   r   r   construct_yaml_omapR  s*    




z#SafeConstructor.construct_yaml_omapc                 c   s   g }|V  t |ts,td|jd|j |j|jD ]}t |tsXtd|jd|j |jt|jdkrtd|jdt|j |j|jd \}}| |}| |}|	||f q2d S )Nzwhile constructing pairsr   r   r   r   r   r   )r   r   rH   rZ   rE   rF   rG   r9   r   r   r   construct_yaml_pairsh  s*    




z$SafeConstructor.construct_yaml_pairsc                 c   s$   t  }|V  | |}|| d S r   )setr0   updater   r   r    r9   r   r   r   construct_yaml_set}  s    
z"SafeConstructor.construct_yaml_setc                 C   s
   |  |S r   r[   r   r   r   r   construct_yaml_str  s    z"SafeConstructor.construct_yaml_strc                 c   s   g }|V  | | | d S r   )rV   r.   )r   r   r    r   r   r   construct_yaml_seq  s    z"SafeConstructor.construct_yaml_seqc                 c   s"   i }|V  |  |}|| d S r   )r0   r   r   r   r   r   construct_yaml_map  s    
z"SafeConstructor.construct_yaml_mapc                 c   sN   | |}|V  t|dr4| j|dd}|| n| |}|j| d S )N__setstate__Tr:   )__new__r   r0   r   rJ   r   )r   r   rL   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   construct_undefined  s    z#SafeConstructor.construct_undefined)F)r   r	   r
   r,   rU   r0   r\   rc   re   r|   r~   r   r   r   recompileXr   r   r   r   r   r   r   r   r   r   __classcell__r   r   rS   r   r      s@   #	

	
r   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:setrT   z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 Z	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
   |  |S r   r[   r   r   r   r   construct_python_str  s    z Constructor.construct_python_strc                 C   s
   |  |S r   r[   r   r   r   r   construct_python_unicode  s    z$Constructor.construct_python_unicodec              
   C   s   z|  |d}W n8 tyL } z td d d| |jW Y d }~n
d }~0 0 z&ttdrft|W S t|W S W n: t	j
y } z td d d| |jW Y d }~n
d }~0 0 d S r   r   r   r   r   r   construct_python_bytes  s    

z"Constructor.construct_python_bytesc                 C   s
   |  |S r   )r|   r   r   r   r   construct_python_long  s    z!Constructor.construct_python_longc                 C   s   t | |S r   )complexr,   r   r   r   r   construct_python_complex  s    z$Constructor.construct_python_complexc                 C   s   t | |S r   )tupler.   r   r   r   r   construct_python_tuple  s    z"Constructor.construct_python_tuplec              
   C   sd   |st d|d|zt| W n: tyX } z"t d|d||f |W Y d }~n
d }~0 0 tj| S )N"while constructing a Python module+expected non-empty name appended to the tagcannot find module %r (%s))r   
__import__ImportErrorsysmodules)r   namemarkr   r   r   r   find_python_module  s    zConstructor.find_python_modulec              
   C   s   |st d|d|d|v r,|dd\}}nd}|}zt| W n: tyz } z"t d|d||f |W Y d }~n
d }~0 0 tj| }t||st d|d||jf |t||S )Nz"while constructing a Python objectr   .r   builtinsr   zcannot find %r in the module %r)	r   rsplitr   r   r   r   r   r   getattr)r   r   r   module_nameZobject_namer   moduler   r   r   find_python_name  s.    

zConstructor.find_python_namec                 C   s2   |  |}|r$td|jd| |j| ||jS )Nz while constructing a Python name&expected the empty value, but found %r)r,   r   r#   r   r   suffixr   r9   r   r   r   construct_python_name  s    

z!Constructor.construct_python_namec                 C   s2   |  |}|r$td|jd| |j| ||jS )Nr   r   )r,   r   r#   r   r   r   r   r   construct_python_module  s    

z#Constructor.construct_python_moduleNFc                 C   sV   |sg }|si }|  ||j}|rDt|trD|j|g|R i |S ||i |S d S r   )r   r#   r)   typer   )r   r   r   argskwdsnewobjrL   r   r   r   make_python_instance"  s    z Constructor.make_python_instancec                 C   s   t |dr|| nfi }t|tr8t|dkr8|\}}t |drP|j| n|r^|| | D ]\}}tt	|| qfd S )Nr   rl   rJ   )
r   r   r)   r   r(   rJ   r   itemssetattrobject)r   instancer   	slotstaterG   r9   r   r   r   set_python_instance_state.  s    


z%Constructor.set_python_instance_statec                 c   s>   | j ||dd}|V  t|d}| j||d}| || d S )NTr   r   r:   )r   r   r0   r   )r   r   r   r   r5   r   r   r   r   construct_python_object<  s
    
z#Constructor.construct_python_objectc                 C   s   t |tr*| j|dd}i }i }g }i }nJ| j|dd}	|	dg }|	di }|	di }|	dg }|	di }| |||||}
|r| |
| |r|
| |r|D ]}|| |
|< q|
S )NTr:   r   r   r   	listitems	dictitems)r)   r-   r.   r0   getr   r   rV   )r   r   r   r   r   r   r   r   r   r9   r   rG   r   r   r   construct_python_object_applyE  s*    

z)Constructor.construct_python_object_applyc                 C   s   | j ||ddS )NTr   )r   )r   r   r   r   r   r   construct_python_object_newh  s    z'Constructor.construct_python_object_new)NNF)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     
	
#r   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/apply:z$tag:yaml.org,2002:python/object/new:))__all__errornodesrB   r   r   r   r   r   r1   MarkedYAMLErrorr   r   r   rM   r\   re   r|   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rO   r   r   r   r   r   r   r   r   r   <module>   s  8    