U e5dÀ-ã@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ŽeZdZdZejddgZejdddgZddd „fgZd d „Zd d „Z dd„Z dd„Z dd„Z dd„Z dd„Zdd„Zdd„Zddd„ZdS) Ú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ÚverifyrrÚcheckcCsdS)NT©©Úselfr r ú2/usr/lib64/python3.8/distutils/command/register.pyÚózregister.cCst |¡d|_d|_dS)Nr)rÚinitialize_optionsÚlist_classifiersrr r r rrs zregister.initialize_optionscCs*t |¡d|jfddœ}||jjd<dS)Nr)ré)rÚrestructuredtextr )rÚfinalize_optionsrÚ distributionZcommand_options)r Z check_optionsr r rr$s  ÿzregister.finalize_optionscCsT| ¡| ¡| ¡D]}| |¡q|jr8| ¡n|jrH| ¡n| ¡dS)N) rÚ _set_configZget_sub_commandsZ run_commandZdry_runÚverify_metadatarÚ classifiersÚ send_metadata)r Zcmd_namer r rÚrun+s    z register.runcCs8tdtƒ|j d¡}| ¡|j|_d|_| ¡dS)zDeprecated API.zddistutils.command.register.check_metadata is deprecated, use the check command insteadr rN)rÚPendingDeprecationWarningrZget_command_objZensure_finalizedrrr)r r r r rÚcheck_metadata:sÿ zregister.check_metadatacCsz| ¡}|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 Zconfigr r rrDs     zregister._set_configcCs*|jd}tj |¡}t | |¡¡dS)z8 Fetch the list of classifiers from the server. z?:action=list_classifiersN)r ÚurllibÚrequestZurlopenrÚinfoÚ_read_pypi_response)r ZurlZresponser r rrUs  zregister.classifierscCs&| | d¡¡\}}t d||¡dS)zF Send the metadata to the package index server to be checked. r úServer response (%s): %sN)Úpost_to_serverÚbuild_post_datarr&)r ÚcodeÚresultr r rr\szregister.verify_metadatac CsÜ|jrd}|j}|j}n d}d}}d ¡}||krd| dtj¡tƒ}|sRd}q,||kr,tdƒq,|dkrl|s|tdƒ}qn|sŒt   d¡}q|t j   ¡}t j  |j¡d }| |j|||¡| | d ¡|¡\}}| d ||ftj¡|d krØ|jr||j_nf| d tj¡| d| ¡tj¡d}| ¡dkrNtdƒ}|s*d}q*| ¡dkrØ| ||¡nl|dkrˆddi} d| d<| d<| d<d| d<| ds¸tdƒ| d<qž| d| dkr0| dsæt   d¡| d<qÊ| dst   d¡| d<qæ| d| dkr¸d| d<d| d<tdƒq¸| dsJtdƒ| d<q0| | ¡\}}|d krrt d ||¡nt d¡t d ¡nP|d!krØdd"i} d| d<| ds¼td#ƒ| d<q¢| | ¡\}}t d ||¡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: rZsubmitr(éÈ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Ú2ú: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&) r ZchoicerrÚchoicesÚauthZhostr+r,Údatar r rrcsšú      ÿÿ  ÿÿÿ           zregister.send_metadatacCs|jj}|d| ¡| ¡| ¡| ¡| ¡| ¡| ¡|  ¡|  ¡|  ¡|  ¡|  ¡| ¡| ¡| ¡dœ}|ds„|ds„|drŒd|d<|S)Nz1.0)r5Úmetadata_versionr7Ú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_dataNc Csôd|kr$| d|d|jftj¡d}d|}|d}t ¡}| ¡D]~\}}t|ƒtgƒtdƒfkrn|g}|D]R}t|ƒ}|  |¡|  d|¡|  d¡|  |¡|rr|d d krr|  d ¡qrqH|  |¡|  d ¡|  ¡  d ¡}d |tt |ƒƒdœ} t j |j|| ¡} t j t jj|d¡} d}z|  | ¡} Wnxt jjk r€} z"|jrd| j ¡}| j| jf} W5d} ~ XYnJt jjk r²} zdt| ƒf} W5d} ~ XYnX|jrÆ| | ¡}d} |jrðd  d|df¡}| |tj¡| S)zC Post a query to the server, and return a string response. r7zRegistering %s to %sz3--------------GHSKFJDLGDS7543FJKLFHRE75642756743254z --z--r z* Content-Disposition: form-data; name="%s"z éÿÿÿÿú Ú zutf-8z/multipart/form-data; boundary=%s; charset=utf-8)z Content-typezContent-length)Z password_mgrr/Niô)r0ZOKzK---------------------------------------------------------------------------)r:r rr;ÚioÚStringIOÚitemsÚtypeÚstrÚwriteÚgetvalueÚencodeÚlenr$r%ZRequestZ build_openerZHTTPBasicAuthHandlerÚopenÚerrorZ HTTPErrorZ show_responseÚfpÚreadr+ÚmsgZURLErrorr'Újoin)r rCrBÚboundaryZ sep_boundaryZ end_boundaryZbodyÚkeyÚvalueZheadersZreqZopenerr,Úer_r r rr)ùs^ ÿþ      þ ÿ  zregister.post_to_server)N)Ú__name__Ú __module__Ú __qualname__rGrZ user_optionsZboolean_optionsZ sub_commandsrrrrrrrrr*r)r r r rrs*ýÿ zr)Ú__doc__r>rRZ urllib.parser$Zurllib.requestÚwarningsrZdistutils.corerZdistutils.errorsZ distutilsrrr r r rÚs