
    P'g              
       Z   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
mZmZmZmZ de
e   dedeedf   fdZde
e   dee   fd	Z G d
 de      Zdedee   fdZ ej,                         dedee   fd       Zdedee   fdZedk(  rddlZ ej6                         Zej;                  d      sJ d        ede        ed eej>                                edd        e ej@                  ddejC                  dd      d               D ]  Z" ee"d        yy) zPEP 656 support.

This module implements logic to detect if the currently running Python is
linked against musl, and what musl version is used.
    N)IOIterator
NamedTupleOptionalTupleffmtreturn.c                 r    t        j                  || j                  t        j                  |                  S N)structunpackreadcalcsize)r   r	   s     X/var/www/html/knws/venv/lib/python3.12/site-packages/pip/_vendor/packaging/_musllinux.py_read_unpackedr      s%    ==affV__S%9:;;    c                    | j                  d       	 t        | d      }|dd t	        d      k7  ry| j                  t        j
                  d      d       	 dd	d
|d      \  }}}t        j                  | }	 t        | |      \  }}}}}}}	t        |	dz         D ]  }
| j                  |||
z  z          	  |t        | |            \  }}}|dk7  r7| j                  |       t        j                  | j                  |            j                  d      }d|vr y|c S  y# t        j                  $ r Y yw xY w# t        $ r Y yw xY w# t        j                  $ r Y yw xY w# t        j                  $ r Y  yw xY w)zDetect musl libc location by parsing the Python executable.

    Based on: https://gist.github.com/lyssdod/f51579ae8d93c8657a5564aefc2ffbca
    ELF header: https://refspecs.linuxfoundation.org/elf/gabi4+/ch4.eheader.html
    r   16BN   s   ELFHHI   )IIIIHHHIIIIIIII)r   r   r   )QQQIHHHIIQQQQQQ)r         )r   r       musl)seekr   r   errortupler   operator
itemgetterKeyErrorrangeosfsdecoder   strip)r   idente_fmtp_fmtp_idxp_get_e_phoffe_phentsizee_phnumip_typep_offsetp_fileszinterpreters                  r   _parse_ld_musl_from_elfr:      s    FF1Iq%( RayE*%%FF6??5!1%,
 21
 (ue ##U+4B1e4L17Aq![' 7Q; 	wq()	).~a/G)H&FHh Q;	xkk!&&"2399$?$ K <<    <<  || 		sG   D" D; 9E
 6E#"D87D8;	EE
E E #E:9E:c                   "    e Zd ZU eed<   eed<   y)_MuslVersionmajorminorN)__name__
__module____qualname__int__annotations__ r   r   r<   r<   G   s    JJr   r<   outputc                 @   d | j                         D        D cg c]  }|s|	 }}t        |      dk  s|d   d d dk7  ry t        j                  d|d         }|sy t	        t        |j                  d            t        |j                  d                  S c c}w )	Nc              3   <   K   | ]  }|j                           y wr   )r+   ).0ns     r   	<genexpr>z&_parse_musl_version.<locals>.<genexpr>M   s     @q@s   r   r   r   r!   zVersion (\d+)\.(\d+)r   )r=   r>   )
splitlineslenrematchr<   rB   group)rE   rI   linesms       r   _parse_musl_versionrR   L   s    @F,=,=,?@F1AQFEF
5zA~q"1/
(%(3Ac!''!*oS_EE Gs
   BB
executablec                 N   t        j                         5 }	 |j                  t        | d            }t        |      }ddd       syt        j                  |gt        j                  d      }t        |j                        S # t        $ r Y ddd       yw xY w# 1 sw Y   _xY w)a`  Detect currently-running musl runtime version.

    This is done by checking the specified executable's dynamic linking
    information, and invoking the loader to parse its output for a version
    string. If the loader is musl, the output would be something like::

        musl libc (x86_64)
        Version 1.2.2
        Dynamic Program Loader
    rbNT)stderruniversal_newlines)
contextlib	ExitStackenter_contextopenOSErrorr:   
subprocessrunPIPErR   rV   )rS   stackr   ldprocs        r   _get_musl_versionrc   V   s     
			 (5	##DT$:;A %Q'( >>2$z4PDt{{++  		( (	( (s-   BBB	BBBBB$archc              #      K   t        t        j                        }|yt        |j                  dd      D ]  }d|j
                   d| d|    yw)aT  Generate musllinux tags compatible to the current platform.

    :param arch: Should be the part of platform tag after the ``linux_``
        prefix, e.g. ``x86_64``. The ``linux_`` prefix is assumed as a
        prerequisite for the current platform to be musllinux-compatible.

    :returns: An iterator of compatible musllinux tags.
    N
musllinux_r1   )rc   sysrS   r(   r>   r=   )rd   sys_muslr>   s      r   platform_tagsrj   n   sY      !0Hx~~r2. ;8>>*!E7!D6::;s   AA__main__zlinux-z	not linuxzplat:zmusl:ztags: )endz[.-]r1   -r   rf   z
      )#__doc__rX   	functoolsr%   r)   rM   r   r]   rh   typingr   r   r   r   r   bytesstrrB   r   r:   r<   rR   	lru_cacherc   rj   r?   	sysconfigget_platformplat
startswithprintrS   subsplittrD   r   r   <module>r}      sz      	 	   
 < <<bi <c <eCHo <.r%y .Xc] .b: 
F F(> F ,# ,(<*@ , ,.; ; ;  z!9!!#D??8$1k1$	'4	'$S^^45	's6266'3

30B20FGH !aZ ! r   