509318396
Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­
<!DOCTYPE html>
<html>
3

  \À-  ã               @   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dddg 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-classifiersNú list the valid Trove classifiersÚstrictúBWill stop the registering if the meta-data are not fully compliantÚverifyÚcheckc             C   s   dS )NT© )Úselfr   r   ú2/usr/lib64/python3.6/distutils/command/register.pyÚ<lambda>   s    zregister.<lambda>c             C   s   t j| ƒ d| _d| _d S )Nr   )r   Úinitialize_optionsÚlist_classifiersr	   )r   r   r   r   r      s    
zregister.initialize_optionsc             C   s*   t j| ƒ d| jfddœ}|| jjd< d S )Nr   é   )r	   Úrestructuredtextr   )r   r   )r   Úfinalize_optionsr	   ÚdistributionZcommand_options)r   Zcheck_optionsr   r   r   r   $   s    
zregister.finalize_optionsc             C   sX   | j ƒ  | jƒ  x| jƒ D ]}| j|ƒ qW | jr<| jƒ  n| jrL| jƒ  n| jƒ  d S )N)	r   Ú_set_configZget_sub_commandsZrun_commandZdry_runÚverify_metadatar   ÚclassifiersÚsend_metadata)r   Zcmd_namer   r   r   Úrun+   s    

zregister.runc             C   s8   t dtƒ | jjdƒ}|jƒ  | j|_d|_|jƒ  dS )zDeprecated API.zddistutils.command.register.check_metadata is deprecated,               use the check command insteadr   r   N)r   ÚPendingDeprecationWarningr   Zget_command_objZensure_finalizedr	   r   r   )r   r   r   r   r   Úcheck_metadata:   s    zregister.check_metadatac             C   sz   | j ƒ }|i kr@|d | _|d | _|d | _|d | _d| _n6| jd| jfkr^td| j ƒ‚| jdkrp| j| _d| _d	S )
z: Reads the configuration file and set attributes.
        ÚusernameÚpasswordÚ
repositoryÚrealmTZpypiz%s not found in .pypircFN)Z_read_pypircr   r   r    r!   Ú
has_configZDEFAULT_REPOSITORYÚ
ValueError)r   Úconfigr   r   r   r   D   s    




zregister._set_configc             C   s*   | j d }tjj|ƒ}tj| j|ƒƒ dS )z8 Fetch the list of classifiers from the server.
        z?:action=list_classifiersN)r    ÚurllibÚrequestZurlopenr   ÚinfoÚ_read_pypi_response)r   ZurlZresponser   r   r   r   U   s    
zregister.classifiersc             C   s&   | j | jdƒƒ\}}tjd||ƒ dS )zF Send the metadata to the package index server to be checked.
        r   zServer response (%s): %sN)Úpost_to_serverÚbuild_post_datar   r'   )r   ÚcodeÚresultr   r   r   r   \   s    zregister.verify_metadatac       
      C   s  | j rd}| j}| j}nd}d }}djƒ }x:||krf| jdtjƒ tƒ }|sTd}q.||kr.tdƒ q.W |dk�r|x|s‚tdƒ}qtW x|s–t	j	dƒ}q†W t
jjƒ }t
jj| jƒd	 }|j| j|||ƒ | j| jd
ƒ|ƒ\}}| jd||f tjƒ |dk�r | j �r|| j_nj| jdtjƒ | jd| jƒ  tjƒ d}x&|jƒ dk�r\tdƒ}|�s8d}�q8W |jƒ dk�r | j||ƒ �n„|dk�r¬ddi}	d |	d<  |	d< |	d< d|	d< x|	d �sÊtdƒ|	d< �q°W x‚|	d |	d k�rNx|	d �sþt	j	dƒ|	d< �qâW x|	d �st	j	dƒ|	d< �qW |	d |	d k�rÎd|	d< d|	d< tdƒ �qÎW x|	d �sltdƒ|	d< �qRW | j|	ƒ\}}|dk�r–tjd||ƒ ntjdƒ tjd ƒ nT|d!k�r dd"i}	d|	d< x|	d �sâtd#ƒ|	d< �qÈW | j|	ƒ\}}tjd||ƒ 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   ZsubmitzServer response (%s): %séÈ   zAI can store your PyPI login so future submissions will be faster.z (the login will be stored in %s)ÚXZynzSave your login (y/N)?ÚnÚyÚ2z:actionÚuserÚnamer   ZemailNZ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.Ú3Zpassword_resetzYour email address: )r"   r   r   ÚsplitÚannouncer   ÚINFOÚinputÚprintÚgetpassr%   r&   ZHTTPPasswordMgrÚparseZurlparser    Zadd_passwordr!   r)   r*   r   Z_get_rc_fileÚlowerZ_store_pypircr'   )
r   Zchoicer   r   ÚchoicesÚauthÚhostr+   r,   Údatar   r   r   r   c   sŒ    











