�`^c@szdZdZddlZddlZddlZddlmZddlmZddl m
Z
defd��YZdS( shdistutils.command.register
Implements the Distutils 'register' command (register with the repository).
s$Id$i�N(twarn(t
PyPIRCCommand(tlogtregistercBs�eZdZejddgZejdddgZdd�fgZd�Zd �Z d
�Z
d�Zd�Zd
�Z
d�Zd�Zd�Zdd�ZRS(s7register the distribution with the Python package indexslist-classifierss list the valid Trove classifierststrictsBWill stop the registering if the meta-data are not fully complianttverifytcheckcCstS(N(tTrue(tself((s0/sys/lib/python2.7/distutils/command/register.pyt<lambda>scCs#tj|�d|_d|_dS(Ni(Rtinitialize_optionstlist_classifiersR(R((s0/sys/lib/python2.7/distutils/command/register.pyR
s
cCs>tj|�id|jfd6dd6}||jjd<dS(NRRitrestructuredtextR(sregisteri(Rtfinalize_optionsRtdistributiontcommand_options(Rt
check_options((s0/sys/lib/python2.7/distutils/command/register.pyR
%s
cCsr|j�|j�x!|j�D]}|j|�q!W|jrN|j�n |jrd|j�n
|j�dS(N( R
t_set_configtget_sub_commandstrun_commandtdry_runtverify_metadataRtclassifierst
send_metadata(Rtcmd_name((s0/sys/lib/python2.7/distutils/command/register.pytrun,s
cCsLtdt�|jjd�}|j�|j|_d|_|j�dS(sDeprecated API.sddistutils.command.register.check_metadata is deprecated, use the check command insteadRiN(RtPendingDeprecationWarningRtget_command_objtensure_finalizedRRR(RR((s0/sys/lib/python2.7/distutils/command/register.pytcheck_metadata;s
cCs�|j�}|ikrX|d|_|d|_|d|_|d|_t|_nU|jd|jfkr�td|j��n|jdkr�|j|_nt |_dS(s: Reads the configuration file and set attributes.
tusernametpasswordt
repositorytrealmtpypis%s not found in .pypircN(
t_read_pypircRRR R!Rt
has_configtDEFAULT_REPOSITORYt
ValueErrortFalse(Rtconfig((s0/sys/lib/python2.7/distutils/command/register.pyREs
cCs-tj|jd�}tj|j��dS(s8 Fetch the list of classifiers from the server.
s?:action=list_classifiersN(turllib2turlopenR Rtinfotread(Rtresponse((s0/sys/lib/python2.7/distutils/command/register.pyRVscCs9|j|jd��\}}tjd||f�dS(sF Send the metadata to the package index server to be checked.
RsServer response (%s): %sN(tpost_to_servertbuild_post_dataRR+(Rtcodetresult((s0/sys/lib/python2.7/distutils/command/register.pyR\sc
Cs�|jr$d}|j}|j}nd}d}}dj�}xO||kr�|jdtj�t�}|szd}qC||krCdGHqCqCW|dkrx|s�td�}q�Wx|s�tjd�}q�Wt j
�}tj|j�d }|j
|j|||�|j|jd
�|�\}}|jd||ftj�|dkr�jrp||j_q|jd
tj�|jd|j�tj�d}x1|j�dkr�td�}|s�d}q�q�W|j�dkr|j||�qq��|dkroidd6} d| d<| d<| d<d#| d<x| dsbtd�| d<qEWx�| d| dkr�| ds�tjd�| d<q}Wx!| ds�tjd�| d<q�W| d| dkrfd| d<d#| d<dGHqfqfWx| dstd�| d<q�j| �\}}|dkrRtjd||f�q�jd�tjd�ns|d kr�d!d6} d| d<x| ds�td"�| d<q�W|j| �\}}tjd||f�nd#S($s_ 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.
t1txts1 2 3 4s�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]: s&Please choose one of the four options!s
Username: s
Password: itsubmitsServer response (%s): %si�sAI can store your PyPI login so future submissions will be faster.s (the login will be stored in %s)tXtynsSave your login (y/N)?tntyt2tusers:actiontnameRtemailtconfirms
Confirm: s!Password and confirm don't match!s
EMail: s"You will receive an email shortly.s7Follow the instructions in it to complete registration.t3tpassword_resetsYour email address: N(R$RRtsplittannounceRtINFOt raw_inputtgetpassR)tHTTPPasswordMgrturlparseR tadd_passwordR!R.R/Rt_get_rc_filetlowert
_store_pypirctNoneR+(
RtchoiceRRtchoicestauththostR0R1tdata((s0/sys/lib/python2.7/distutils/command/register.pyRds�
cCs|jj}i|d6dd6|j�d6|j�d6|j�d6|j�d6|j�d6|j�d 6|j�d
6|j �d6|j
�d6|j�d
6|j�d6|j
�d6|j�d6|j�d6|j�d6}|ds|ds|drd|d<n|S(Ns:actions1.0tmetadata_versionR<tversiontsummaryt home_pagetauthortauthor_emailtlicensetdescriptiontkeywordstplatformRtdownload_urltprovidestrequirest obsoletess1.1(Rtmetadatatget_nametget_versiontget_descriptiontget_urltget_contacttget_contact_emailtget_licencetget_long_descriptiontget_keywordst
get_platformstget_classifierstget_download_urltget_providestget_requirest
get_obsoletes(RtactiontmetaRQ((s0/sys/lib/python2.7/distutils/command/register.pyR/�s,
cCs�d|kr3|jd|d|jftj�nd}d|}|d}g}x�|j�D]�\}}t|�tg�td�fkr�|g}nxl|D]d}|j|�|jd|�|jd�|j|�|r�|dd kr�|jd
�q�q�Wq`W|j|�|jd
�g} xC|D];}
t|
t�rd| j|
j d��q6| j|
�q6Wdj
| �} id
|d6tt| ��d6}t
j|j| |�}t
jt
jd|��}
d}y|
j|�}Wnjt
jk
r9}|jr$|jj�}n|j|jf}nFt
jk
r`}dt|�f}nX|jry|j�}nd}|jr�dd}|jd|||f�n|S(sC Post a query to the server, and return a string response.
R<sRegistering %s to %ss3--------------GHSKFJDLGDS7543FJKLFHRE75642756743254s
--s--s*
Content-Disposition: form-data; name="%s"s
i�s
s
sutf-8R4s/multipart/form-data; boundary=%s; charset=utf-8sContent-typesContent-lengthtpassword_mgri�i�tOKt-iKs%s%s%s((i�Rs(RBR RRCtitemsttypetappendt
isinstancetunicodetencodetjointstrtlenR)tRequesttbuild_openertHTTPBasicAuthHandlertopent HTTPErrort
show_responsetfpR,R0tmsgtURLError(RRQROtboundarytsep_boundarytend_boundarytchunkstkeytvaluetbodytchunktheaderstreqtopenerR1tetdashes((s0/sys/lib/python2.7/distutils/command/register.pyR.�s`
$
N(slist-classifiersNs list the valid Trove classifiers(sstrictNsBWill stop the registering if the meta-data are not fully compliant(t__name__t
__module__RYRtuser_optionsRLtboolean_optionstsub_commandsR
R
RRRRRRR/R.(((s0/sys/lib/python2.7/distutils/command/register.pyRs&
{ (t__doc__t__revision__R)RERGtwarningsRtdistutils.coreRt distutilsRR(((s0/sys/lib/python2.7/distutils/command/register.pyt<module>s
|