o
    ev%                     @   s  U 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mZmZ ddlmZmZmZmZ dZdZdZejded	e	ee ddf fd
dZded	efddZded	efddZdedee d	efddZe dd Zee e f e!d< G dd deZ"d	ee fddZ#d	ee fddZ$d	ee fddZ%ded	ee e f fd d!Z&e' d	ee e f fd"d#Z(d$ed%e"d	efd&d'Z)d(d)d*d+Z*dee d	e
e fd,d-Z+dS ).    N)Dict	GeneratorIterator
NamedTupleOptionalSequenceTuple   )EIClassEIDataELFFileEMachinel      ~ i   i   pathreturnc              
   c   sb    zt | d}t|V  W d    W d S 1 sw   Y  W d S  tttfy0   d V  Y d S w )Nrb)openr   OSError	TypeError
ValueError)r   f r   4lib/python3.10/site-packages/packaging/_manylinux.py
_parse_elf   s   &r   
executablec                 C   sv   t | -}|d uo(|jtjko(|jtjko(|jtj	ko(|j
t@ tko(|j
t@ tk	 W  d    S 1 s4w   Y  d S N)r   capacityr
   C32encodingr   Lsbmachiner   ZArmflagsEF_ARM_ABIMASKEF_ARM_ABI_VER5EF_ARM_ABI_FLOAT_HARDr   r   r   r   r   _is_linux_armhf   s   



$r%   c                 C   sZ   t | }|d uo|jtjko|jtjko|jtj	k	 W  d    S 1 s&w   Y  d S r   )
r   r   r
   r   r   r   r   r   r   ZI386r$   r   r   r   _is_linux_i686+   s   



$r&   archsc                    s>   d|v rt | S d|v rt| S h d t fdd|D S )NZarmv7li686>   Zloongarch64x86_64Zppc64leZriscv64Zaarch64Zppc64Zs390xc                 3   s    | ]}| v V  qd S r   r   ).0archZallowed_archsr   r   	<genexpr>C   s    z'_have_compatible_abi.<locals>.<genexpr>)r%   r&   any)r   r'   r   r,   r   _have_compatible_abi5   s   	r/   c                   C   s   dS )N2   r   r   r   r   r   <lambda>K   s    r1   _LAST_GLIBC_MINORc                   @   s   e Zd ZU eed< eed< dS )_GLibCVersionmajorminorN)__name__
__module____qualname__int__annotations__r   r   r   r   r3   N   s   
 r3   c                  C   sF   zt d} | dusJ |  \}}W |S  ttttfy"   Y dS w )zJ
    Primary implementation of glibc_version_string using os.confstr.
    CS_GNU_LIBC_VERSIONN)osconfstrrsplitAssertionErrorAttributeErrorr   r   )Zversion_string_versionr   r   r   _glibc_version_string_confstrS   s   
rC   c                  C   s   zddl } W n
 ty   Y dS w z| d}W n
 ty"   Y dS w z|j}W n
 ty2   Y dS w | j|_| }t|t	sD|
d}|S )zG
    Fallback implementation of glibc_version_string using ctypes.
    r   Nascii)ctypesImportErrorZCDLLr   gnu_get_libc_versionr@   Zc_char_pZrestype
isinstancestrdecode)rE   Zprocess_namespacerG   version_strr   r   r   _glibc_version_string_ctypesf   s(   


rL   c                   C   s   t  pt S )z9Returns glibc version string, or None if not using glibc.)rC   rL   r   r   r   r   _glibc_version_string   s   rM   rK   c                 C   sB   t d| }|std|  t dS t|dt|dfS )a3  Parse glibc version.

    We use a regexp instead of str.split because we want to discard any
    random junk that might come after the minor version -- this might happen
    in patched/forked versions of glibc (e.g. Linaro's version of glibc
    uses version strings like "2.20-2014.11"). See gh-3588.
    z$(?P<major>[0-9]+)\.(?P<minor>[0-9]+)z;Expected glibc version with 2 components major.minor, got: rO   r4   r5   )rematchwarningswarnRuntimeWarningr9   group)rK   mr   r   r   _parse_glibc_version   s   rW   c                  C   s   t  } | d u r	dS t| S )NrN   )rM   rW   )rK   r   r   r   _get_glibc_version   s   rX   r+   rB   c                 C   s   t  }||k r	dS zdd l}W n
 ty   Y dS w t|dr4||d |d | }|d ur2t|S dS |tddkrEt|drEt|jS |tdd	krVt|d
rVt|jS |tddkrgt|drgt|j	S dS )NFr   Tmanylinux_compatibler	         manylinux1_compatible   manylinux2010_compatible   manylinux2014_compatible)
rX   
_manylinuxrF   hasattrrY   boolr3   r\   r^   r`   )r+   rB   Z	sys_glibcra   resultr   r   r   _is_compatible   s.   






re   Zmanylinux2014Zmanylinux2010Z
manylinux1))rZ   r_   )rZ   r]   )rZ   r[   c                 c   s   t tj| s	dS tdd}t| ddh@ rtdd}tt  }|g}t|jd ddD ]}t| }|	t|| q,| D ]J}|D ]E}|j|jkrM|j
}nd}t|j
|dD ]/}t|j|}	d	j|	 }
t||	rp|
 d
| V  |	tv rt|	 }t||	r| d
| V  qVqAq=dS )a  Generate manylinux tags compatible to the current platform.

    :param archs: Sequence of compatible architectures.
        The first one shall be the closest to the actual architecture and 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 manylinux-compatible.

    :returns: An iterator of compatible manylinux tags.
    NrZ      r)   r(      r	   rO   zmanylinux_{}_{}rA   )r/   sysr   r3   setrX   ranger4   r2   appendr5   formatre   _LEGACY_MANYLINUX_MAP)r'   Ztoo_old_glibc2Zcurrent_glibcZglibc_max_listZglibc_majorZglibc_minorr+   Z	glibc_maxZ	min_minorZglibc_versiontagZ
legacy_tagr   r   r   platform_tags   s:   





ro   ),collections
contextlib	functoolsr<   rP   rh   rR   typingr   r   r   r   r   r   r   Z_elffiler
   r   r   r   r!   r"   r#   contextmanagerrI   r   rc   r%   r&   r/   defaultdictr2   r9   r:   r3   rC   rL   rM   rW   	lru_cacherX   re   rm   ro   r   r   r   r   <module>   s>   
 $"
,
