
    wBf)                       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*m+Z+m,Z, ddl-m.Z. ddl/m0Z0m1Z1m2Z2 ddl3m4Z4m5Z5 ddl6m7Z7m8Z8m9Z9m:Z: ddl;m<Z< ddl=m>Z>m?Z? erddlm@Z@  eeA      ZBd ZCd ZDd+dZEd  ZFd! ZGd" ZHd# ZId$ ZJd% ZKd& ZLd' ZMd( ZNd) ZOd* ZPy),z@Disk utility functions for reading and processing file contents.    )annotationsN)	b64encode)
namedtuple)ENOENT)partial)chain)	getLogger)isdirisfilejoin)Path)TYPE_CHECKING   )first)shlex_split_unicode)dals)PREFIX_PLACEHOLDER)open)PythonDistributionPythonEggInfoDistributionPythonEggLinkDistributionPythonInstalledDistribution)CondaUpgradeErrorCondaVerificationErrorPathNotFoundError)Channel)FileModePackageTypePathType)PackageInfoPackageMetadata)PathData
PathDataV1	PathsDataPrefixRecord   )TemporaryDirectory)islinklexists)Literalc                L    t        d t        j                  |       D              S )Nc              3  4   K   | ]  }|j                     y wN)name).0entrys     8lib/python3.12/site-packages/conda/gateways/disk/read.py	<genexpr>z<lambda>.<locals>.<genexpr>,   s     ??s   )listosscandir)ds    r1   <lambda>r7   ,   s    D?A??     c              #    K   	 t        |       5 }|D ]*  }|j                         }|r|j                  d      r'| , 	 ddd       y# 1 sw Y   yxY w# t        $ r}|j                  t
        k(  rn Y d}~yd}~ww xY w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     $Z 	2 zz|ts3
		 	 	  77f sQ   B A 0A	 A B 	AA B A 	A=A83B 8A==B c                p   t        |       } | j                         st        |       t        j                  |      }| j                  d      5 }t        t        |j                  d      d      D ]  }|j                  |        	 d d d        |j                         S # 1 sw Y   |j                         S xY w)Nrbi    r8   )r   is_filer   hashlibnewr   iterr   readupdate	hexdigest)r?   algohasherr@   chunks        r1   compute_sumrP   G   s    :D<<>%% [[F	4 !B'"''40#6 	!EMM% 	!! ! s   7BB5c           
         |j                   }t        |      }t        |      }t        |      }t	        ||j
                  t        | j                  xs | j                        | |j                  |||      S )N)extracted_package_dirpackage_tarball_full_pathchannelrepodata_recordurlicondatapackage_metadata
paths_data)
rR   read_icondataread_package_metadataread_paths_jsonr    rS   r   schannelrT   rV   )recordpackage_cache_recordepdrW   rX   rY   s         r1   read_package_infora   Y   so    

