o
    4ôjj  ã                   @   sL   d Z ddlZddlZddlmZ ddlmZ dZG dd„ deƒZ	d	d
„ Z
dS )z�distutils.pypirc

Provides the PyPIRCCommand class, the base class for the command classes
that uses .pypirc in the distutils.command package.
é    N)ÚRawConfigParseré   )ÚCommandzE[distutils]
index-servers =
    pypi

[pypi]
username:%s
password:%s
c                   @   sh   e Zd 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 )ÚPyPIRCCommandz6Base command that knows how to handle the .pypirc filez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 )zReturns rc file path.ú~z.pypirc)ÚosÚpathÚjoinÚ
expanduser©Úself© r   úo/var/www/html/academy/tools/voices/clone/cosy-venv/lib/python3.10/site-packages/setuptools/_distutils/config.pyÚ_get_rc_file'   s   zPyPIRCCommand._get_rc_filec                 C   sf   |   ¡ }t |tjtjB d¡}tj|ddd��}| t||f ¡ W d  ƒ dS 1 s,w   Y  dS )zCreates a default .pypirc file.i€  Úwúutf-8©ÚencodingN)r   r
   ÚopenÚO_CREATÚO_WRONLYÚfdopenÚwriteÚDEFAULT_PYPIRC)r   ÚusernameÚpasswordÚrcÚrawÚfr   r   r   Ú_store_pypirc+   s
   "ÿzPyPIRCCommand._store_pypircc                 C   s”  |   ¡ }tj |¡rÈ|  d| ¡ | jp| j}tƒ }|j|dd� | 	¡ }d|v r¡| 
dd¡}dd„ | d¡D ƒ}|g krGd	|v rEd	g}ni S |D ]U}d
|i}| 
|d¡|d< d| jfd| jfdfD ]\}	}
| ||	¡ru| 
||	¡||	< qb|
||	< qb|d	krŽ|| jd	fv rŽ| j|d< |  S |d
 |ksš|d |krž|  S qIi S d|v rÈd}| |d¡r´| 
|d¡}n| j}| 
|d¡| 
|d¡||| jdœS i S )zReads the .pypirc file.zUsing PyPI login from %sr   r   Ú	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   ÚexistsÚannouncer*   ÚDEFAULT_REPOSITORYr   ÚreadÚsectionsÚgetÚsplitÚDEFAULT_REALMZ
has_option)r   r   r*   Úconfigr0   Zindex_serversZ_serversr'   ÚcurrentÚkeyÚdefaultr   r   r   Ú_read_pypirc2   sb   þý

þ
þñ

ûzPyPIRCCommand._read_pypircc                 C   s   |  dd¡}| ¡  t|ƒ¡S )z%Read and decode a PyPI HTTP response.úcontent-typez
text/plain)Z	getheaderr/   ÚdecodeÚ_extract_encoding)r   ZresponseÚcontent_typer   r   r   Ú_read_pypi_response{   s   z!PyPIRCCommand._read_pypi_responsec                 C   s   d| _ d| _d| _dS )zInitialize options.Nr   )r*   r+   Zshow_responser   r   r   r   Úinitialize_options€   s   
z PyPIRCCommand.initialize_optionsc                 C   s,   | j du r	| j| _ | jdu r| j| _dS dS )zFinalizes options.N)r*   r.   r+   r3   r   r   r   r   Úfinalize_options†   s
   

ÿzPyPIRCCommand.finalize_options)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r.   r3   r*   r+   Úuser_optionsZboolean_optionsr   r"   r8   r=   r>   r?   r   r   r   r   r      s     þIr   c                 C   s$   t j ¡ }| |d< |d j dd¡S )z{
    >>> _extract_encoding('text/plain')
    'ascii'
    >>> _extract_encoding('text/html; charset="utf8"')
    'utf8'
    r9   ÚcharsetÚascii)ÚemailÚmessageZEmailMessageÚparamsr1   )r<   Úmsgr   r   r   r;   Ž   s   
r;   )rC   Zemail.messagerG   r
   Zconfigparserr   Úcmdr   r   r   r;   r   r   r   r   Ú<module>   s    v