o
    Uh0                  
   @   sL  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rhdd
l m!Z!m"Z" ede#Z$ee$df Z%g dZ&ej'dkZ(e(rdndZ)e*dej+ej,B Z-e
dg dZ.e*dej+ej,B Z/ee%dZ0de#defddZ1de#de#fddZ2de#de.fddZ3d ed!ed"e#dee#e4f fd#d$Z5d<d&d'Z6ej7d(ed)e#dee fd*d+Z8d,d- fd.eee$ef  d/ee$gee# f defd0d1Z9d2e#deee#e#e#d3f  fd4d5Z:de4fd6d7Z;d8ee#d9f ddfd:d;Z<dS )=z=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                 C   s   t td}||  | 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_parser r/   c/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/installer/utils.pyr   U   s   

r   namec                 C   s   t dd|  S )ziCanonicalize a project name according to PEP-503.

    :param name: The project name to canonicalize
    z[-_.]+-)resublower)r1   r/   r/   r0   canonicalize_nameb   s   r6   filenamec                 C   s(   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)r7   
wheel_infor/   r/   r0   r   j   s   
r   sourcedesthash_algorithmc                 C   s`   t |}d}	 | t}|sn|| || |t|7 }qt|	 
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)r=   r>   r?   hashersizebufr/   r/   r0   r   u   s   



r   r   c                   C   sZ   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)osr1   sysr!   r5   platformNotImplementedErrorr/   r/   r/   r0   r      s   

r   streaminterpreterc                 c   s    |  d | ddkrBt }|d| d  |  d |   	 | t}|s.n|| q&| 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)	seekrD   ioBytesIOrG   encodereadlinerE   r-   )rX   rY   
new_streamrP   r/   r/   r0   r      s$   
	





r   c                 C   s   d S )Nr/   )_r/   r/   r0   <lambda>   s    rc   recordsprefix_for_schemec                 C   s\   t jt  dddd}tj|dddd}| D ]\}}|||| q|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,"r[   )	delimiter	quotecharlineterminatorr   )	r]   TextIOWrapperr^   csvwriterwriterowto_rowr\   detach)rd   re   rX   rq   schemerecordr/   r/   r0   r      s   
r   textr   c           	      c   s    t dd}t|_||  | D ]R}|dvrq||D ]E\}}t|ts)J t|}|s2J |	d}t|ts>J |	d}|dusIJ t|tsPJ t
d|dtd  }||||fV  qq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)
    rA   )
delimiters)console_scriptsgui_scriptsmoduleattrsNr   _scripts)r   stroptionxformread_stringsectionsitems
isinstance_ENTRYPOINT_REGEXr9   groupr   rH   )	rw   configsectionr1   valuer9   r{   r|   script_sectionr/   r/   r0   r      s(   




r   c                  C   s   t d} t |  | S )zBGet the current umask which involves having to set it temporarily.r   )rT   umask)maskr/   r/   r0   _current_umask   s   

r   pathzos.PathLike[str]c                 C   s   t | dt  @ dB  dS )z.Make the file at the provided path executable.i  I   N)rT   chmodr   )r   r/   r/   r0   r     s   r   )r*   r   )=__doc__rI   
contextlibrp   rB   r]   rT   r3   rU   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__r1   _WINDOWSrE   compileVERBOSEUNICODEr8   r   r   r   r   r6   r   intr   r   contextmanagerr   r   r   r   r   r/   r/   r/   r0   <module>   sz    0


	






""	