o
    ˳i,                  	   @   s  d Z ddlZddlmZ ddlmZ ddlmZmZ ddl	m
Z
 ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ejdd dkrrddl m!Z! nddl"m!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,G d%d& d&ee,eee#eZ-d1d(d)Z.	*d2d+d,Z/	*d2d-d.Z0d1d/d0Z1dS )3z
Parsing code for strictyaml.
    N)ruamel)
exceptions)CommentedSeqCommentedMap)Any)	YAMLChunk)utils)Reader)RoundTripScanner)RoundTripParser)Composer)RoundTripConstructor)VersionedResolver)MappingNode)PY2)ConstructorError   )      )Hashablec                   @   s   e Zd Zi ZdddZdS )StrictYAMLConstructorFc                 C   s*  t |tstd d d|j |j| |}|jr3||jd d  t|jdkr3|j	|jd dd |j
rGddlm} ||j
sG||j
 |jD ]\}}| j|dd}t |tsct |trct|}trzt| W n% ty }	 ztd|jd	|	 |jd }	~	ww t |tstd|jd
|j| j||d}
|jr|j|j|d |jr|j|j|d |||jj|jj|jj|jjg ||v r| j|j_| j|j_td|jd||j|
||< qJ|r|| | j sd }dd |jD D ]}|d u r|jj}|jj|krt!d|jd|jqd S d S )Nz%expected a mapping node, but found %sr   T)clearr   )templated_id)deepzwhile constructing a mappingzfound unacceptable key (%s)zfound unhashable key)key)valuezWhile parsingzDuplicate key '{0}' foundc                 S   s&   g | ]}t |d  tjjr|d  qS )   )
isinstance
ruamelyamlnodesr   ).0	nodegroup r"   E/home/ubuntu/.local/lib/python3.10/site-packages/strictyaml/parser.py
<listcomp>x   s    z;StrictYAMLConstructor.construct_mapping.<locals>.<listcomp>zAFound mapping with indentation inconsistent with previous mapping)"r   r   r   id
start_markflatten_mappingcomment_yaml_add_commentlenyaml_end_comment_extendanchorstrictyaml.ruamel.serializerr   yaml_set_anchorr   construct_objectr   listtupler   hash	TypeError_yaml_set_kv_line_collinecolumnlabelnameend_markr   DuplicateKeysDisallowedformatadd_yaml_mergeallow_flow_style!InconsistentIndentationDisallowed)selfnodemaptypr   	merge_mapr   key_node
value_noder   excr   previous_indentationr"   r"   r#   construct_mapping&   s   





	




z'StrictYAMLConstructor.construct_mappingN)F)__name__
__module____qualname__yaml_constructorsrG   r"   r"   r"   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: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S )StrictYAMLScannerc                 G   s   |   r|   |   s|   | jrs|sdS |D ]Y}t| jd |rr| jd }| j|j_| j|j_t|t	jj
rCtd|jd|j| js^t|t	jjsTt|t	jjr^td|jd|jt|t	jjrotd|jd|j dS qdS )NTr   zWhile scanningz<Found disallowed tag tokens (do not specify types in markup)zbFound ugly disallowed JSONesque flow mapping (surround with ' and ' to make text appear literally)z]Found confusing disallowed anchor token (surround with ' and ' to make text appear literally)F)need_more_tokensfetch_more_tokens_gather_commentstokensr   r7   r&   r8   r9   r   TagTokenr   TagTokenDisallowedr=   FlowMappingStartTokenFlowSequenceStartTokenFlowMappingDisallowedAnchorTokenAnchorTokenDisallowed)r?   choiceschoicetokenr"   r"   r#   check_token   sV   


#zStrictYAMLScanner.check_tokenN)rH   rI   rJ   r[   r"   r"   r"   r#   rL      s    rL   c                   @   s   e Zd ZdddZdS )StrictYAMLLoaderNc                 C   s^   t j| || d tj| | d tj| | d tj| | d tj| || d tj| || d d S )N)loader)preserve_quotesr]   )r	   __init__rL   r   r   r   r   )r?   streamversionr^   r"   r"   r#   r_      s   zStrictYAMLLoader.__init__)NN)rH   rI   rJ   r_   r"   r"   r"   r#   r\      s    r\   <unicode string>c                 C   s$   |du rt  }|t|| |dS )z~
    Translate dicts/lists and scalar (string/bool/float/int/etc.) values into a
    YAML object which can be dumped out.
    Nr7   )r   r   to_yaml)dataschemar7   r"   r"   r#   as_document  s   rg   Fc              
   C   s   t | s	tdtdtf||d}z	tj| |d}W n! tjy= } z|jd ur.||j_	|j
d ur7||j
_	|d }~ww t|ttfvrH| }|d u rOt }|t||dS )Nz0StrictYAML can only read a string of valid YAML.DynamicStrictYAMLLoader)r7   r=   )Loaderrc   )r   	is_stringr3   typer\   r   load	YAMLErrorcontext_markr8   problem_markr   r   r   r   )yaml_stringrf   r7   r=   rh   documentparse_errorr"   r"   r#   generic_load  s,   


	rs   c                 C   s   t | |||dS )z
    Parse the first YAML document in a string
    and produce corresponding YAML object.

    If allow_flow_style is set to True, then flow style is allowed.
    )rf   r7   r=   rs   )rp   rf   r7   r=   r"   r"   r#   
dirty_load0  s   	ru   c                 C   s   t | ||dS )z^
    Parse the first YAML document in a string
    and produce corresponding YAML object.
    )rf   r7   rt   )rp   rf   r7   r"   r"   r#   rl   >  s   rl   )Nrb   )Nrb   F)2__doc__sys
strictyamlr   r   r   strictyaml.ruamel.commentsr   r   strictyaml.any_validatorr   strictyaml.yamllocationr   r   strictyaml.ruamel.readerr	   strictyaml.ruamel.scannerr
   strictyaml.ruamel.parserr   strictyaml.ruamel.composerr   strictyaml.ruamel.constructorr   strictyaml.ruamel.resolverr   strictyaml.ruamel.nodesr   strictyaml.ruamel.compatr   r   version_infocollections.abcr   collectionsr   add_constructorconstruct_yaml_strconstruct_yaml_omapconstruct_yaml_pairsconstruct_yaml_setconstruct_yaml_seqconstruct_yaml_mapconstruct_undefinedrL   r\   rg   rs   ru   rl   r"   r"   r"   r#   <module>   s    f
0

"
