o ­=?hÀ-ã@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ŒeZdZdZejddgZejgd¢Zddd„fgZdd „Zd d „Z d d „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 úA/opt/alt/python310/lib64/python3.10/distutils/command/register.pyÚszregister.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_optionscCsX| ¡| ¡| ¡D]}| |¡q |jr| ¡dS|jr&| ¡dS| ¡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_metadatacCs|| ¡}|ikr!|d|_|d|_|d|_|d|_d|_d S|jd|jfvr0td|jƒ‚|jdkr9|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|jr d}|j}|j}nd}d}}d ¡}||vr5| dtj¡tƒ}|s)d}n||vr1tdƒ||vs|dkr¾|sAtdƒ}|r;|sJt   d¡}|rCt j   ¡}t j  |j¡d }| |j|||¡| | d ¡|¡\}}| d ||ftj¡|d krº|jr„||j_dS| d tj¡| d| ¡tj¡d}| ¡dvr¬tdƒ}|s¦d}| ¡dvsž| ¡dkr¼| ||¡dSdSdS|dkr\ddi} d| d<| d<| d<d| d<| dsåtdƒ| d<| drÛ| d| dkr+| dsýt   d¡| d<| drò| dst   d¡| d<| dr| d| dkr#d| d<d| d<tdƒ| d| dksî| ds;tdƒ| d<| dr0| | ¡\}}|d krPt d ||¡dSt d¡t d ¡dS|d!kr‰dd"i} d| d<| dsytd#ƒ| d<| drn| | ¡\}}t d ||¡dSdS)$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}id|“dd“d| ¡“d| ¡“d| ¡“d| ¡“d| ¡“d | ¡“d | ¡“d |  ¡“d |  ¡“d |  ¡“d|  ¡“d|  ¡“d| ¡“d| ¡“d| ¡“}|dsc|dsc|drgd|d<|S)Nr5Zmetadata_versionz1.0r7ÚversionZsummaryZ home_pageZauthorZ author_emailÚlicenseÚ descriptionÚkeywordsÚplatformrZ download_urlZprovidesZrequiresZ obsoletesz1.1)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*ÝsNÿþýüûúùø ÷ ö õ ô óòðïîzregister.build_post_dataNc Csîd|vr| d|d|jftj¡d}d|}|d}t ¡}| ¡D]?\}}t|ƒtgƒtdƒfvr7|g}|D])}t|ƒ}|  |¡|  d|¡|  d¡|  |¡|rb|d d krb|  d ¡q9q$|  |¡|  d ¡|  ¡  d ¡}d |tt |ƒƒdœ} t j |j|| ¡} t j t jj|d¡} d}z|  | ¡} Wn;t jjy¿} z|jr¯| j ¡}| j| jf} WYd} ~ n(d} ~ wt jjyØ} z dt| ƒf} WYd} ~ nd} ~ ww|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_boundaryÚbodyÚkeyÚvalueZheadersZreqZopenerr,Úer[r r rr)ùsh ÿþ    €ù   þ ÿ €€ÿ zregister.post_to_serverr)Ú__name__Ú __module__Ú __qualname__rFrZ user_optionsZboolean_optionsZ sub_commandsrrrrrrrrr*r)r r r rrs$ý zr)Ú__doc__r>rNZ urllib.parser$Zurllib.requestÚwarningsrZdistutils.corerZdistutils.errorsZ distutilsrrr r r rÚs