
    .Ph0              
       "   d Z ddlZddlZddlZ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 ddlmZ ddlmZ ddlmZmZmZmZmZmZmZmZmZmZ dd	lmZ erdd
l m!Z!m"Z"  ede#          Z$ee$df         Z%g dZ&ej'        dk    Z(e(rdndZ) ej*        dej+        ej,        z            Z- e
dg d          Z. ej*        dej+        ej,        z            Z/ ee%d          Z0de#defdZ1de#de#fdZ2de#de.fdZ3dedede#dee#e4f         fd Z5d1d"Z6ej7        d#ed$e#dee         fd%            Z8d& fd'eee$ef                  d(ee$gee#         f         defd)Z9d*e#deee#e#e#d+f                  fd,Z:de4fd-Z;d.ee#d/f         ddfd0Z<dS )2z=Utilities related to handling / interacting with wheel files.    N)
namedtuple)ConfigParser)Message)
FeedParser)compat32)
TYPE_CHECKINGBinaryIOCallableIterableIteratorNewTypeOptionalTupleUnioncast)RecordEntry)LauncherKindScriptSectionScheme.)
parse_metadata_fileparse_wheel_filenamecopyfileobj_with_hashingget_launcher_kindfix_shebangconstruct_record_fileparse_entrypointsmake_file_executableWheelFilenameSCHEME_NAMESnti   i   z
    ^
    (?P<distribution>.+?)
    -(?P<version>.*?)
    (?:-(?P<build_tag>\d[^-]*?))?
    -(?P<tag>.+?-.+?-.+?)
    \.whl
    $
    r   )distributionversion	build_tagtagzZ
    (?P<module>[\w.]+)\s*
    (:\s*(?P<attrs>[\w.]+))\s*
    (?P<extras>\[.*\])?\s*$
    )purelibplatlibheadersscriptsdatacontentsreturnc                 ~    t          t                    }|                    |            |                                S )zParse :pep:`376` ``PKG-INFO``-style metadata files.

    ``METADATA`` and ``WHEEL`` files (as per :pep:`427`) use the same syntax
    and can also be parsed using this function.

    :param contents: The entire contents of the file
    )policy)r   r   feedclose)r*   feed_parsers     O/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/installer/utils.pyr   r   U   s:     H---KX    namec                 R    t          j        dd|                                           S )ziCanonicalize a project name according to PEP-503.

    :param name: The project name to canonicalize
    z[-_.]+-)resublower)r3   s    r1   canonicalize_namer9   b   s$    
 6)S$''--///r2   filenamec                     t                               |           }|st          d|            t          |                                 S )zfParse a wheel filename, into it's various components.

    :param filename: The filename to parse
    zNot a valid wheel filename: )_WHEEL_FILENAME_REGEXmatch
