
    c%5                     &   d Z ddlmZmZ 	 ddlZddlmZ ddlm	Z	 ddlm
Z
 n## e$ r ddlmZ ddlmZ ddlm	Z	 ddlm
Z
 Y nw xY wddlZddlZddlZddlZddlZddlmZ ddlmZ dd	lmZ eZe	Ze
ZddZd Zd Z ddZ!d Z" G d de#          Z$dS )z#YAML file loading and manipulation.    )absolute_importprint_functionN)	YAMLError)CommentedMap)CommentedSeq)makedirs_ok_if_exists)rename_over_existing)	is_stringutf-8c                    | dz   t          t          j                              z   }	 t          j        |d|          5 }|                    |           |                                 |                                 d d d            n# 1 swxY w Y   t          ||            	 t          j
        |           d S # t          t          f$ r Y d S w xY w# 	 t          j
        |           w # t          t          f$ r Y w w xY wxY w)Nz.tmp-w)struuiduuid4codecsopenwriteflushcloser	   osremoveIOErrorOSError)pathcontentsencodingtmpfiles        :lib/python3.11/site-packages/anaconda_project/yaml_file.py_atomic_replacer    -   sA   
.3tz||,,
,C
[c8,, 	JJx   JJLLLJJLLL	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	S$'''	IcNNNNN! 	 	 	DD		IcNNNN! 	 	 	D	sd   C >B<C BC BC $B: :CCD C)(D )C=:D <C==D c                     |                                  dk    ri S t          t          j        t          j        j                  sJ t          j        | t          j                  S )N Loader)strip
issubclassryamlRoundTripLoaderconstructorSafeConstructorload)r   s    r   _load_stringr,   <   sZ    ~~2 B 	 %/1B1RSSSSSz(5+@AAAA    c                 B    t          j        | t           j                  S )N)Dumper)r'   dumpRoundTripDumper)yamls    r   _dump_stringr3   H   s    :d5#89999r-   c                    |t          |           }	 t          j        |t          j                   n# t          $ r}t          dt          j                   t          dt          |          z   t          j                   t          dt          j                   t          |t          j                   t          dt          |          z             d }~ww xY wt          j                            |          s.t          j                            |          }t          |           t          ||           d S )Nr#   z=ruamel.yaml bug; it failed to parse a file that it generated.)r   z  the parse error was: zGenerated file was:zFBug in ruamel.yaml library; failed to parse a file that it generated: )r3   r'   r+   r(   r   printsysstderrr   RuntimeErrorr   r   isfiledirnamer   r    )r2   filenamer   er:   s        r   
_save_filer=   L   s,    &%%n
8E$9::::: n n nMTWT^____'#a&&0szBBBB##*5555hSZ((((cfijkflfllmmmn 7>>(## ''//(++g&&&Hh'''''s    4 
CBCCc                 (   t          | d          r| j                                         t          | t                    r| D ]}t          |           d S t          | t                    r&|                                 D ]}t          |           d S d S )Nfa)hasattrr?   set_block_style
isinstancelist_block_style_all_nodesdictvalues)r2   elementvalues      r   rD   rD   a   s    tT "!!!$ * 	, 	,G"7++++	, 	,	D$		 *[[]] 	* 	*E"5))))* *	* 	*r-   c                   ,   e Zd ZdZdZd Zd Zd Zd Zd Z	d Z
ed	             Zed
             Zed             Zed             Zed             Zed             Zed             Zd Zd Zed             Zd Zd Zd Zd ZddZed             ZdS )YamlFilea  Abstract YAML file, base class for ``ProjectFile`` and ``LocalStateFile``.

    Be careful with creating your own instance of this class,
    because you have to think about when other code might load or
    save in a way that conflicts with your loads and saves.

    z# yaml file
__dummy__: dummyc                 X    || _         d| _        d| _        |                                  dS )a  Load a YamlFile with the given filename.

        Raises an exception on an IOError, but if the file is
        missing this succeeds (then creates the file if and when
        you call ``save()``).

        If the file has syntax problems, this sets the
        ``corrupted`` and ``corrupted_error_message`` properties,
        and attempts to modify the file will raise an
        exception.

        r"   r   N)r;   _previous_content_change_countr+   )selfr;   s     r   __init__zYamlFile.__init__z   s,     !!#		r-   c                    d| _         d| _        d| _        d| _        | j        dz   | _        	 t          j        | j        dd          5 }|                                }ddd           n# 1 swxY w Y   t          |          | _
        t          | j
                  | _        n# t          $ r)}|j        t          j        k    rd| _
        n|Y d}~nd}~wt           $ r{}d| _         t#          |          | _        t%          |dd          }|<|j        |j        dk    r|j        | _        |j        |j        dk    r|j        | _        d| _
        Y d}~nd}~ww xY w| j
        | j         rt+                      | _
        dS |                                 | _
        |                     | j
                   t1          | j
                   |                                 st          | j
                  | _        dS dS dS )	a)  Reload the file from disk, discarding any unsaved changes.

        If the file has syntax problems, this sets the
        ``corrupted`` and ``corrupted_error_message`` properties,
        and attempts to modify the file will raise an
        exception.

        Returns:
            None
        FN   rr   Tproblem_markr   )
