3 \À-ã@sddZddlZddlZddlZddlZddlmZddlm Z ddl Tddl m Z Gdd„de ƒZ dS) zhdistutils.command.register Implements the Distutils 'register' command (register with the repository). éN)Úwarn)Ú PyPIRCCommand)Ú*)Úlogc@sŽeZdZdZejdd gZejdddgZdd d „fgZd d „Zd d„Z dd„Z dd„Z dd„Z dd„Z dd„Zdd„Zdd„Zd!dd„ZdS)"Ú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ÚcheckcCsdS)NT©)Úselfr r ú2/usr/lib64/python3.6/distutils/command/register.pyÚszregister.cCstj|ƒd|_d|_dS)Nr)rÚinitialize_optionsÚlist_classifiersr )rr r rrs zregister.initialize_optionscCs*tj|ƒd|jfddœ}||jjd<dS)Nré)r Úrestructuredtextr )rr)rÚfinalize_optionsr Ú distributionZcommand_options)rZ check_optionsr r rr$s zregister.finalize_optionscCsX|jƒ|jƒx|jƒD]}|j|ƒqW|jr<|jƒn|jrL|jƒn|jƒdS)N) rÚ _set_configZget_sub_commandsZ run_commandZdry_runÚverify_metadatarÚ classifiersÚ send_metadata)rZcmd_namer r rÚrun+s  z register.runcCs8tdtƒ|jjdƒ}|jƒ|j|_d|_|jƒdS)zDeprecated API.zddistutils.command.register.check_metadata is deprecated, use the check command insteadr rN)rÚPendingDeprecationWarningrZget_command_objZensure_finalizedr rr)rr r r rÚcheck_metadata:s zregister.check_metadatacCsz|jƒ}|ikr@|d|_|d|_|d|_|d|_d|_n6|jd|jfkr^td|jƒ‚|jdkrp|j|_d|_d S) z: Reads the configuration file and set attributes. ÚusernameÚpasswordÚ repositoryÚrealmTZpypiz%s not found in .pypircFN)Z _read_pypircrrr r!Ú has_configZDEFAULT_REPOSITORYÚ ValueError)rÚconfigr r rrDs     zregister._set_configcCs*|jd}tjj|ƒ}tj|j|ƒƒdS)z8 Fetch the list of classifiers from the server. z?:action=list_classifiersN)r ÚurllibÚrequestZurlopenrÚinfoÚ_read_pypi_response)rZurlZresponser r rrUs  zregister.classifierscCs&|j|jdƒƒ\}}tjd||ƒdS)zF Send the metadata to the package index server to be checked. r zServer response (%s): %sN)Úpost_to_serverÚbuild_post_datarr')rÚcodeÚresultr r rr\szregister.verify_metadatac Cs|jrd}|j}|j}n d}d}}djƒ}x:||krf|jdtjƒtƒ}|sTd}q.||kr.tdƒq.W|dk�r|x|s‚tdƒ}qtWx|s–t j dƒ}q†Wt j j ƒ}t j j|jƒd }|j|j|||ƒ|j|jd ƒ|ƒ\}}|jd ||ftjƒ|d k�r|j�r||j_nj|jd tjƒ|jd|jƒtjƒd}x&|jƒdk�r\tdƒ}|�s8d}�q8W|jƒdk�r|j||ƒ�n„|dk�r¬ddi} d| d<| d<| d<d| d<x| d�sÊtdƒ| d<�q°Wx‚| d| dk�rNx| d�sþt j dƒ| d<�qâWx| d�st j dƒ| d<�qW| d| dk�rÎd| d<d| d<tdƒ�qÎWx| d�sltdƒ| d<�qRW|j| ƒ\}}|d k�r–tjd ||ƒntjdƒtjd ƒnT|d!k�rdd"i} d| d<x| d�sâtd#ƒ| d<�qÈW|j| ƒ\}}tjd ||ƒdS)$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Úz1 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: rZsubmitzServer response (%s): %séÈzAI can store your PyPI login so future submissions will be faster.z (the login will be stored in %s)ÚXZynzSave your login (y/N)?ÚnÚyÚ2z:actionÚuserÚnamerZemailNZconfirmz 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.Ú3Zpassword_resetzYour email address: )r"rrÚsplitÚannouncerÚINFOÚinputÚprintÚgetpassr%r&ZHTTPPasswordMgrÚparseZurlparser Z add_passwordr!r)r*rZ _get_rc_fileÚlowerZ _store_pypircr') rZchoicerrÚchoicesÚauthÚhostr+r,Údatar r rrcsŒ                     zregister.send_metadatacCs�|jj}|d|jƒ|jƒ|jƒ|jƒ|jƒ|jƒ|jƒ|j ƒ|j ƒ|j ƒ|j ƒ|j ƒ|jƒ|jƒ|jƒdœ}|ds„|ds„|drŒd|d<|S)Nz1.0)z:actionÚmetadata_versionr6ÚversionZsummaryZ home_pageZauthorZ author_emailÚlicenseÚ descriptionÚkeywordsÚplatformrZ download_urlÚprovidesÚrequiresÚ obsoletesrJrKrLz1.1rD)rZmetadataZget_nameZ get_versionZget_descriptionZget_urlZ get_contactZget_contact_emailZ get_licenceZget_long_descriptionZ get_keywordsZ get_platformsZget_classifiersZget_download_urlZ get_providesZ get_requiresZ get_obsoletes)rÚactionÚmetarCr r rr*Ýs* zregister.build_post_datacCsd|kr$|jd|d|jftjƒd}d|}|d}tjƒ}xŽ|jƒD]‚\}}t|ƒtgƒtfƒfkrp|g}xZ|D]R}t|ƒ}|j |ƒ|j d|ƒ|j dƒ|j |ƒ|rv|dd krv|j d ƒqvWqJW|j |ƒ|j d ƒ|j ƒj d ƒ}d |tt |ƒƒd œ} t jj|j|| ƒ} t jjt jj|d�ƒ} d}y| j| ƒ} Wnxt jjk �rˆ} z$|j�rl| jjƒ}| j| jf} WYdd} ~ XnJt jjk �rº} zdt| ƒf} WYdd} ~ XnX|j�rÎ|j| ƒ}d} |j�rd jdd|ddfƒ}|j|tjƒ| S)zC Post a query to the server, and return a string response. r6zRegistering %s to %sz3--------------GHSKFJDLGDS7543FJKLFHRE75642756743254z --z--z* Content-Disposition: form-data; name="%s"z rú Ú zutf-8z/multipart/form-data; boundary=%s; charset=utf-8)z Content-typezContent-length)Z password_mgrr/Niôr0ÚOKú-éKéÿÿÿÿ)r0rQ)r9r rr:ÚioÚStringIOÚitemsÚtypeÚstrÚwriteÚgetvalueÚencodeÚlenr%r&ZRequestZ build_openerZHTTPBasicAuthHandlerÚopenÚerrorZ HTTPErrorZ show_responseÚfpÚreadr+ÚmsgZURLErrorr(Újoin)rrCrAÚboundaryZ sep_boundaryZ end_boundaryZbodyÚkeyÚvalueZheadersZreqÚopenerr,Úerbr r rr)ùsV         zregister.post_to_server)rNr)r Nr )N)Ú__name__Ú __module__Ú __qualname__rGrZ user_optionsZboolean_optionsZ sub_commandsrrrrrrrrr*r)r r r rrs&  zr)Ú__doc__r=rUZ urllib.parser%Zurllib.requestÚwarningsrZdistutils.corerZdistutils.errorsZ distutilsrrr r r rÚs