ValueErrorr   groups)r:   
wheel_infos     r1   r   r   j   sN    
 ',,X66J DBBBCCC*++--..r2   sourcedesthash_algorithmc                    t          j        |          }d}	 |                     t                    }|sn=|                    |           |                    |           |t          |          z  }Zt          j        |	                                          
                    d                              d          |fS )a  Copy a buffer while computing the content's hash and size.

    Copies the source buffer into the destination buffer while computing the
    hash of the contents. Adapted from :any:`shutil.copyfileobj`.

    :param source: buffer holding the source data
    :param dest: destination buffer
    :param hash_algorithm: hashing algorithm

    :return: size, hash digest of the contents
    r   Tascii=)hashlibnewread_COPY_BUFSIZEupdatewritelenbase64urlsafe_b64encodedigestdecoderstrip)rA   rB   rC   hashersizebufs         r1   r   r   u   s      [((FDkk-(( 	c

3C #FMMOO44;;GDDKKCPPRVVVr2   r   c                  4   t           j        dk    rdS dt          j                                        v rdS dt          j                                        v rdS dt          j                                        v rdS t          j        d	k    rd
S t          d          )z.Get the launcher kind for the current machine.r    posixamd64z	win-amd64z(arm64)z	win-arm64z(arm)zwin-armwin32zwin-ia32z&Unknown launcher kind for this machine)osr3   sysr"   r8   platformNotImplementedError r2   r1   r   r      s    	w$w#+##%%%%{CK%%''''{#+##%%%%y
|wz
F
G
GGr2   streaminterpreterc              #   ,  K   |                      d           |                     d          dk    rt          j                    }|                    d| d                                           |                      d           |                                  	 |                     t                    }|sn|                    |           3|                     d           |V  |                                 dS |                      d           | V  dS )a  Replace ``#!python`` shebang in a stream with the correct interpreter.

    :param stream: stream to modify
    :param interpreter: "correct interpreter" to substitute the shebang with

    :returns: A context manager, that provides an appropriately modified stream.
    r      s   #!pythonz#!
TN)	seekrI   ioBytesIOrL   encodereadlinerJ   r/   )r_   r`   
new_streamrU   s       r1   r   r      s      KKNNN{{1~~$$Z\\
-k---4466777A	"++m,,C S!!!		"
 	Ar2   c                     d S )Nr^   )_s    r1   <lambda>rl      s    T r2   recordsprefix_for_schemec                 H   t          j        t          j                    ddd          }t          j        |ddd          }| D ]6\  }}|                    |                     ||                               7|                    d	           |                                S )
a?  Construct a RECORD file.

    :param records:
        ``records`` as passed into :any:`WheelDestination.finalize_installation`
    :param prefix_for_scheme:
        function to get a prefix to add for RECORD entries, within a scheme

    :return: A stream that can be written to file. Must be closed by the caller.
    zutf-8T )encodingwrite_throughnewline,"rc   )	delimiter	quotecharlineterminatorr   )	re   TextIOWrapperrf   csvwriterwriterowto_rowrd   detach)rm   rn   r_   r{   schemerecords         r1   r   r      s     

wdB  F Z#TRRRF! B B&7&7&?&?@@AAAA
KKNNN==??r2   textr   c           
   #   X  K   t          d          }t          |_        |                    |            |                                D ]}|dvr|                    |          D ]\  }}t          |t                    sJ t                              |          }|sJ |	                    d          }t          |t                    sJ |	                    d          }|J t          |t                    sJ t          d|dt          d                              }||||fV  ŌdS )	zParse ``entry_points.txt``-style files.

    :param text: entire contents of the file
    :return:
        name of the script, module to use, attribute to call, kind of script (cli / gui)
    rF   )
delimiters)console_scriptsgui_scriptsmoduleattrsNr   _scripts)r   stroptionxformread_stringsectionsitems
isinstance_ENTRYPOINT_REGEXr=   groupr   rM   )	r   configsectionr3   valuer=   r   r   script_sections	            r1   r   r      sQ      S)))FF
t??$$ 6 6<<<!<<00 	6 	6KD%dC(((((%++E22ELLL[[**Ffc*****KK((E$$$eS)))))!/7;Mc*oo=M;M3NOON~55555	6	6 6r2   c                  V    t          j        d          } t          j        |            | S )zBGet the current umask which involves having to set it temporarily.r   )rZ   umask)masks    r1   _current_umaskr      s!    8A;;DHTNNNKr2   pathzos.PathLike[str]c                 V    t          j        | dt                       z  dz             dS )z.Make the file at the provided path executable.i  I   N)rZ   chmodr   )r   s    r1   r   r     s-    HTE^----577777r2   )r+   r   )=__doc__rN   
contextlibrz   rG   re   rZ   r6   r[   collectionsr   configparserr   email.messager   email.parserr   email.policyr   typingr   r	   r
   r   r   r   r   r   r   r   installer.recordsr   installer.scriptsr   r   r   r   
AllSchemes__all__r3   _WINDOWSrJ   compileVERBOSEUNICODEr<   r   r   r   r   r9   r   intr   r   contextmanagerr   r   r   r   r   r^   r2   r1   <module>r      s   C C      



  				 				 				 



 " " " " " " % % % % % % ! ! ! ! ! ! # # # # # # ! ! ! ! ! !                        * ) ) ) ) ) >========	3		63;
   7d?'6Y #
 J   
DDD 
 BJ
 J   tJ TUU
# 
' 
 
 
 
0C 0C 0 0 0 0/3 /= / / / /WW
W W 38_	W W W W:H H H H"  s x7I    > <J> eFK/01(3- 78    .6C 6HU3S/3Q-R$S 6 6 6 6D    8uS*<%<= 8$ 8 8 8 8 8 8r2   