B \·^|@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)zlist-classifiersNz list the valid Trove classifiers)strictNzBWill stop the registering if the meta-data are not fully compliantverifyzlist-classifiersrcheckcCsdS)NT)selfr r ?/opt/alt/python37/lib64/python3.7/distutils/command/register.pyzregister.cCst|d|_d|_dS)Nr)rinitialize_optionslist_classifiersr)r r r r rs zregister.initialize_optionscCs*t|d|jfdd}||jjd<dS)Nr)r)rrestructuredtextr )rfinalize_optionsr distributionZcommand_options)r Z check_optionsr r r r$s zregister.finalize_optionscCsX||x|D]}||qW|jr<|n|jrL|n|dS)N) r _set_configZget_sub_commandsZ run_commandZdry_runverify_metadatar classifiers send_metadata)r Zcmd_namer r r run+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 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. usernamepassword repositoryrealmTZpypiz%s not found in .pypircFN)Z _read_pypircrrrr has_configZDEFAULT_REPOSITORY ValueError)r Zconfigr r r rDs     zregister._set_configcCs*|jd}tj|}t||dS)z8 Fetch the list of classifiers from the server. z?:action=list_classifiersN)rurllibrequestZurlopenrinfo_read_pypi_response)r ZurlZresponser r r rUs  zregister.classifierscCs&||d\}}td||dS)zF Send the metadata to the package index server to be checked. rzServer response (%s): %sN)post_to_serverbuild_post_datarr$)r coderesultr r r r\szregister.verify_metadatac Cs|jrd}|j}|j}n d}d}}d}x:||krf|dtjt}|sTd}q.||kr.tdq.W|dkr|x|std}qtWx|st d}qWt j }t j |jd }||j|||||d |\}}|d ||ftj|d kr|jr||j_nj|d tj|d|tjd}x&|dkr\td}|s8d}q8W|dkr|||n|dkrddi} d| d<| d<| d<d| d<x| dstd| d<qWx| d| dkrNx| dst d| d<qWx| dst d| d<qW| d| dkrd| d<d| d<tdqWx| dsltd| d<qRW|| \}}|d krtd ||ntdtd nT|d!krdd"i} d| d<x| dstd#| d<qW|| \}}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: 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#ZHTTPPasswordMgrparseZurlparserZ add_passwordrr&r'rZ _get_rc_filelowerZ _store_pypircr$) r ZchoicerrchoicesauthZhostr(r)datar r r rcs                     zregister.send_metadatacCs|jj}|d|||||||| | | | | |||d}|ds|ds|drd|d<|S)Nz1.0)z:actionmetadata_versionr3versionZsummaryZ home_pageZauthorZ author_emaillicense descriptionkeywordsplatformrZ download_urlprovidesrequires obsoletesrFrGrHz1.1r@)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 actionmetar?r r r r's* zregister.build_post_dataNc Csd|kr$|d|d|jftjd}d|}|d}t}x|D]\}}t|tgtdfkrp|g}xZ|D]R}t|}| || d|| d| ||rv|d d krv| d qvWqJW| || d | d }d |tt |d} t j|j|| } t jt jj|d} d}y| | } Wnxt jjk r} z"|jrl| j}| j| jf} Wdd} ~ XYnJt jjk r} zdt| f} Wdd} ~ XYnX|jr|| }d} |jrd d|df}||tj| S)zC Post a query to the server, and return a string response. r3zRegistering %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)r-ZOKzK---------------------------------------------------------------------------)r6rrr7ioStringIOitemstypestrwritegetvalueencodelenr"r#ZRequestZ build_openerZHTTPBasicAuthHandleropenerrorZ HTTPErrorZ show_responsefpreadr(msgZURLErrorr%join)r r?r>boundaryZ sep_boundaryZ end_boundaryZbodykeyvalueZheadersZreqopenerr)er[r r r r&sV         zregister.post_to_server)N)__name__ __module__ __qualname__rCrZ user_optionsZboolean_optionsZ sub_commandsrrrrrrrrr'r&r r r r rs"  zr)__doc__r:rNZ urllib.parser"Zurllib.requestwarningsrZdistutils.corerZdistutils.errorsZ distutilsrrr r r r s