o
    <i!                     @   sr   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
m	Z	 d dlZejd  dkr/eZG dd	 d	eZdS )
    )CommentedSeqCommentedMap)YAMLValidationError)YAMLPointer)utils)deepcopycopyN   c                   @   s.  e Zd ZdZ				dBddZdCddZdCddZd	d
 Zdd Zdd Z	dd Z
dd ZdDddZdd Zdd Zedd Zedd Zedd Zd d! Zd"d# Zed$d% Zd&d' Zd(d) Zd*d+ Zd,d- Zd.d/ ZdCd0d1Zd2d3 Zd4d5 Zd6d7 Zd8d9 Zd:d; Z d<d= Z!ed>d? Z"d@dA Z#dS )E	YAMLChunka  
    Represents a section of the document with references to the ruamel
    parsed document and the strictparsed document.

    Most operations done by validators on the document are done using this object.

    Before validation the strictparsed document will be identical to the
    ruamelparsed document. After it will contain CommentedMaps, CommentedSeqs
    and YAML objects.
    Nc                 C   sR   || _ |d u rt|n|| _|d ur|nt | _|| _|d u r$i | _d S || _d S N)_ruamelparsedr   _strictparsedr   _pointer_label_key_association)selfruamelparsedpointerlabelstrictparsedkey_association r   T/home/ubuntu/veenaModal/venv/lib/python3.10/site-packages/strictyaml/yamllocation.py__init__   s   zYAMLChunk.__init__c                 C   s&   t ||d ur
|| d|  | )N	found {0})r   formatfound)r   	expectingr   r   r   r   expecting_but_found+   s   
zYAMLChunk.expecting_but_foundc                 C   s   | j d||d d S )Nzwhile parsing {0})r   )r   r   )r   whatr   r   r   r   while_parsing_found2   s   zYAMLChunk.while_parsing_foundc                    s   | j  j| jdd}t|dr|jn|  fdd}| j  r(| | j j< d S | j  r7| || j j	< d S | j 
 rO|| j j	} | } |= | |< d S d S )NT	strictdoc_valuec                    s>   |    v r| S    D ]}t|dr|j| kr|  S qd S )Nr#   )keyshasattrtext)
string_keykeycurrent_parsedr   r   actual_key_from_string_key;   s   

z5YAMLChunk.process.<locals>.actual_key_from_string_key)r   parentgetr   r%   r#   is_index
last_indexis_vallast_regularkeyis_key)r   new_itemr   r+   r(   existing_valr   r)   r   process5   s"   
	


zYAMLChunk.processc                 C      t | jtS r   )
isinstancecontentsr   r   r   r   r   is_sequenceP      zYAMLChunk.is_sequencec                 C   r6   r   )r7   r8   r   r9   r   r   r   
is_mappingS   r;   zYAMLChunk.is_mappingc                 C   s   t | jttf S r   )r7   r8   r   r   r9   r   r   r   	is_scalarV      zYAMLChunk.is_scalarc                 C   sJ   |   rdS |  rdS | jdkrdS t| jrdS t| jr#dS dS )Nz
a sequencez	a mapping za blank stringzan arbitrary integerzan arbitrary numberzarbitrary text)r:   r<   r8   r   
is_integer
is_decimalr9   r   r   r   r   Y   s   
zYAMLChunk.foundwhen expecting a sequencec                    s:      s |d    fddtt jD S )Nr   c                    s   g | ]}  |qS r   )index).0ir9   r   r   
<listcomp>j   s    z-YAMLChunk.expect_sequence.<locals>.<listcomp>)r:   r   r   r   rangelenr8   )r   r   r   r9   r   expect_sequenceg   s   zYAMLChunk.expect_sequencec                    sD      s dd    fddt j    D S )Nzwhen expecting a mappingr   c                    s.   g | ]\}}  |t| t|fqS r   )r(   unicodeval)rD   regular_keyvalidated_keyr9   r   r   rF   q   s    z,YAMLChunk.expect_mapping.<locals>.<listcomp>)r<   r   r   r   zipr8   r$   r   r9   r   r9   r   expect_mappingl   s   
zYAMLChunk.expect_mappingc                 C   s,   |   s| d|d|   d S d S )Nzwhen expecting {0}r   )r=   r   r   r   )r   r   r   r   r   expect_scalar{   s
   zYAMLChunk.expect_scalarc                 C      | j S r   )r   r9   r   r   r   r         zYAMLChunk.labelc                 C   rQ   r   )r   r9   r   r   r   whole_document   rR   zYAMLChunk.whole_documentc                 C   rQ   r   )r   r9   r   r   r   r      rR   zYAMLChunk.pointerc                 C   s|   t t| j| j| jt| jd}|  r(|j|dt	  |jj|dt	 dd |
 |j| |< t|
 | |< |S )z
        Return a chunk referring to the same location in a duplicated document.

        Used when modifying a YAML chunk so that the modification can be validated
        before changing it.
        )r   r   r   r   r   Tr!   )r
   r   r   r   r   r   r   r=   setr   as_marked_upr8   ruamelindexr   )r   strictindex	new_valueforked_chunkr   r   r   fork   s   
