o ?Og-@sddZddlZddlZddlZddlZddlmZddlm Z ddl Tddl m Z Gddde Z dS) zhdistutils.command.register Implements the Distutils 'register' command (register with the repository). N)warn) PyPIRCCommand)*)logc@seZdZdZejddgZejgdZdddfgZdd Zd d Z d d Z ddZ ddZ ddZ ddZddZddZdddZdS)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)verifyrrcheckcCsdS)NTselfr r A/opt/alt/python310/lib64/python3.10/distutils/command/register.pyszregister.cCst|d|_d|_dS)Nr)rinitialize_optionslist_classifiersrr r r rrs  zregister.initialize_optionscCs*t|d|jfdd}||jjd<dS)Nr)r)rrestructuredtextr )rfinalize_optionsr distributionZcommand_options)r Z check_optionsr r rr$s zregister.finalize_optionscCsX|||D]}||q |jr|dS|jr&|dS|dSN) r _set_configZget_sub_commandsZ run_commandZdry_runverify_metadatar classifiers send_metadata)r Zcmd_namer r rrun+s     z register.runcCs8tdt|jd}||j|_d|_|dS)zDeprecated API.zddistutils.command.register.check_metadata is deprecated, use the check command insteadr rN)rPendingDeprecationWarningrZget_command_objZensure_finalizedrrr)r r r r rcheck_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. usernamepassword repositoryrealmTZpypiz%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 urllibrequestZurlopenrinfo_read_pypi_response)r ZurlZresponser r rrUs  zregister.classifierscCs&||d\}}td||dS)zF Send the metadata to the package index server to be checked. r Server response (%s): %sN)post_to_serverbuild_post_datarr&)r coderesultr r rr\szregister.verify_metadatac Cs|jr d}|j}|j}nd}d}}d}||vr5|dtjt}|s)d}n||vr1td||vs|dkr|sAtd}|r;|sJt d}|rCt j }t j |jd }||j|||||d |\}}|d ||ftj|d kr|jr||j_dS|d tj|d|tjd}|dvrtd}|sd}|dvs|dkr|||dSdSdS|dkr\ddi} d| d<| d<| d<d| d<| dstd| d<| dr| d| dkr+| dst d| d<| dr| dst d| d<| dr| d| dkr#d| d<d| d<td| d| dks| ds;td| d<| dr0|| \}}|d krPtd ||dStdtd dS|d!krdd"i} d| d<| dsytd#| d<| drn|| \}}td ||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. 1xz1 2 3 4zWe 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)?ny2:actionusernamerZemailNZconfirmz 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"rrsplitannouncerINFOinputprintgetpassr$r%ZHTTPPasswordMgrparseZurlparser Z add_passwordr!r)r*rZ _get_rc_filelowerZ _store_pypircr&) r ZchoicerrchoicesauthZhostr+r,datar r rrcs                  zregister.send_metadatacCs|jj}id|ddd|d|d|d|d|d |d |d | d | d | d| d| d|d|d|}|dsc|dsc|drgd|d<|S)Nr5Zmetadata_versionz1.0r7versionZsummaryZ home_pageZauthorZ author_emaillicense descriptionkeywordsplatformrZ 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 actionmetarCr r rr*sN     zregister.build_post_dataNc Csd|vr|d|d|jftjd}d|}|d}t}|D]?\}}t|tgtdfvr7|g}|D])}t|}| || d|| d| ||rb|d d krb| d q9q$| || d | d }d |tt |d} t j|j|| } t jt 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} |jrd 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;ioStringIOitemstypestrwritegetvalueencodelenr$r%ZRequestZ build_openerZHTTPBasicAuthHandleropenerrorZ HTTPErrorZ show_responsefpreadr+msgZURLErrorr'join)r rCrBboundaryZ sep_boundaryZ end_boundarybodykeyvalueZheadersZreqZopenerr,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.requestwarningsrZdistutils.corerZdistutils.errorsZ distutilsrrr r r rs