o
    tyi1                     @   s   d dl mZmZ d dlmZm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Zd dlZejd  dkr;eZejdd	 d
k rSd dlmZ G dd deZneZG dd deZG dd deZdS )    )CommentedSeqCommentedMap)raise_type_errorYAMLSerializationError)	YAMLChunk)StrictYAMLDumper)dumpscalarstringcopyN      )r      )OrderedDictc                   @   s   e Zd Zdd ZdS )r   c                 C   s    dd dd |  D  d S )N{z, c                 s   s(    | ]\}}d  t|t|V  qdS )z{}: {}N)formatrepr).0kv r   \/home/ubuntu/maya3_transcribe/venv/lib/python3.10/site-packages/strictyaml/representation.py	<genexpr>   s   & z'OrderedDict.__repr__.<locals>.<genexpr>})joinitemsselfr   r   r   __repr__   s   zOrderedDict.__repr__N)__name__
__module____qualname__r   r   r   r   r   r      s    r   c                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
YAMLIteratorc                 C   s   || _ d| _d S )Nr   )_yaml_object_index)r   yaml_objectr   r   r   __init__   s   
zYAMLIterator.__init__c                 C   s   | S Nr   r   r   r   r   __iter__"   s   zYAMLIterator.__iter__c                 C      |   S r'   )__next__r   r   r   r   next%      zYAMLIterator.nextc                 C   s0   | j t| jkr
t| j d | _ | j| j d  S )N   )r$   lenr#   StopIterationr   r   r   r   r*   (   s   zYAMLIterator.__next__N)r   r    r!   r&   r(   r+   r*   r   r   r   r   r"      s
    r"   c                   @   s  e Zd ZdZdWddZdd Zdd Zd	d
 Zdd Ze	dd Z
dd Ze	dd Ze	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( Zd)d* Zd+d, Zd-d. Zd/d0 Zd1d2 Zd3d4 Zd5d6 ZdWd7d8Zd9d: Z d;d< Z!e	d=d> Z"e	d?d@ Z#dAdB Z$dCdD Z%dEdF Z&e	dGdH Z'dIdJ Z(dKdL Z)dMdN Z*e	dOdP Z+dQdR Z,dSdT Z-dUdV Z.dS )XYAMLa   
    A YAML object represents a block of YAML which can be:

    * Used to extract parsed data from the YAML (.data).
    * Used to render to a string of YAML, with comments (.as_yaml()).
    * Revalidated with a stricter schema (.revalidate(schema)).
    Nc                 C   s   t |tr:|| _|| _| r%||| _t | jtr | jj| _|j| _	nAt |
 tr1|
 jn|
 | _d | _	n,t |trV|j| _|d urI|n|j| _|j| _|j	| _	nt|| _|| _|| _t|| _	d | _t | jtrqJ d S r'   )
isinstancer   _chunk
_validator	is_scalarvalidate_valuer0   contents_textstrictparsed	validatorunicode_selected_validator)r   valuer:   r   r   r   r&   9   s0   






zYAML.__init__c                 C   
   t | jS r'   )intr6   r   r   r   r   __int__V   s   
zYAML.__int__c                 C   sT   |   stdt| jt| jtttt	t
jfv r t| jS tt| dd d S )Nz,Cannot cast mapping/sequence '{0}' to stringstrz&str(yamlobj.data) or str(yamlobj.text))r4   	TypeErrorr   r   r6   typer;   rA   r?   floatdecimalDecimalr   r   r   r   r   __str__Z   s   

zYAML.__str__c                 C   r)   r'   )rG   r   r   r   r   __unicode__f   r,   zYAML.__unicode__c                 C   s4   |   r|| jj| _n	|| j}|j| _|| _d S r'   )r4   r2   r6   r<   r3   )r   schemaresultr   r   r   
revalidatei   s
   

