o
     zqf.                     @   sx   d Z ddlZddlZddlZddlZddlZddlmZ ddl	m
Z
 ddlmZ ddlmZ G dd	 d	eZd
d ZdS )zhdistutils.command.register

Implements the Distutils 'register' command (register with the repository).
    N)log)warn   always_iterable)PyPIRCCommandc                   @   s   e Zd ZdZejddg Zejg d Zddd fgZdd	 Zd
d Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd ZdddZdS )registerz7register the distribution with the Python package index)list-classifiersNz list the valid Trove classifiers)strictNzBWill stop the registering if the meta-data are not fully compliant)verifyr	   r
   checkc                 C   s   dS )NT selfr   r   e/root/parts/websockify/install/lib/python3.10/site-packages/setuptools/_distutils/command/register.py<lambda>$   s    zregister.<lambda>c                 C   s   t |  d| _d| _d S )Nr   )r   initialize_optionslist_classifiersr
   r   r   r   r   r   &   s   

zregister.initialize_optionsc                 C   s*   t |  d| jfdd}|| jjd< d S )Nr   )r      )r
   restructuredtextr   )r   finalize_optionsr
   distributioncommand_options)r   check_optionsr   r   r   r   +   s
   
zregister.finalize_optionsc                 C   sX   |    |   |  D ]}| | q| jr|   d S | jr&|   d S |   d S N)	r   _set_configget_sub_commandsrun_commanddry_runverify_metadatar   classifierssend_metadata)r   cmd_namer   r   r   run4   s   zregister.runc                 C   s8   t dt | jd}|  | j|_d|_|  dS )zDeprecated API.zVdistutils.command.register.check_metadata is deprecated; use the check command insteadr   r   N)r   DeprecationWarningr   get_command_objensure_finalizedr
   r   r#   )r   r   r   r   r   check_metadataC   s   zregister.check_metadatac                 C   s|   |   }|i kr!|d | _|d | _|d | _|d | _d| _d	S | jd| jfvr0td| j | jdkr9| j| _d| _d	S )
z0Reads the configuration file and set attributes.usernamepassword
repositoryrealmTpypiz%s not found in .pypircFN)_read_pypircr(   r)   r*   r+   
has_configDEFAULT_REPOSITORY
ValueError)r   configr   r   r   r   P   s   






