3  f-@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@seZdZdZejdd gZejdddgZdd d fgZd d Zd dZ ddZ ddZ ddZ ddZ ddZddZddZd!ddZdS)"registerz7register the distribution with the Python package indexlist-classifiersN list the valid Trove classifiersstrictBWill stop the registering if the meta-data are not fully compliantverifycheckcCsdS)NT)selfr r ?/opt/alt/python36/lib64/python3.6/distutils/command/register.pyszregister.cCstj|d|_d|_dS)Nr)rinitialize_optionslist_classifiersr )rr r rrs zregister.initialize_optionscCs*tj|d|jfdd}||jjd<dS)Nr)r restructuredtextr )rr)rfinalize_optionsr distributionZcommand_options)rZ check_optionsr r rr$s zregister.finalize_optionscCsX|j|jx|jD]}|j|qW|jr<|jn|jrL|jn|jdS)N) r _set_configZget_sub_commandsZ run_commandZdry_runverify_metadatar classifiers send_metadata)rZcmd_namer r rrun+s  z register.runcCs8tdt|jjd}|j|j|_d|_|jdS)zDeprecated API.zddistutils.command.register.check_metadata is deprecated, use the check command insteadr rN)rPendingDeprecationWarningrZget_command_objZensure_finalizedr rr)rr r r rcheck_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. usernamepassword repositoryrealmTZpypiz%s not found in .pypircFN)Z _read_pypircrrr r! has_configZDEFAULT_REPOSITORY ValueError)rconfigr r rrDs     zregister._set_configcCs*|jd}tjj|}tj|j|dS)z8 Fetch the list of classifiers from the server. z?:action=list_classifiersN)r urllibrequestZurlopenrinfo_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_serverbuild_post_datarr')rcoderesultr r rr\szregister.verify_metadatac Cs|jrd}|j}|j}n d}d}}dj}x:||krf|jdtjt}|sTd}q.||kr.tdq.W|dkr|x|std}qtWx|st j d}qWt j j }t j j|jd }|j|j||||j|jd |\}}|jd ||ftj|d kr|jr||j_nj|jd tj|jd|jtjd}x&|jdkr\td}|s8d}q8W|jdkr|j||n|dkrddi} d| d<| d<| d<d| d<x| dstd| d<qWx| d| dkrNx| dst j d| d<qWx| dst j d| d<qW| d| dkrd| d<d| d<tdqWx| dsltd| d<qRW|j| \}}|d krtjd ||ntjdtjd nT|d!krdd"i} d| d<x| dstd#| d<qW|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. 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: rZsubmitzServer response (%s): %szAI can store your PyPI login so future submissions will be faster.z (the login will be stored in %s)XZynzSave your login (y/N)?ny2z: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') rZchoicerrchoicesauthhostr+r,datar r rrcs                     zregister.send_metadatacCs|jj}|d|j|j|j|j|j|j|j|j |j |j |j |j |j|j|jd}|ds|ds|drd|d<|S)Nz1.0)z:actionmetadata_versionr6versionZsummaryZ home_pageZauthorZ author_emaillicense descriptionkeywordsplatformrZ download_urlprovidesrequires 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)ractionmetarCr r rr*s* zregister.build_post_datacCsd|kr$|jd|d|jftjd}d|}|d}tj}x|jD]\}}t|tgtffkrp|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$|jrl| jj}| j| jf} WYdd} ~ XnJt jjk r} zdt| f} WYdd} ~ XnX|jr|j| }d} |jrd 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/Nir0OK-K)r0rQ)r9r rr:ioStringIOitemstypestrwritegetvalueencodelenr%r&ZRequestZ build_openerZHTTPBasicAuthHandleropenerrorZ HTTPErrorZ show_responsefpreadr+msgZURLErrorr(join)rrCrAboundaryZ sep_boundaryZ end_boundaryZbodykeyvalueZheadersZreqopenerr,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.requestwarningsrZdistutils.corerZdistutils.errorsZ distutilsrrr r r rs