File: //lib/python3/dist-packages/packaging/__pycache__/_musllinux.cpython-310.pyc
o
    {ۓa  �                	   @   s~  d Z ddlZddlZddlZddlZddlZddlZddlZddlZddl	m
Z
mZmZm
Z
mZ de
e dedeedf fdd	�Zde
e de
e fd
d�ZG dd
� d
e�Zdede
e fdd�Ze�� dede
e fdd��Zdedee fdd�Zedkr�ddlZe�� Ze�d�s�J d��ede� edeej�� eddd� ee� dd e�!d!d"�d# ��D ]
Z"ee"d$d� q�dS dS )%z�PEP 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                 C   s   t �|| �t �|���S �N)�struct�unpack�read�calcsize)r   r   � r   �6/usr/lib/python3/dist-packages/packaging/_musllinux.py�_read_unpacked   s   r   c              	   C   sb  | � d� zt| d�}W n tjy   Y dS w |dd� td�kr$dS | � t�d�d� zdd	d
�|d  \}}}W n
 tyE   Y dS w tj|� }zt| |�\}}}}}}}	W n tjyd   Y dS w t	|	d �D ]C}
| � |||
  � z|t| |��\}}}
W n tjy�   Y  dS w |dkr�qk| � |� t
�| �|
���
d�}d
|vr� dS |  S dS )z�Detect 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   �KeyError�operator�
itemgetter�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�interpreterr   r   r   �_parse_ld_musl_from_elf   sN   
����
��
r7   c                   @   s   e Zd ZU eed<