4
4CS!H,S1 %J!"6"P"P96>>: $$)	 	r8   c                    t        t        | dd            5 }t        j                  |      cd d d        S # 1 sw Y   y xY w)Ninfo
index.jsonr   r   jsonloadextracted_package_directoryfis     r1   read_index_jsonrk   k   s6    	d.E	F "yy}     6?c                   dd l }t               5 }|j                  j                  | |d       t	        t        |dd            5 }t        j                  |      }d d d        d d d        S # 1 sw Y   xY w# 1 sw Y   S xY w)Nr   rc   rd   )conda_package_handling.apir'   apiextractr   r   rf   rg   )rS   conda_package_handlingtmpdirf	json_datas        r1   read_index_json_from_tarballru   p   s{    %		 %""**+DffU$vv|45 	%		!I	%% 	% 	%% s#   4A7A+A7+A4	0A77Bc                    t        t        | dd            5 }t        j                  |      cd d d        S # 1 sw Y   y xY w)Nrc   zrepodata_record.jsonre   rh   s     r1   read_repodata_jsonrw   z   s8    	d.8NO	P TVyy}  rl   c                    t        | dd      }t        |      r?t        |d      5 }|j                         }d d d        t	              j                  d      S y # 1 sw Y   $xY w)Nrc   zicon.pngrE   zutf-8)r   r   r   rJ   r   decode)ri   icon_file_pathrs   datas       r1   rZ   rZ      s]    5vzJNn.$' 	1668D	%%g..		 	s   AA"c                2     fd}t         |       t              }|sy t        |      5 }t        j                  |j                               }|j                  d      dk7  rt        t        d            	 d d d        t        di }|S # 1 sw Y   xY w)Nc               3  J   K   t         dd       t         dd       y w)Nrc   z	link.jsonzpackage_metadata.json)r   )ri   s   r1   _pathsz%read_package_metadata.<locals>._paths   s(     .DD.8OPPs    #)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   rf   loadsrJ   getr   r   r!   )ri   r~   r?   rs   r{   rX   s   `     r1   r[   r[      s    Q v&D$Z 	1::affh'Dxx23q8'  9	 +2T2	 	s   ABBc                   	 t         d      t        d      }t        |      rjt        |      5 }t        j                  |      }d d d        j                  d      dk7  rt        t        d            t        dd |d   D              }|S t        t        d	            t              	 	fd
}t         |             }t        d|      }|S # 1 sw Y   xY w)Nrc   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  2   K   | ]  }t        di |  y w)Nr   )r#   )r/   rs   s     r1   r2   z"read_paths_json.<locals>.<genexpr>   s     :q:??:s   pathsr   r   
has_prefixc               3  ^  K   t        d      } d d t        |       D        D        D ]  }d|i}|j                         v r|   d   |d<   |   d   |d<   |v rd	|d
<   t        t        |            rt        j
                  |d<   nt        j                  |d<   t        di |  y w)Nfilesc              3  &   K   | ]	  }|s|  y wr-   r   )r/   lns     r1   r2   z;read_paths_json.<locals>.read_files_file.<locals>.<genexpr>   s      SUs   c              3  <   K   | ]  }|j                           y wr-   r;   )r/   rA   s     r1   r2   z;read_paths_json.<locals>.read_files_file.<locals>.<genexpr>   s     OtdjjlOs   _pathr   prefix_placeholderr&   	file_modeTno_link	path_typer   )r   rC   keysr(   r   softlinkhardlinkr"   )
files_pathrs   	path_infori   has_prefix_filesinfo_dirr   s      r1   read_files_filez(read_paths_json.<locals>.read_files_file   s     h0JO{:7NO , %aL	(--//6Fq6I!6LI23-=a-@-CIk*<+/Ii($:A>?-5->->Ik*-5->->Ik*+++,s   B*B-r   )r   r   r   rf   rg   r   r   r   r$   read_has_prefixread_no_linktuple)
ri   paths_json_path
paths_jsonr{   rY   r   r   r   r   r   s
   `      @@@r1   r\   r\      s    /8H8\2Oo/" 	)j99Z(D	)88O$)#  :DM:

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

 S	) 	)s   CC"c                     t        dd       fdfdt               D        }|D ci c]%  }|j                  |j                  |j                  f' c}S c c}w )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   | ]  }|j                  d         yw)z"'Nr   )r/   xs     r1   r2   z6read_has_prefix.<locals>.parse_line.<locals>.<genexpr>   s     UaggenUs   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.A$e.TUUu:?18==%(KKZ1_uQx%();U1XFF()NQU)UVVr8   c              3  .   K   | ]  } |        y wr-   r   )r/   rA   r   s     r1   r2   z"read_has_prefix.<locals>.<genexpr>   s     CJt$Cs   )r   rC   r   r   r   )r?   parsed_linesprr   r   s   `  @@r1   r   r      sT     ],STKW DT1BCLAMN2BKK".."++66NNNs   *Ac                x    t        t        t        t        | d            t        t        | d                        S )Nr   no_softlink)setr   rC   r   )r   s    r1   r   r      s5    Xy12X}56	
 r8   c                ,     t         fd|D              S )Nc              3  N   K   | ]  }t        t        |            s|  y wr-   )r(   r   )r/   rs   ri   s     r1   r2   z"read_soft_links.<locals>.<genexpr>   s      RqVD1La,P%QRs   %%)r   )ri   r   s   ` r1   read_soft_linksr      s    RERRRr8   c                6   t        j                  | ||      }|j                         \  }}t        |t              rTt        d      }d}t        j                  }|j                         }	t        dd |	D              }
t        d |	D              }nt        |t              r-t        d      }d}t        j                  }t        dd	      d	}}
nt        |t              rt        d      }d}|j                  rGt        j                  }|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  ^   K   | ]%  \  }}}t        |t        j                  ||        ' yw))r   r   sha256size_in_bytesN)r#   r   r   )r/   r?   checksumsizes       r1   r2   z%read_python_record.<locals>.<genexpr>
  s<       +T8T &//#"&	 s   +-r   c              3  &   K   | ]	  }|d      ywr   Nr   r/   ps     r1   r2   z%read_python_record.<locals>.<genexpr>  s     /qad/   z	<develop>dev_0r   c              3  &   K   | ]	  }|d      ywr   r   r   s     r1   r2   z%read_python_record.<locals>.<genexpr>$  s     31!A$3r   c              3  R   K   | ]  }t        |t        j                          ! yw))r   r   N)r"   r   r   )r/   r?   s     r1   r2   z%read_python_record.<locals>.<genexpr>'  s%      JNH483D3DEEs   %'r   )package_typer.   versionrT   subdirfnbuildbuild_numberrY   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   rT   r   r   
paths_tupsrY   r   s               r1   read_python_recordr      s   
  $$[+~NF 779GZ&56&/"77%%'
 /9

 /J//	F5	6+&"::%AR@"E
	F5	6&/&DDL))+J3
33E"RWJ 'FFL ) DbJ "##! r8   )r?   zstr | os.PathLikerM   zLiteral['md5', 'sha256']returnstr)Q__doc__
__future__r   rG   rf   r4   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   
exceptionsr   r   r   models.channelr   models.enumsr   r   r   models.package_infor    r!   models.recordsr"   r#   r$   r%   creater'   linkr(   r)   r*   __name__loglistdirrC   rP   ra   rk   ru   rw   rZ   r[   r\   r   r   r   r   r   r8   r1   <module>r      s    G "   	  "     ' '    & 0  0 !  W V % ; ; ? K K & !
?0
$$

 2-`O6SEr8   