
    DIe{+                    v   d Z ddlm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 ddlmZ ddlmZ dd	lmZ dd
lmZ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%m&Z&m'Z'm(Z( ddl)m*Z* ddl+m,Z,m-Z-m.Z. ddl/m0Z0 ddl1m2Z2m3Z3m4Z4 ddl5m6Z6m7Z7 ddl8m9Z9m:Z:m;Z;m<Z< ddl=m>Z> ddl?m@Z@mAZA  eeB          ZCd ZDd ZE e*dd d!"          d:d)            ZFd;d*ZG e*dd d+"          d<d,            ZH e*dd d-"          d<d.            ZId/ ZJd0 ZKd1 ZLd2 ZMd3 ZNd4 ZOd5 ZPd6 ZQd7 ZRd8 ZSd9 ZTdS )=z@Disk utility functions for reading and processing file contents.    )annotationsN)	b64encode)
namedtuple)ENOENT)partial)chain)	getLogger)isdirisfilejoin)Path)Literal   )first)shlex_split_unicode)dals)PREFIX_PLACEHOLDER)open)PythonDistributionPythonEggInfoDistributionPythonEggLinkDistributionPythonInstalledDistribution)
deprecated)CondaUpgradeErrorCondaVerificationErrorPathNotFoundError)Channel)FileModePackageTypePathType)PackageInfoPackageMetadata)PathData
PathDataV1	PathsDataPrefixRecord   )TemporaryDirectory)islinklexistsc                X    t          d t          j        |           D                       S )Nc              3  $   K   | ]}|j         V  d S N)name).0entrys     8lib/python3.11/site-packages/conda/gateways/disk/read.py	<genexpr>z<lambda>.<locals>.<genexpr>)   s$      ????????    )listosscandir)ds    r1   <lambda>r8   )   s%    D??A????? r3   c              #    K   	 t          |           5 }|D ]2}|                                }|r|                    d          r.|V  3	 ddd           dS # 1 swxY w Y   dS # t          $ r}|j        t
          k    rn Y d}~dS d}~ww xY w)zGenerator function for lines in file.  Empty generator if path does not exist.

    Args:
        path (str): path to file

    Returns:
        iterator: each line in file, not starting with '#'

    #N)r   strip
startswithOSErrorerrnor   )pathfhlinees       r1   yield_linesrC   ,   s     $ZZ 	2  zz|| ts33 



		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	    7f DDDDDs:   A$ 6A
A$ AA$ AA$ $
B.BBz23.9z24.3z3Use `conda.gateways.disk.read.compute_sum` instead.)addendumalgoLiteral['md5', 'sha256']r?   str | os.PathLikereturnstrc                "    t          ||           S r-   compute_sum)rE   r?   s     r1   _digest_pathrM   D   s     tT"""r3   c                   t          |           } |                                 st          |           t          j        |          }|                     d          5 }t          t          |j        d          d          D ]}|	                    |           	 d d d            n# 1 swxY w Y   |
                                S )Nrbi    r3   )r   is_filer   hashlibnewr   iterr   readupdate	hexdigest)r?   rE   hasherr@   chunks        r1   rL   rL   K   s    ::D<<>> &%%% [F	4 !B'"'400#66 	! 	!EMM%    	!! ! ! ! ! ! ! ! ! ! ! ! ! ! ! s   <B%%B),B)z@Use `conda.gateways.disk.read.compute_sum(path, "md5")` instead.c                "    t          | d          S )Nmd5rK   r?   s    r1   compute_md5sumr\   X   s     tU###r3   zCUse `conda.gateways.disk.read.compute_sum(path, "sha256")` instead.c                "    t          | d          S )Nsha256rK   r[   s    r1   compute_sha256sumr_   a   s     tX&&&r3   c           
         |j         }t          |          }t          |          }t          |          }t	          ||j        t          | j        p| j                  | |j	        |||          S )N)extracted_package_dirpackage_tarball_full_pathchannelrepodata_recordurlicondatapackage_metadata
paths_data)
ra   read_icondataread_package_metadataread_paths_jsonr!   rb   r   schannelrc   re   )recordpackage_cache_recordepdrf   rg   rh   s         r1   read_package_inforp   o   sx    