zYAML.revalidatec                 C   sr   t | jtrt }| j D ]\}}	 |j||j< q|S t | jtr*dd | jD S t | jtjr6t	| jS | jS )a=  
        Returns raw data representation of the document or document segment.

        Mappings are rendered as ordered dicts, sequences as lists and scalar values
        as whatever the validator returns (int, string, etc.).

        If no validators are used, scalar values are always returned as strings.
        c                 S   s   g | ]}|j qS r   data)r   itemr   r   r   
<listcomp>   s    zYAML.data.<locals>.<listcomp>)
r1   r6   r   r   r   rM   r   r	   ScalarStringrA   )r   mappingkeyr=   r   r   r   rM   q   s   

z	YAML.datac                 C      | j jS )z
        Returns strictyaml.ruamel CommentedSeq/CommentedMap objects
        with comments. This can be fed directly into a strictyaml.ruamel
        dumper.
        )r2   r7   r   r   r   r   as_marked_up   s   zYAML.as_marked_upc                 C   
   | j  S )z_
        Return line number that the element starts on (including preceding comments).
        )r2   
start_liner   r   r   r   rV         
zYAML.start_linec                 C   rU   )z\
        Return line number that the element ends on (including trailing comments).
        )r2   end_liner   r   r   r   rX      rW   zYAML.end_linec                 C   rU   )z
        Return a string of the lines which make up the selected line
        including preceding and trailing comments.
        )r2   linesr   r   r   r   rY      rW   z
YAML.linesc                 C      | j |S r'   )r2   lines_beforer   how_manyr   r   r   r[         zYAML.lines_beforec                 C   rZ   r'   )r2   lines_afterr\   r   r   r   r_      r^   zYAML.lines_afterc                 C   r>   r'   )rD   r6   r   r   r   r   	__float__      
zYAML.__float__c                 C   s   d | jS )Nz	YAML({0}))r   rM   r   r   r   r   r      r^   zYAML.__repr__c                 C   s&   t | jtr	| jS tt| dd d S )Nboolz(bool(yamlobj.data) or bool(yamlobj.text))r1   r6   rb   r   r   r   r   r   r   __bool__   s
   
zYAML.__bool__c                 C   sD   t |tr|j}|  r | jd ur| jjn| jj}|t|jS |S r'   )r1   r0   rM   
is_mappingr<   key_validatorr3   r   )r   indexre   r   r   r   _strictindex   s   

zYAML._strictindexc                 C   r)   r'   )rc   r   r   r   r   __nonzero__   r,   zYAML.__nonzero__c                 C   s   | j | | S r'   )r6   rg   )r   rf   r   r   r   __getitem__   s   zYAML.__getitem__c           
      C   s  |  |}t|tr| j||}| |}nB| j}t|tr$|||< nt|tr8t	||kr3t
d|||< ntt|t| j|}| |}| j||| }| |}| j}	|j| _|j| _|j| _|j| _| jj|	d|jj | jjj|	d| dd |	j| j_|	j| j_d S )NzPcannot extend list via __setitem__.  Instead, replace whole list on parent node._ruamelparsed_strictparsedT)	strictdoc)rg   r1   r0   r2   forkr3   rM   dictlistr.   r   NotImplementedErrorr   r   to_yamlr6   r8   r<   pointersetr7   rj   rk   )
r   rf   r=   strictindex
yaml_value	new_valueold_datayaml_value_reprforked_chunk	old_chunkr   r   r   __setitem__   s6   








zYAML.__setitem__c                 C   s(   |  |}| j|= | jj| j|= d S r'   )rg   r6   r2   r7   ruamelindex)r   rf   rt   r   r   r   __delitem__   s   
zYAML.__delitem__c                 C   r>   r'   )hashr6   r   r   r   r   __hash__  ra   zYAML.__hash__c                 C   r>   r'   )r.   r6   r   r   r   r   __len__  ra   zYAML.__len__c                 C   s.   t |  tdd}tjd dkr|S |dS )z>
        Render the YAML node and subnodes as string.
        T)Dumperallow_unicoder   r   utf8)r   rT   r   sysversion_infodecode)r   dumpedr   r   r   as_yaml	  s   zYAML.as_yamlc                    6   t  jtstdt  fdd j D S )Nz&{0} not a mapping, cannot use .items()c                    s   g | ]\}}| j | fqS r   r6   r   rR   r=   r   r   r   rO     s    zYAML.items.<locals>.<listcomp>r1   r6   r   rB   r   r   r   r   r   r   r   r     s   z