zregister.send_metadatac             C   s�   | j j}|d|jƒ |jƒ |jƒ |jƒ |jƒ |jƒ |jƒ |j	ƒ |j
ƒ |jƒ |jƒ |jƒ |jƒ |jƒ |jƒ dœ}|d s„|d s„|d rŒd|d< |S )Nz1.0)z:actionÚmetadata_versionr6   ÚversionZsummaryZ	home_pageZauthorZauthor_emailÚlicenseÚdescriptionÚkeywordsÚplatformr   Zdownload_urlÚprovidesÚrequiresÚ	obsoletesrJ   rK   rL   z1.1rD   )r   ZmetadataZget_nameZget_versionZget_descriptionZget_urlZget_contactZget_contact_emailZget_licenceZget_long_descriptionZget_keywordsZget_platformsZget_classifiersZget_download_urlZget_providesZget_requiresZget_obsoletes)r   ÚactionÚmetarC   r   r   r   r*   Ý   s*    zregister.build_post_datac             C   s  d|kr$| j d|d | jf tjƒ d}d| }|d }tjƒ }xŽ|jƒ D ]‚\}}t|ƒtg ƒtf ƒfkrp|g}xZ|D ]R}t|ƒ}|j	|ƒ |j	d| ƒ |j	dƒ |j	|ƒ |rv|d d	krv|j	d
ƒ qvW qJW |j	|ƒ |j	d
ƒ |j
ƒ jdƒ}d| tt|ƒƒdœ}	tjj| j||	ƒ}
tjjtjj|d�ƒ}d}y|j|
ƒ}W nx tjjk
�rˆ } z$| j�rl|jjƒ }|j|jf}W Y dd}~X nJ tjjk
�rº } zdt|ƒf}W Y dd}~X nX | j�rÎ| j|ƒ}d}| j�r d
jdd |dd fƒ}| j |tjƒ |S )zC Post a query to the server, and return a string response.
        r6   zRegistering %s to %sz3--------------GHSKFJDLGDS7543FJKLFHRE75642756743254z
--z--z*
Content-Disposition: form-data; name="%s"z

r   úÚ
zutf-8z/multipart/form-data; boundary=%s; charset=utf-8)zContent-typezContent-length)Zpassword_mgrr/   Niô  r0   ÚOKú-éK   éÿÿÿÿ)r0   rQ   )r9   r    r   r:   ÚioÚStringIOÚitemsÚtypeÚstrÚwriteÚgetvalueÚencodeÚlenr%   r&   ZRequestZbuild_openerZHTTPBasicAuthHandlerÚopenÚerrorZ	HTTPErrorZshow_responseÚfpÚreadr+   ÚmsgZURLErrorr(   Újoin)r   rC   rA   ÚboundaryZsep_boundaryZend_boundaryZbodyÚkeyÚvalueZheadersZreqÚopenerr,   Úerb   r   r   r   r)   ù   sV    







zregister.post_to_server)r   Nr   )r	   Nr
   )N)Ú__name__Ú
__module__Ú__qualname__rG   r   Zuser_optionsZboolean_optionsZsub_commandsr   r   r   r   r   r   r   r   r*   r)   r   r   r   r   r      s&     
zr   )Ú__doc__r=   rU   Zurllib.parser%   Zurllib.requestÚwarningsr   Zdistutils.corer   Zdistutils.errorsZ	distutilsr   r   r   r   r   r   Ú<module>   s   