a
    "h                     @   s8   d dl Z d dlmZ d dlmZ dZG dd deZdS )    N)RawConfigParser)CommandzE[distutils]
index-servers =
    pypi

[pypi]
username:%s
password:%s
c                   @   sd   e Zd ZdZdZdZdZddde fdgZdgZd	d
 Z	dd Z
dd Zdd Zdd Zdd ZdS )PyPIRCCommandzhttps://upload.pypi.org/legacy/pypiNzrepository=rzurl of repository [default: %s])show-responseNz&display full response text from serverr   c                 C   s   t jt jddS )N~z.pypirc)ospathjoin
expanduserself r   8/opt/python-3.9.21/usr/lib/python3.9/distutils/config.py_get_rc_file&   s    zPyPIRCCommand._get_rc_filec                 C   s\   |   }tt|tjtjB dd"}|t||f  W d    n1 sN0    Y  d S )Ni  w)r   r	   fdopenopenO_CREATO_WRONLYwriteDEFAULT_PYPIRC)r   usernamepasswordrcfr   r   r   _store_pypirc*   s     zPyPIRCCommand._store_pypircc                 C   s  |   }tj|r| d|  | jp.| j}t }|| |	 }d|v rF|
dd}dd |dD }|g krd|v rdg}ni S |D ]}d|i}|
|d	|d	< d
| jfd| jfdfD ].\}	}
|||	r|
||	||	< q|
||	< q|dkr || jdfv r | j|d
< |  S |d |ks:|d
 |kr|  S qnRd|v rd}||d
rp|
|d
}n| j}|
|d	|
|d||| jdS i S )NzUsing PyPI login from %sZ	distutilszindex-serversc                 S   s    g | ]}|  d kr|  qS ) )strip).0serverr   r   r   
<listcomp>=   s   z.PyPIRCCommand._read_pypirc.<locals>.<listcomp>
r   r!   r   
repositoryrealm)r   Nzserver-loginr   )r   r   r$   r!   r%   )r   r	   r
   existsZannouncer$   DEFAULT_REPOSITORYr   readsectionsgetsplitDEFAULT_REALMZ
has_option)r   r   r$   Zconfigr)   Zindex_serversZ_serversr!   currentkeydefaultr   r   r   _read_pypirc0   sb    








zPyPIRCCommand._read_pypircc                 C   s8   dd l }|dd}||d dd}| |S )Nr   zcontent-typez
text/plain   charsetascii)cgiZ	getheaderZparse_headerr*   r(   decode)r   responser4   Zcontent_typeencodingr   r   r   _read_pypi_responsep   s    z!PyPIRCCommand._read_pypi_responsec                 C   s   d | _ d | _d| _d S )Nr   )r$   r%   Zshow_responser   r   r   r   initialize_optionsw   s    z PyPIRCCommand.initialize_optionsc                 C   s(   | j d u r| j| _ | jd u r$| j| _d S )N)r$   r'   r%   r,   r   r   r   r   finalize_options}   s    

zPyPIRCCommand.finalize_options)__name__
__module____qualname__r'   r,   r$   r%   Zuser_optionsZboolean_optionsr   r   r0   r8   r9   r:   r   r   r   r   r      s$   @r   )r	   configparserr   Zdistutils.cmdr   r   r   r   r   r   r   <module>   s   