4CS!!H,S11 %%J!"6"P96>:: $)	 	 	 	r3   c                    t          t          | dd                    5 }t          j        |          cd d d            S # 1 swxY w Y   d S )Ninfo
index.jsonr   r   jsonloadextracted_package_directoryfis     r1   read_index_jsonrz      s    	d.EE	F	F "y}}                    A  AAc                &   dd l }t                      5 }|j                            | |d           t	          t          |dd                    5 }t          j        |          }d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   |S )Nr   rr   rs   )conda_package_handling.apir(   apiextractr   r   ru   rv   )rb   conda_package_handlingtmpdirf	json_datas        r1   read_index_json_from_tarballr      s	   %%%%			 %"**+DffUUU$vv|4455 	%	!I	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	%% % % % % % % % % % % % % % % s5   ;BA/#B/A3	3B6A3	7BB
B
c                    t          t          | dd                    5 }t          j        |          cd d d            S # 1 swxY w Y   d S )Nrr   zrepodata_record.jsonrt   rw   s     r1   read_repodata_jsonr      s    	d.8NOO	P	P TVy}}                 r{   c                   t          | dd          }t          |          r^t          |d          5 }|                                }d d d            n# 1 swxY w Y   t	          |                              d          S d S )Nrr   zicon.pngrO   zutf-8)r   r   r   rT   r   decode)rx   icon_file_pathr   datas       r1   ri   ri      s    5vzJJNn .$'' 	16688D	 	 	 	 	 	 	 	 	 	 	 	 	 	 	%%g...ts   AAAc                t     fd}t           |            t                    }|sd S t          |          5 }t          j        |                                          }|                    d          dk    rt          t          d                    	 d d d            n# 1 swxY w Y   t          di |}|S )Nc               3  X   K   t           dd          V  t           dd          V  d S )Nrr   z	link.jsonzpackage_metadata.json)r   )rx   s   r1   _pathsz%read_package_metadata.<locals>._paths   s@      .DDDDD.8OPPPPPPPr3   )keypackage_metadata_versionr'   z
                The current version of conda is too old to install this package. (This version
                only supports link.json schema version 1.)  Please update conda to install
                this package.
                 )
r   r   r   ru   loadsrT   getr   r   r"   )rx   r   r?   r   r   rg   s   `     r1   rj   rj      s   Q Q Q Q Q v&&&D  t$ZZ 	1:affhh''Dxx233q88'    9	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 +22T22s   AB!!B%(B%c                H   	 t           d          t          d          }t          |          rt          |          5 }t          j        |          }d d d            n# 1 swxY w Y   |                    d          dk    rt          t          d                    t          dd |d         D                       }n\t          t          d	                    t                    	 	fd
}t           |                      }t          d|          }|S )Nrr   z
paths.jsonpaths_versionr'   z
            The current version of conda is too old to install this package. (This version
            only supports paths.json schema version 1.)  Please update conda to install
            this package.c              3  .   K   | ]}t          di |V  d S )Nr   )r$   )r/   r   s     r1   r2   z"read_paths_json.<locals>.<genexpr>   s,      ::q:????::::::r3   pathsr   r   
has_prefixc               3    K   t          d          } d d t          |           D             D             D ]}d|i}|                                v r"|         d         |d<   |         d         |d<   |v rd	|d
<   t          t          |                    rt          j        |d<   nt          j        |d<   t          di |V  d S )Nfilesc              3     K   | ]}||V  	d S r-   r   )r/   lns     r1   r2   z;read_paths_json.<locals>.read_files_file.<locals>.<genexpr>   s<        SU     r3   c              3  >   K   | ]}|                                 V  d S r-   r;   )r/   rA   s     r1   r2   z;read_paths_json.<locals>.read_files_file.<locals>.<genexpr>   s*      OOtdjjllOOOOOOr3   _pathr   prefix_placeholderr'   	file_modeTno_link	path_typer   )r   rC   keysr)   r    softlinkhardlinkr#   )
files_pathr   	path_inforx   has_prefix_filesinfo_dirr   s      r1   read_files_filez(read_paths_json.<locals>.read_files_file   s     h00J OO{:7N7NOOO   , , %aL	(--////6Fq6I!6LI23-=a-@-CIk*<<+/Ii($:A>>?? ?-5->Ik**-5->Ik*++++++++, ,r3   r   )r   r   r   ru   rv   r   r   r   r%   read_has_prefixread_no_linktuple)
rx   paths_json_path
paths_jsonr   rh   r   r   r   r   r   s
   `      @@@r1   rk   rk      s   /88H8\22Oo )
/"" 	)j9Z((D	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	)88O$$))#    ::DM:::
 
 



 +4,+G+GHHx((	, 	, 	, 	, 	, 	, 	, 	," oo''((
 
 

 s   A$$A(+A(c                     t          dd           fdfdt                     D             }d |D             S )zReads `has_prefix` file and return dict mapping filepaths to tuples(placeholder, FileMode).

    A line in `has_prefix` contains one of:
      * filepath
      * placeholder mode filepath

    Mode values are one of:
      * text
      * binary
    ParseResult)placeholderfilemodefilepathc                `   t          d t          | d          D                       }t          |          dk    r" t          t          j        |d                   S t          |          dk    r, |d         t	          |d                   |d                   S t          dz            )	Nc              3  @   K   | ]}|                     d           V  dS )z"'Nr   )r/   xs     r1   r2   z6read_has_prefix.<locals>.parse_line.<locals>.<genexpr>   s,      UUaggennUUUUUUr3   F)posixr'   r   r      z#Invalid has_prefix file at path: %s)r   r   lenr   r   textr   )rA   partsr   r?   s     r1   
parse_linez#read_has_prefix.<locals>.parse_line   s    UU.A$e.T.T.TUUUUUu::??;18=%(KKKZZ1__;uQx%(););U1XFFF()NQU)UVVVr3   c              3  .   K   | ]} |          V  d S r-   r   )r/   rA   r   s     r1   r2   z"read_has_prefix.<locals>.<genexpr>   s-      CCJJt$$CCCCCCr3   c                6    i | ]}|j         |j        |j        fS r   )r   r   r   )r/   prs     r1   
<dictcomp>z#read_has_prefix.<locals>.<dictcomp>   s%    NNN2BK"."+6NNNr3   )r   rC   )r?   parsed_linesr   r   s   ` @@r1   r   r      ss     ],STTKW W W W W W DCCCT1B1BCCCLNNNNNNr3   c                    t          t          t          t          | d                    t          t          | d                                        S )Nr   no_softlink)setr   rC   r   )r   s    r1   r   r     sK    Xy1122X}5566	
 	
  r3   c                :     t           fd|D                       S )Nc              3  V   K   | ]#}t          t          |                    |V  $d S r-   )r)   r   )r/   r   rx   s     r1   r2   z"read_soft_links.<locals>.<genexpr>  s;      RRqVD1La,P,P%Q%QRRRRRRRr3   )r   )rx   r   s   ` r1   read_soft_linksr     s&    RRRRERRRRRRr3   c                   t          j        | ||          }|                                \  }}t          |t                    rft          d          }d}t          j        }|                                }	t          dd |	D                       }