zYAMLChunk.forkc                 C   s   || j |< d S r   r   )r   unprocessed_keyprocessed_keyr   r   r   add_key_association      zYAMLChunk.add_key_associationc                 C   rQ   r   r[   r9   r   r   r   r      rR   zYAMLChunk.key_associationc                 C   s   |   r#| j D ]\}}| ||j|j | || q	dS |  r;t| jD ]\}}| 	|| q,dS | j|j dS )zr
        Link one YAML chunk to another.

        Used when inserting a chunk of YAML into another chunk.
        N)
r<   r8   itemsr(   r   make_child_ofrK   r:   	enumeraterC   )r   chunkr(   valuerC   itemr   r   r   ra      s   zYAMLChunk.make_child_ofc                 C   s   t | j|| j| jt| jdS )z:
        Get a YAMLChunk referenced by a pointer.
        )r   r   r   r   )r
   r   r   r   r   r   )r   r   r   r   r   _select   s   zYAMLChunk._selectc                 C   s   |  | j| |S )zC
        Return a chunk in a sequence referenced by index.
        )rf   r   rC   rV   r   rW   r   r   r   rC      s   zYAMLChunk.indexc                 C   s   |   r| j||S |S )z
        Get the ruamel equivalent of a strict parsed index.

        E.g. 0 -> 0, 1 -> 2, parsed-via-slugify -> Parsed via slugify
        )r<   r   r-   rg   r   r   r   rV      s
   zYAMLChunk.ruamelindexc                 C   s   |  |}| | j||S )zU
        Return a chunk referencing a value in a mapping with the key 'key'.
        )rV   rf   r   rK   )r   	strictkey	ruamelkeyr   r   r   rK      s   
zYAMLChunk.valc                 C      |  | j||S )zT
        Return a chunk referencing a key in a mapping with the name 'key'.
        )rf   r   r(   )r   r(   rh   r   r   r   r(         zYAMLChunk.keyc                 C   rj   )zL
        Return a chunk referencing a slice of a scalar text value.
        )rf   r   	textslice)r   startendr   r   r   rl      rk   zYAMLChunk.textslicec                 C      | j | jS r   )r   
start_liner   r9   r   r   r   rp      r_   zYAMLChunk.start_linec                 C   ro   r   )r   end_liner   r9   r   r   r   rq      r_   zYAMLChunk.end_linec                 C   ro   r   )r   linesr   r9   r   r   r   rr      r_   zYAMLChunk.linesc                 C      | j | j|S r   )r   lines_beforer   r   how_manyr   r   r   rt         zYAMLChunk.lines_beforec                 C   rs   r   )r   lines_afterr   ru   r   r   r   rx      rw   zYAMLChunk.lines_afterc                 C   ro   r   )r   r-   r   r9   r   r   r   r8      s   zYAMLChunk.contentsc                 C   s   | j j| jddS )NTr!   )r   r-   r   r9   r   r   r   r      r>   zYAMLChunk.strictparsed)NNNNr   )rB   )$__name__
__module____qualname____doc__r   r   r    r5   r:   r<   r=   r   rI   rO   rP   propertyr   rS   r   rZ   r^   r   ra   rf   rC   rV   rK   r(   rl   rp   rq   rr   rt   rx   r8   r   r   r   r   r   r
      sT    









r
   )strictyaml.ruamel.commentsr   r   strictyaml.exceptionsr   strictyaml.yamlpointerr   
strictyamlr   r   r   sysversion_infostrrJ   objectr
   r   r   r   r   <module>   s    