o
     zqfj                     @   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 )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   [/root/parts/websockify/install/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 rd}||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_REALM
has_option)r   r   r*   configr0   index_servers_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)	getheaderr/   decode_extract_encoding)r   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+   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_optionsboolean_optionsr   r"   r;   rB   rD   rE   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'
    r<   charsetascii)emailmessageEmailMessageparamsr1   )rA   msgr   r   r   r?      s   
r?   )rI   email.messagerN   r
   configparserr   cmdr   r   r   r?   r   r   r   r   <module>   s    v