t          d |	D                       }nt          |t                    r1t          d          }d}t          j        }t          dd	          d	}}
nt          |t                    rt          d          }d}|j        rUt          j        }|                                }	t          d
 |	D                       }t          dd |D                       }
n.t          j        }t          dd	          d	}}
nt#                      t%          ||j        |j        |d|j        |d|
|||          S )zz
    Convert a python package defined by an anchor file (Metadata information)
    into a conda prefix record object.
    pypipypi_0r'   c              3  X   K   | ]%\  }}}t          |t          j        ||           V  &dS ))r   r   r^   size_in_bytesN)r$   r    r   )r/   r?   checksumsizes       r1   r2   z%read_python_record.<locals>.<genexpr>   s\         +T8T &/#"&	       r3   r   c              3  &   K   | ]}|d          V  dS r   Nr   r/   ps     r1   r2   z%read_python_record.<locals>.<genexpr>*  s&      //qad//////r3   z	<develop>dev_0r   c              3  &   K   | ]}|d          V  dS r   r   r   s     r1   r2   z%read_python_record.<locals>.<genexpr>:  s&      331!A$333333r3   c              3  L   K   | ]}t          |t          j                   V   dS ))r   r   N)r#   r    r   )r/   r?   s     r1   r2   z%read_python_record.<locals>.<genexpr>=  sC        JNH483DEEE     r3   r   )package_typer.   versionrc   subdirfnbuildbuild_numberrh   r   depends
constrains)r   initget_conda_dependencies
isinstancer   r   r   VIRTUAL_PYTHON_WHEEL	get_pathsr%   r   r   VIRTUAL_PYTHON_EGG_LINKr   is_manageableVIRTUAL_PYTHON_EGG_MANAGEABLEVIRTUAL_PYTHON_EGG_UNMANAGEABLENotImplementedErrorr&   
conda_namer   sp_reference)prefix_pathanchor_filepython_versionpydistr   r   rc   r   r   
paths_tupsrh   r   s               r1   read_python_recordr     s   
  $[+~NNF 7799GZ&566 .$&//"7%%''
  /9  
 
 

 //J/////	F5	6	6 $+&&":%AR@@@"E

	F5	6	6 $&// 	I&DL))++J33
33333E" RW    JJ 'FL ) D D DbJJ "###!   r3   )rE   rF   r?   rG   rH   rI   )r?   rG   rE   rF   rH   rI   )r?   rG   rH   rI   )U__doc__
__future__r   rQ   ru   r5   base64r   collectionsr   r>   r   	functoolsr   	itertoolsr   loggingr	   os.pathr
   r   r   pathlibr   typingr   auxlib.collectionr   auxlib.compatr   
auxlib.ishr   base.constantsr   common.compatr   common.pkg_formats.pythonr   r   r   r   deprecationsr   
exceptionsr   r   r   models.channelr   models.enumsr   r   r    models.package_infor!   r"   models.recordsr#   r$   r%   r&   creater(   linkr)   r*   __name__loglistdirrC   rM   rL   r\   r_   rp   rz   r   r   ri   rj   rk   r   r   r   r   r   r3   r1   <module>r     s   G F " " " " " "   				       " " " " " "                         ' ' ' ' ' ' ' ' ' '             & & & & & & 0 0 0 0 0 0       0 0 0 0 0 0 ! ! ! ! ! !            ' & & & & & V V V V V V V V V V % % % % % % ; ; ; ; ; ; ; ; ; ; ? ? ? ? ? ? ? ? K K K K K K K K K K K K & & & & & & ! ! ! ! ! ! ! !i
?
?  0 
FR  # # # #
 
 
 
 

O  
$ $ $ 
$ 

R  
' ' ' 
'  $  
    
       2- - -`O O O6  S S SE E E E Er3   