
    $TXg:)                       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_utf8)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   /   sp     t_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newopeniterr   readupdate	hexdigest)r?   algohasherr@   chunks        r1   compute_sumrQ   G   s    :D<<>%% [[F	4B'"''40#6EMM%  7 
  
 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)
rS   read_icondataread_package_metadataread_paths_jsonr    rT   r   schannelrU   rW   )recordpackage_cache_recordepdrX   rY   rZ   s         r1   read_package_inforb   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_jsonrl   k   s.    	43V\J	Kryy} 
L	K	K   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   rd   re   )conda_package_handling.apir'   apiextractr   r   rg   rh   )rT   conda_package_handlingtmpdirf	json_datas        r1   read_index_json_from_tarballrv   p   so    %		""**+DffUtFFL9:a		!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)Nrd   zrepodata_record.jsonrf   ri   s     r1   read_repodata_jsonrx   z   s6    	(&2HI
	yy}
 
 
rm   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)Nrd   zicon.pngrE   zutf-8)r   r   r   rK   r   decode)rj   icon_file_pathrt   datas       r1   r[   r[      sV    5vzJNn~t,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)Nrd   z	link.jsonzpackage_metadata.json)r   )rj   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   rg   loadsrK   getr   r   r!   )rj   r   r?   rt   r|   rY   s   `     r1   r\   r\      s    Q v&Dt_::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)Nrd   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/   rt   s     r1   r2   z"read_paths_json.<locals>.<genexpr>   s     :Mq:??Ms   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      OrSUOs   c              3  <   K   | ]  }|j                           y wr-   r;   )r/   rA   s     r1   r2   z;read_paths_json.<locals>.read_files_file.<locals>.<genexpr>   s     O7Ntdjjl7Ns   _pathr   prefix_placeholderr&   	file_modeTno_link	path_typer   )r   rC   keysr(   r   softlinkhardlinkr"   )
files_pathrt   	path_inforj   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   rg   rh   r   r   r   r$   read_has_prefixread_no_linktuple)
rj   paths_json_path
paths_jsonr|   rZ   r   r   r   r   r   s
   `      @@@r1   r]   r]      s    /8H8\2Oo':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       )	Nc              3  >   K   | ]  }|j                  d         yw)z"'Nr   )r/   xs     r1   r2   z6read_has_prefix.<locals>.parse_line.<locals>.<genexpr>   s     U.Taggen.Ts   F)posixr&   r   r      z!Invalid has_prefix file at path: )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(+LTF)STTr8   c              3  .   K   | ]  } |        y wr-   r   )r/   rA   r   s     r1   r2   z"read_has_prefix.<locals>.<genexpr>   s     C1BJt$1Bs   )r   rC   r   r   r   )r?   parsed_linesprr   r   s   `  @@r1   r   r      sX     ],STKU DT1BCLAMN2BKK".."++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/   rt   rj   s     r1   r2   z"read_soft_links.<locals>.<genexpr>   s!     REqVD1La,P%QEs   %%)r   )rj   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?       /9*T8T &//#"&	  /9s   +-r   c              3  &   K   | ]	  }|d      ywr   Nr   r/   ps     r1   r2   z%read_python_record.<locals>.<genexpr>  s     /JqadJ   z	<develop>dev_0r   c              3  &   K   | ]	  }|d      ywr   r   r   s     r1   r2   z%read_python_record.<locals>.<genexpr>&  s     3
1!A$
r   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%      RW$H483D3DEERWs   %'r   )package_typer.   versionrU   subdirfnbuildbuild_numberrZ   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%   	norm_namer   sp_reference)prefix_pathanchor_filepython_versionpydistr   r   rU   r   r   
paths_tupsrZ   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.PathLikerN   zLiteral['md5', 'sha256']returnstr)Q__doc__
__future__r   rG   rg   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   rQ   rb   rl   rv   rx   r[   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   