zregister._set_configc                 C   s*   | j d }tj|}t| | dS )z.Fetch the list of classifiers from the server.z?:action=list_classifiersN)r*   urllibrequesturlopenr   info_read_pypi_response)r   urlresponser   r   r   r    `   s   
zregister.classifiersc                 C   s&   |  | d\}}td|| dS )z<Send the metadata to the package index server to be checked.r   Server response (%s): %sN)post_to_serverbuild_post_datar   r5   )r   coderesultr   r   r   r   f   s   zregister.verify_metadatac           
      C   s  | j rd}| j}| j}nd}d }}d }||vr5| dtj t }|s)d}n||vr1td ||vs|dkr|sAtd}|r;|sJt		d}|rCt
j }t
j| jd	 }|| j||| | | d
|\}}| d| d| tj |dkr| j r|| j_dS | dtj | d|   tj d}| dvrtd}|sd}| dvs| dkr| || dS dS dS |dkr^ddi}	d |	d<  |	d< |	d< d|	d< |	d std|	d< |	d r|	d |	d kr-|	d st		d|	d< |	d r|	d st		d|	d< |	d r|	d |	d kr%d|	d< d|	d< td |	d |	d ks|	d s=td|	d< |	d r2| |	\}}|dkrRtd || dS td! td" dS |d#krdd$i}	d|	d< |	d s{td%|	d< |	d rp| |	\}}td || dS dS )&a  Send the metadata to the package index server.

        Well, do the following:
        1. figure who the user is, and then
        2. send the data as a Basic auth'ed POST.

        First we try to read the username/password from $HOME/.pypirc,
        which is a ConfigParser-formatted file with a section
        [distutils] containing username and password entries (both
        in clear text). Eg:

            [distutils]
            index-servers =
                pypi

            [pypi]
            username: fred
            password: sekrit

        Otherwise, to figure who the user is, we offer the user three
        choices:

         1. use existing login,
         2. register as a new user, or
         3. set the password to a random string and email the user.

        1x z1 2 3 4zWe need to know who you are, so please choose either:
 1. use your existing login,
 2. register as a new user,
 3. have the server generate a new password for you (and email it to you), or
 4. quit
Your selection [default 1]: z&Please choose one of the four options!z
Username: z
Password: r   submitzServer response (z):    zAI can store your PyPI login so future submissions will be faster.z (the login will be stored in %s)XynzSave your login (y/N)?ny2:actionusernamer)   emailNconfirmz
 Confirm: z!Password and confirm don't match!z
   EMail: r9   z"You will receive an email shortly.z7Follow the instructions in it to complete registration.3password_resetzYour email address: )r.   r(   r)   splitannounceloggingINFOinputprintgetpassr2   r3   HTTPPasswordMgrparseurlparser*   add_passwordr+   r:   r;   r   _get_rc_filelower_store_pypircr   r5   )
r   choicer(   r)   choicesauthhostr<   r=   datar   r   r   r!   l   s   







	





zregister.send_metadatac                 C   s   | j j}i d|ddd| d| d| d| d| d	| d
| d|	 d|
 d| d| d| d| d| d| }|d sc|d sc|d rgd|d< |S )NrH   metadata_versionz1.0rJ   versionsummary	home_pageauthorauthor_emaillicensedescriptionkeywordsplatformr    download_urlprovidesrequires	obsoletesz1.1)r   metadataget_nameget_versionget_descriptionget_urlget_contactget_contact_emailget_licenceget_long_descriptionget_keywordsget_platformsget_classifiersget_download_urlget_providesget_requiresget_obsoletes)r   actionmetara   r   r   r   r;      sN   	
zregister.build_post_dataNc              
   C   s  d|v r|  d|d | jtj d}d| }|d }t }| D ]1\}}tt	t
|D ]%}	|| |d|  |d ||	 |	rT|	d d	krT|d
 q/q$|| |d
 | d}d| t	t|d}
tj| j||
}tjtjj|d}d}z||}W n; tjjy } z| jr|j }|j|jf}W Y d}~n(d}~w tjjy } zdt	|f}W Y d}~nd}~ww | jr| |}d}| jrd
d|df}|  |tj |S )z9Post a query to the server, and return a string response.rJ   zRegistering {} to {}z3--------------GHSKFJDLGDS7543FJKLFHRE75642756743254z
--z--z*
Content-Disposition: form-data; name="%s"z


zutf-8z/multipart/form-data; boundary=%s; charset=utf-8)zContent-typezContent-length)password_mgrr@   Ni  )rB   OKzK---------------------------------------------------------------------------)rP   formatr*   rQ   rR   ioStringIOitemsmapstrmake_iterablewritegetvalueencodelenr2   r3   Requestbuild_openerHTTPBasicAuthHandleropenerror	HTTPErrorshow_responsefpreadr<   msgURLErrorr6   join)r   ra   r_   boundarysep_boundaryend_boundarybodykeyvaluesvalueheadersreqopenerr=   er   r   r   r   r:   	  sd   








zregister.post_to_serverr   )__name__
__module____qualname__ri   r   user_optionsboolean_optionssub_commandsr   r   r#   r'   r   r    r   r!   r;   r:   r   r   r   r   r      s&    	 r   c                 C   s   | d u rd gS t | S r   r   )r   r   r   r   r   @  s   r   )__doc__rU   r   rQ   urllib.parser2   urllib.requestdistutils._logr   warningsr   
_itertoolsr   corer   r   r   r   r   r   r   <module>   s      .