U +a-@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@seZdZdZejddgZejdddgZddd fgZd d Zd d Z ddZ 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 compliantverifyrrcheckcCsdS)NTselfr r N/tmp/pip-install-1bd_1mtk/setuptools/setuptools/_distutils/command/register.pyzregister.cCst|d|_d|_dS)Nr)rinitialize_optionslist_classifiersrr r r rrs zregister.initialize_optionscCs*t|d|jfdd}||jjd<dS)Nr)r)rrestructuredtextr )rfinalize_optionsr distributioncommand_options)r check_optionsr r rr$s  zregister.finalize_optionscCsT|||D]}||q|jr8|n|jrH|n|dS)N) r _set_configget_sub_commands run_commanddry_runverify_metadatar classifiers send_metadata)r cmd_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)rPendingDeprecationWarningrget_command_objensure_finalizedrrr!)r r r r rcheck_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. usernamepassword repositoryrealmTpypiz%s not found in .pypircFN) _read_pypircr&r'r(r) has_configDEFAULT_REPOSITORY ValueError)r configr r rrDs     zregister._set_configcCs*|jd}tj|}t||dS)z8 Fetch the list of classifiers from the server. z?:action=list_classifiersN)r(urllibrequesturlopenrinfo_read_pypi_response)r urlresponser 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_datarr3)r coderesultr r rr\szregister.verify_metadatac Cs|jrd}|j}|j}n d}d}}d}||krd|dtjt}|sRd}q,||kr,tdq,|dkrl|s|td}qn|st d}q|t j }t j |jd }||j|||||d |\}}|d ||ftj|d kr|jr||j_nf|d tj|d|tjd}|dkrNtd}|s*d}q*|dkr|||nl|dkrddi} d| d<| d<| d<d| d<| dstd| d<q| d| dkr0| dst d| d<q| dst d| d<q| d| dkrd| d<d| d<tdq| dsJtd| d<q0|| \}}|d krrtd ||ntdtd nP|d!krdd"i} d| d<| dstd#| d<q|| \}}td ||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: rZsubmitr7zAI 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:actionusernamer'emailNZconfirmz 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,r&r'splitannouncerINFOinputprintgetpassr0r1HTTPPasswordMgrparseurlparser( add_passwordr)r8r9r _get_rc_filelower _store_pypircr3) r choicer&r'choicesauthhostr:r;datar r rrcs                   zregister.send_metadatacCs|jj}|d|||||||| | | | | |||d}|ds|ds|drd|d<|S)Nz1.0)rDmetadata_versionrFversionsummaryZ home_pageauthor author_emaillicense descriptionkeywordsplatformr download_urlprovidesrequires obsoletesrerfrgz1.1r[)rmetadataget_name get_versionget_descriptionget_url get_contactget_contact_email get_licenceget_long_description get_keywords get_platformsget_classifiersget_download_url get_provides get_requires get_obsoletes)r actionmetarZr r rr9s,zregister.build_post_dataNc Csd|kr$|d|d|jftjd}d|}|d}t}|D]~\}}t|tgtdfkrn|g}|D]R}t|}| || d|| d| ||rr|d d krr| d qrqH| || d | d }d |tt |d} t j|j|| } t jt jj|d} d}z| | } Wnxt jjk r} z"|jrd| j}| j| jf} W5d} ~ XYnJt jjk r} zdt| f} W5d} ~ XYnX|jr|| }d} |jrd d|df}||tj| S)zC Post a query to the server, and return a string response. rFzRegistering %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) password_mgrr>Ni)r?OKzK---------------------------------------------------------------------------)rJr(rrKioStringIOitemstypestrwritegetvalueencodelenr0r1Request build_openerHTTPBasicAuthHandleropenerror HTTPError show_responsefpreadr:msgURLErrorr4join)r rZrXboundaryZ sep_boundaryZ end_boundarybodykeyvalueheadersreqopenerr;err r rr8s^          zregister.post_to_server)N)__name__ __module__ __qualname__rar user_optionsboolean_options sub_commandsrrr!r%rrrrr9r8r r r rrs* zr)__doc__rNr urllib.parser0urllib.requestwarningsrdistutils.corerdistutils.errors distutilsrrr r r rs