_corrupted_corrupted_error_message_corrupted_maybe_line_corrupted_maybe_columnrM   r   r   r;   readr,   _yamlr3   rL   r   errnoENOENTr   r   getattrlinecolumnrE   _load_template_fill_default_contentrD   _save_default_content)rN   r   r   r<   marks        r   r+   zYamlFile.load   sa     (,%%)"'+$!/!3	T]C99 'T99;;' ' ' ' ' ' ' ' ' ' ' ' ' ' '%h//DJ &2$*%=%=D"" 	 	 	w%,& !

 



  	 	 	"DO,/FFD) 1nd33D ?9 ;TY!^ ;15D.; ?t{a/? ?37;D0DJJJJJJ	 : 	F F "VV


!0022
**4:666&tz2221133 F-9$*-E-ED***	F 	FF FsH   B" A)B" )A--B" 0A-10B" "
E,CEA1EEc                     | j         J t          | j                                                   }|                    dd            |S )N	__dummy__)templater,   lstrippop)rN   results     r   r_   zYamlFile._load_template   sH     }(((dm224455 	

;%%%r-   c                     d S N )rN   re   s     r   r`   zYamlFile._fill_default_content   s    r-   c                     dS )zHOverride to change whether we consider a default, unmodified file dirty.Trk   rN   s    r   ra   zYamlFile._save_default_content   s    tr-   c                 R    | j         rt          d| j        d| j                  d S )Nz"Cannot modify corrupted YAML file 
)rT   
ValueErrorr;   rU   rm   s    r   _throw_if_corruptedzYamlFile._throw_if_corrupted   sG    ? 	M*"mmmT-J-JL M M M	M 	Mr-   c                 J    t           j                            | j                  S )zBasename of the filename.)r   r   basenamer;   rm   s    r   rs   zYamlFile.basename   s     w...r-   c                     | j         S )zGet whether the file is corrupted.

        A corrupted file has a syntax error so we can't modify and save it.
        See ``corrupted_error_message`` for what's wrong with it.

        Returns:
            True if file is corrupted.
        )rT   rm   s    r   	corruptedzYamlFile.corrupted   s     r-   c                     | j         S )zGet the error message if file is corrupted, or None if it isn't.

        Use this to display the problem if the file is corrupted.

        Returns:
            Corruption message or None.
        )rU   rm   s    r   corrupted_error_messagez YamlFile.corrupted_error_message   s     ,,r-   c                     | j         S )z}Get the line number for syntax error, or None if unavailable.

        Returns:
            Corruption line or None.
        )rV   rm   s    r   corrupted_maybe_linezYamlFile.corrupted_maybe_line   s     ))r-   c                     | j         S )zzGet the column for syntax error, or None if unavailable.

        Returns:
            Corruption column or None.
        )rW   rm   s    r   corrupted_maybe_columnzYamlFile.corrupted_maybe_column  s     ++r-   c                     | j         S )aB  Get the number of times we've resynced with the file on disk (reloaded or saved changes).

        This is used for cache invalidation. If a cached value becomes invalid whenever
        ``change_count`` increments, then the cached value will be recomputed whenever
        we save new changes or reload the file.
        rM   rm   s    r   change_countzYamlFile.change_count  s     !!r-   c                 <    | j         t          | j                  k    S )z"Get whether changes are all saved.)rL   r3   rY   rm   s    r   has_unsaved_changeszYamlFile.has_unsaved_changes  s     %dj)A)AAAr-   c                 $    | j         dz   | _         dS )zApply any in-memory changes as if we'd saved, but don't actually save.

        This is used to "try out" a change before we save it. We can load()
        to undo our changes.
        rQ   Nr}   rm   s    r   use_changes_without_savingz#YamlFile.use_changes_without_saving  s     "/!3r-   c                     |                                   t          | j                  }|| j        k    r3t	          | j        | j        |           | j        dz   | _        || _        dS dS )zWrite the file to disk, only if any changes have been made.

        Raises ``IOError`` if it fails for some reason.

        Returns:
            None
        rQ   N)rq   r3   rY   rL   r=   r;   rM   )rN   r   s     r   savezYamlFile.save&  ss     	  """
++t-- 	.tz4=(;;;!%!3a!7D%-D"""	. 	.r-   c                     t          |          r|fS 	 t          d |D                       S # t          $ r t          d          w xY w)Nc              3      K   | ]}|V  d S rj   rk   ).0rG   s     r   	<genexpr>z!YamlFile._path.<locals>.<genexpr><  s"      88G888888r-   z9YAML file path must be a string or an iterable of strings)r
   rC   	TypeErrorrp   )clsr   s     r   _pathzYamlFile._path6  si    T?? 	^8O^884888888 ^ ^ ^ !\]]]^s	   - Ac                 r    | j         }|D ],}||v r$t          ||         t                    r	||         }* d S |S rj   )rY   rB   rE   rN   piecescurrentps       r   _get_dict_or_nonezYamlFile._get_dict_or_none@  sP    * 	 	AG| 
71:t < < !!*ttr-   c                     |                                   | j        }|D ]O}||vst          ||         t                    s&t	                      ||<   t          ||                    ||         }P|S rj   )rq   rY   rB   rE   r   rD   r   s       r   _ensure_dicts_at_pathzYamlFile._ensure_dicts_at_pathI  s}      """* 	! 	!A 3z'!*d'C'C 3 *^^
&wqz222ajGGr-   c                     |                                   |                     |          }|                     |dd                   }|||d         <   dS )a6  Set a single value at the given path.

        Overwrites any existing value at the path.

        This method does not save the file, call ``save()`` to do that.

        Args:
            path (str or list of str): single key, or list of nested keys
            value: any YAML-compatible value type
        N)rq   r   r   )rN   r   rH   existings       r   	set_valuezYamlFile.set_valueW  sV     	  """zz$--d3B3i88"br-   c                     |                                   |                     |          }|                     |dd                   }|d         }|	||v r||= dS dS dS )zRemove a single value at the given path.

        This method does not save the file, call ``save()`` to do that.

        Args:
            path (str or list of str): single key, or list of nested keys
        Nr   )rq   r   r   )rN   r   r   keys       r   unset_valuezYamlFile.unset_valueh  s}     	  """zz$))$ss)442h 	C8O 		 	 	 	r-   Nc                     |                      |          }|                     |dd                   }||S |                    |d         |          S )a
  Get a single value from the YAML file.

        Args:
            path (str or list of str): single key, or list of nested keys
            default: any YAML-compatible value type

        Returns:
            the value from the file or the provided default
        Nr   )r   r   get)rN   r   defaultr   s       r   	get_valuezYamlFile.get_valuey  sU     zz$))$ss)44 	3N<<R'222r-   c                 8    |                                   | j        S )z+Get the outermost value from the yaml file.)rq   rY   rm   s    r   rootzYamlFile.root  s     	  """zr-   rj   )__name__
__module____qualname____doc__re   rO   r+   r_   r`   ra   rq   propertyrs   ru   rw   ry   r{   r~   r   r   r   classmethodr   r   r   r   r   r   r   rk   r-   r   rJ   rJ   m   s         /H  $;F ;F ;Fz	 	 	    M M M
 / / X/ 	 	 X	 - - X- * * X* , , X, " " X" B B XB
4 4 4. . .  ^ ^ [^    # # #"  "3 3 3 3"   X  r-   rJ   )r   rj   )%r   
__future__r   r   ruamel_yamlr'   ruamel_yaml.errorr   ruamel_yaml.commentsr   r   ImportErrorruamel.yamlr2   ruamel.yaml.errorruamel.yaml.commentsr   rZ   r   r6   r   "anaconda_project.internal.makedirsr    anaconda_project.internal.renamer	   $anaconda_project.internal.py2_compatr
   
_YAMLError_CommentedMap_CommentedSeqr    r,   r3   r=   rD   objectrJ   rk   r-   r   <module>r      s   * ) 6 6 6 6 6 6 6 62  ++++++1111111111111 2 2 2++++++111111111111112   				 



  D D D D D D A A A A A A : : : : : : 
   	B 	B 	B: : :( ( ( (*	* 	* 	*b b b b bv b b b b bs   # AA