o
    Ëý°jÀ-  ã                   @   sd   d 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
T ddlmZ G dd„ de	ƒZdS )	zhdistutils.command.register

Implements the Distutils 'register' command (register with the repository).
é    N)Úwarn)ÚPyPIRCCommand)Ú*)Úlogc                   @   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   ú™/root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/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   Úrun+   s   zregister.runc                 C   s8   t dtƒ | j d¡}| ¡  | j|_d|_| ¡  dS )zDeprecated API.zddistutils.command.register.check_metadata is deprecated,               use the check command insteadr
   r   N)r   ÚPendingDeprecationWarningr   Úget_command_objÚensure_finalizedr   r   r!   )r   r
   r   r   r   Úcheck_metadata:   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 )
z: Reads 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   D   s   






zregister._set_configc                 C   s*   | j d }tj |¡}t |  |¡¡ dS )z8 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   U   s   
zregister.classifiersc                 C   s&   |   |  d¡¡\}}t d||¡ dS )zF Send the metadata to the package index server to be checked.
        r	   úServer response (%s): %sN)Úpost_to_serverÚbuild_post_datar   r3   )r   ÚcodeÚresultr   r   r   r   \   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||f tj¡ |dkrº| j r„|| j_dS |  dtj¡ |  d|  ¡  tj¡ d}| ¡ dvr¬tdƒ}|s¦d}| ¡ 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 såtdƒ|	d< |	d rÛ|	d |	d k�r+|	d sýt	 	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 �r0|  |	¡\}}|dk�rPt d||¡ dS t d¡ t d ¡ dS |d!k�r‰dd"i}	d|	d< |	d �sytd#ƒ|	d< |	d �rn|  |	¡\}}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 4zâWe 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   Úsubmitr7   éÈ   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: 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Úannouncer   ÚINFOÚinputÚprintÚgetpassr0   r1   ÚHTTPPasswordMgrÚparseÚurlparser(   Úadd_passwordr)   r8   r9   r   Ú_get_rc_fileÚlowerÚ_store_pypircr3   )
r   Úchoicer&   r'   ÚchoicesÚauthÚhostr:   r;   Údatar   r   r   r   c   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 )NrF   Úmetadata_versionz1.0rH   Ú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Úmetar^   r   r   r   r9   Ý   sN   ÿþýüûúùø	÷
öõôóòðïîzregister.build_post_dataNc              
   C   sî  d|v r|   d|d | jf tj¡ d}d| }|d }t ¡ }| ¡ D ]?\}}t|ƒtg ƒtdƒfvr7|g}|D ])}t|ƒ}| 	|¡ | 	d| ¡ | 	d¡ | 	|¡ |rb|d	 d
krb| 	d¡ q9q$| 	|¡ | 	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rõd d|df¡}|   |tj¡ |S )zC Post a query to the server, and return a string response.
        rH   zRegistering %s to %sz3--------------GHSKFJDLGDS7543FJKLFHRE75642756743254z
--z--r   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ô  )r@   ÚOKzK---------------------------------------------------------------------------)rN   r(   r   rO   ÚioÚStringIOÚitemsÚtypeÚstrÚwriteÚgetvalueÚencodeÚlenr0   r1   ÚRequestÚbuild_openerÚHTTPBasicAuthHandlerÚopenÚerrorÚ	HTTPErrorÚshow_responseÚfpÚreadr:   ÚmsgÚURLErrorr4   Újoin)r   r^   r\   ÚboundaryÚsep_boundaryÚend_boundaryÚbodyÚkeyÚvalueÚheadersÚreqÚopenerr;   Úer–   r   r   r   r8   ù   sh   ÿþ



€ù


þÿ
€€ÿ
zregister.post_to_serverr   )Ú__name__Ú
__module__Ú__qualname__rf   r   Úuser_optionsÚboolean_optionsÚsub_commandsr   r   r!   r%   r   r   r   r   r9   r8   r   r   r   r   r      s$    ý
zr   )Ú__doc__rR   r„   Úurllib.parser0   Úurllib.requestÚwarningsr   Údistutils.corer   Údistutils.errorsÚ	distutilsr   r   r   r   r   r   Ú<module>   s    