YAML.itemsc                 C   s2   t | jtstdt| dd | j D S )Nz%{0} not a mapping, cannot use .keys()c                 S   s   g | ]\}}|qS r   r   )r   rR   _r   r   r   rO     s    zYAML.keys.<locals>.<listcomp>r   r   r   r   r   keys  s   z	YAML.keysc                    r   )Nz'{0} not a mapping, cannot use .values()c                    s   g | ]	\}} j | qS r   r   r   r   r   r   rO     s    zYAML.values.<locals>.<listcomp>r   r   r   r   r   values  s
   zYAML.valuesc                 C   s:   t | jtstdt| || j v r| j| S |S )Nz${0} not a mapping, cannot use .get())r1   r6   r   rB   r   r   r   )r   rf   defaultr   r   r   get!  s   zYAML.getc                 C   s8   t | jtr|| jv S t | jtr||  v S || jv S r'   )r1   r6   r   r   r   )r   rN   r   r   r   __contains__&  s
   

zYAML.__contains__c                 C   s6   |   rt| S |  rt|  S tdt| )Nz&{0} is a scalar value, cannot iterate.)is_sequencer"   rd   r   rB   r   r   r   r   r   r   r(   .  s
   zYAML.__iter__c                 C      | j S r'   )r3   r   r   r   r   r:   6     zYAML.validatorc                 C   sB   t | jtrtdt| t | jtrtdt| | jS )zQ
        Return string value of scalar, whatever value it was parsed as.
        z${0} is a mapping, has no text value.z%{0} is a sequence, has no text value.)r1   r6   r   rB   r   r   r   r8   r   r   r   r   text:  s
   z	YAML.textc                 C   s   t | S r'   r
   r   r   r   r   r   E  r,   z	YAML.copyc                 C   s6   t | jtst | jtrtdt| j| j|kS Nz{0} not an orderable type.r1   r6   r   r   rB   r   r   r   valr   r   r   __gt__H  
   
zYAML.__gt__c                 C   s6   t | jtst | jtrtdt| j| j|k S r   r   r   r   r   r   __lt__O  r   zYAML.__lt__c                 C   r   r'   r   r   r   r   r   r=   V  r   z
YAML.valuec                 C      t | jtS r'   )r1   r6   r   r   r   r   r   rd   Z  r^   zYAML.is_mappingc                 C   r   r'   )r1   r6   r   r   r   r   r   r   ]  r^   zYAML.is_sequencec                 C   s   |    o	|   S r'   )rd   r   r   r   r   r   r4   `  s   zYAML.is_scalarc                 C   s(   t | jttfrtdt| | jS )Nz{0} has no scalar value.r   r   r   r   r   scalarc  s   zYAML.scalarc                 C   rS   r'   )r2   whole_documentr   r   r   r   r   i  r,   zYAML.whole_documentc                 C   s
   | j |kS r'   rL   r   r=   r   r   r   __eq__l  ra   zYAML.__eq__c                 C   s
   | j |kS r'   rL   r   r   r   r   __ne__o  ra   zYAML.__ne__r'   )/r   r    r!   __doc__r&   r@   rG   rH   rK   propertyrM   rT   rV   rX   rY   r[   r_   r`   r   rc   rg   rh   ri   r{   r}   r   r   r   r   r   r   r   r   r(   r:   r   r   r   r   r=   rd   r   r4   r   r   r   r   r   r   r   r   r0   0   sf    



/





r0   )strictyaml.ruamel.commentsr   r   strictyaml.exceptionsr   r   strictyaml.yamllocationr   strictyaml.dumperr   strictyaml.ruamelr   r	   r   rE   r   r   rA   r;   collectionsr   OrderedDictBasern   objectr"   r0   r   r   r   r   <module>   s     	