U
    -ºc/  ã                   @   s<   d Z ddlZddlmZ ddlmZ dZG dd„ deƒZdS )	zdistutils.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   ú@/tmp/pip-unpacked-wheel-izj_87as/setuptools/_distutils/config.pyÚ_get_rc_file%   s    zPyPIRCCommand._get_rc_filec              	   C   sH   |   ¡ }t t |tjtjB d¡d¡}| t||f ¡ W 5 Q R X dS )zCreates a default .pypirc file.i€  ÚwN)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|krF| 
dd¡}dd„ | d¡D ƒ}|g krŽd|krŠd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kr | j|d
< |  S |d |ks:|d
 |kr’|  S q’nRd|kr˜d}| |d
¡rp| 
|d
¡}n| j}| 
|d	¡| 
|d¡||| jdœS i S )zReads the .pypirc file.zUsing PyPI login from %sÚ	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_REALMÚ
has_option)r   r   r&   Úconfigr,   Úindex_serversÚ_serversr#   ÚcurrentÚkeyÚdefaultr   r   r   Ú_read_pypirc/   sb    

þý
þ

ÿ
þ


ûzPyPIRCCommand._read_pypircc                 C   s8   ddl }| dd¡}| |¡d  dd¡}| ¡  |¡S )z%Read and decode a PyPI HTTP response.r   Nzcontent-typez
text/plainr   ÚcharsetÚascii)ÚcgiÚ	getheaderÚparse_headerr-   r+   Údecode)r   Úresponser:   Úcontent_typeÚencodingr   r   r   Ú_read_pypi_responsex   s    z!PyPIRCCommand._read_pypi_responsec                 C   s   d| _ d| _d| _dS )zInitialize options.Nr   )r&   r'   Úshow_responser   r   r   r   Úinitialize_options€   s    z PyPIRCCommand.initialize_optionsc                 C   s(   | j dkr| j| _ | jdkr$| j| _dS )zFinalizes options.N)r&   r*   r'   r/   r   r   r   r   Úfinalize_options†   s    

zPyPIRCCommand.finalize_options)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r*   r/   r&   r'   Úuser_optionsÚboolean_optionsr   r   r7   rA   rC   rD   r   r   r   r   r      s   þIr   )rH   r
   Úconfigparserr   Úcmdr   r   r   r   r   r   r   Ú<module>   s
   