
    
_d).                     j    d Z ddlZddlZddlZddlZddlZddlmZ ddl	m
Z
 ddlmZ  G d de
      Zy)	zhdistutils.command.register

Implements the Distutils 'register' command (register with the repository).
    N)warn   )PyPIRCCommand)logc                       e Zd ZdZej
                  ddgz   Zej                  g dz   Zdd fgZd Zd Z	d	 Z
d
 Zd Zd Zd Zd Zd ZddZy)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)verifyr	   r
   checkc                      y)NT selfs    H/usr/lib/python3/dist-packages/setuptools/_distutils/command/register.py<lambda>zregister.<lambda>#   s        c                 J    t        j                  |        d| _        d| _        y )Nr   )r   initialize_optionslist_classifiersr
   r   s    r   r   zregister.initialize_options%   s    ((. !r   c                     t        j                  |        d| j                  fdd}|| j                  j                  d<   y )Nr   )r      )r
   restructuredtextr   )r   finalize_optionsr
   distributioncommand_options)r   check_optionss     r   r   zregister.finalize_options*   sA    &&t, "4;;/ /
 6C))'2r   c                 $   | j                          | j                          | j                         D ]  }| j                  |        | j                  r| j                          y | j                  r| j                          y | j                          y N)	r   _set_configget_sub_commandsrun_commanddry_runverify_metadatar   classifierssend_metadata)r   cmd_names     r   runzregister.run3   sx     --/ 	'HX&	' <<  """ r   c                     t        dt               | j                  j                  d      }|j	                          | j
                  |_        d|_        |j                          y)zDeprecated API.zVdistutils.command.register.check_metadata is deprecated; use the check command insteadr   r   N)r   DeprecationWarningr   get_command_objensure_finalizedr
   r   r(   )r   r   s     r   check_metadatazregister.check_metadataB   sR    ,	

 !!11': {{!"		r   c                 @   | j                         }|i k7  r0|d   | _        |d   | _        |d   | _        |d   | _        d| _        y	| j                  d| j                  fvrt        d| j                  z        | j                  dk(  r| j                  | _        d| _        y	)
z0Reads the configuration file and set attributes.usernamepassword
repositoryrealmTpypiz%s not found in .pypircFN)_read_pypircr/   r0   r1   r2   
has_configDEFAULT_REPOSITORY
ValueError)r   configs     r   r    zregister._set_configO   s    ""$R<":.DM":.DM$\2DODJ"DOvt/F/F&GG !:T__!LMM&("&"9"9#DOr   c                     | j                   dz   }t        j                  j                  |      }t	        j
                  | j                  |             y)z.Fetch the list of classifiers from the server.z?:action=list_classifiersN)r1   urllibrequesturlopenr   info_read_pypi_response)r   urlresponses      r   r%   zregister.classifiers_   s<    oo ;;>>))#.))(34r   c                 x    | j                  | j                  d            \  }}t        j                  d||       y)z<Send the metadata to the package index server to be checked.r   Server response (%s): %sN)post_to_serverbuild_post_datar   r=   )r   coderesults      r   r$   zregister.verify_metadatae   s4     ,,T-A-A(-KLv+T6:r   c                    | j                   rd}| j                  }| j                  }nd}dx}}dj                         }||vrC| j	                  dt
        j                         t               }|sd}n||vrt        d       ||vrC|dk(  r|st        d      }|s|st        j                  d      }|st        j                  j                         }t        j                  j                  | j                        d	   }|j!                  | j"                  |||       | j%                  | j'                  d
      |      \  }}| j	                  dj)                  ||      t
        j                         |dk(  r| j                   r|| j*                  _        y| j	                  dt
        j                         | j	                  d| j-                         z  t
        j                         d}|j/                         dvr"t        d      }|sd}|j/                         dvr"|j/                         dk(  r| j1                  ||       yyy|dk(  r#ddi}	dx|	d<   x|	d<   |	d<   d|	d<   |	d   st        d      |	d<   |	d   s|	d   |	d   k7  rr|	d   st        j                  d      |	d<   |	d   s|	d   st        j                  d      |	d<   |	d   s|	d   |	d   k7  rd|	d<   d|	d<   t        d       |	d   |	d   k7  rr|	d   st        d      |	d<   |	d   s| j%                  |	      \  }}|dk7  rt3        j4                  d||       yt3        j4                  d        t3        j4                  d!       y|d"k(  rNdd#i}	d|	d<   |	d   st        d$      |	d<   |	d   s| j%                  |	      \  }}t3        j4                  d||       yy)%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.

        1x z1 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: r   submitzServer response ({}): {}   zAI can store your PyPI login so future submissions will be faster.z (the login will be stored in %s)XynzSave your login (y/N)?ny2:actionusernamer0   emailNconfirmz
 Confirm: z!Password and confirm don't match!z
   EMail: rB   z"You will receive an email shortly.z7Follow the instructions in it to complete registration.3password_resetzYour email address: )r5   r/   r0   splitannounceloggingINFOinputprintgetpassr:   r;   HTTPPasswordMgrparseurlparser1   add_passwordr2   rC   rD   formatr   _get_rc_filelower_store_pypircr   r=   )
r   choicer/   r0   choicesauthhostrE   rF   datas
             r   r&   zregister.send_metadatak   s   < ??F}}H}}HF"$$Hx //#G#MM  	 WFw&>? G#" S= . "??<8  >>113D<<((9!<Ddjj$(C..t/C/CH/MtTLD&MM4;;D&I7<<X s{?? 2:D%%.MM:   MM:T=N=N=PP !F ,,.4!&'?!@%%(F !,,.4 ||~,**8X> -- 2 s]v&D>@@DL@4
+d7m"DO6l$\2V 6lz"d9o5z*'.|'DD$ z*y/&-ool&CDO y/
#tI6')D$&*DO=> z"d9o5 7m %l 3W 7m..t4LD&s{3T6B=>UVs]/0DDM7m %&< =W 7m..t4LD&HH/v> r   c                 h   | j                   j                  }i d|ddd|j                         d|j                         d|j	                         d|j                         d|j                         d	|j                         d
|j                         d|j                         d|j                         d|j                         d|j                         d|j                         d|j                         d|j                         d|j!                         }|d   s
|d   s|d   rd|d<   |S )NrR   metadata_versionz1.0rT   versionsummary	home_pageauthorauthor_emaillicensedescriptionkeywordsplatformr%   download_urlprovidesrequires	obsoletesz1.1)r   metadataget_nameget_versionget_descriptionget_urlget_contactget_contact_emailget_licenceget_long_descriptionget_keywordsget_platformsget_classifiersget_download_urlget_providesget_requiresget_obsoletes)r   actionmetarl   s       r   rD   zregister.build_post_data   s      ))
v

 DMMO
 t'')	

 t++-
 
 d&&(
 D224
 t'')
 4446
 ))+
 **,
 4//1
 D113
  ))+!
" ))+#
$ ++-%
( 
tJ/43D',D#$r   Nc                    d|v r=| j                  dj                  |d   | j                        t        j                         d}d|z   }|dz   }t        j                         }|j                         D ]  \  }}t        |      t        g       t        d      fvr|g}|D ]q  }t        |      }|j                  |       |j                  d|z         |j                  d       |j                  |       |sX|d	   d
k(  sa|j                  d       s  |j                  |       |j                  d       |j                         j                  d      }d|z  t        t        |            d}	t        j                  j!                  | j                  ||	      }
t        j                  j#                  t        j                  j%                  |            }d}	 |j'                  |
      }| j(                  r| j+                  |      }d}| j(                  r4dj;                  d|df      }| j                  |t        j                         |S # t        j,                  j.                  $ rH}| j(                  r|j0                  j3                         }|j4                  |j6                  f}Y d}~d}~wt        j,                  j8                  $ r}dt        |      f}Y d}~d}~ww xY w)z9Post a query to the server, and return a string response.rT   zRegistering {} to {}z3--------------GHSKFJDLGDS7543FJKLFHRE75642756743254z
--z--r   z*
Content-Disposition: form-data; name="%s"z


zutf-8z/multipart/form-data; boundary=%s; charset=utf-8)zContent-typezContent-length)password_mgrrJ   )rL   OKNi  zK---------------------------------------------------------------------------)rZ   rd   r1   r[   r\   ioStringIOitemstypestrwritegetvalueencodelenr:   r;   Requestbuild_openerHTTPBasicAuthHandleropenshow_responser>   error	HTTPErrorfpreadrE   msgURLErrorjoin)r   rl   rj   boundarysep_boundaryend_boundarybodykeyvalueheadersreqopenerrF   er   s                  r   rC   zregister.post_to_server  si   T>MM&--d6lDOOL
 I(#d*{{}**, 	%JCE{48T"X"66 %E


<(

H3NO

6"

5!U2Y$.JJt$%		% 	

< 

4}}%%g. N!#d)n

 nn$$T__dGD ,,NN//T/B
 	[[%F !!//7F))XtX67CMM#w||, ||%% 	#!!ttyy{VVQUU]F||$$ 	!#a&[F	!s$   I K#)>J,, K#KK#r   )__name__
__module____qualname__ru   r   user_optionsboolean_optionssub_commandsr   r   r(   r-   r    r%   r$   r&   rD   rC   r   r   r   r   r      s    KK --F	
1 L $33 7 O /01L
C!$ 5;?B88r   r   )__doc__r_   r   r[   urllib.parser:   urllib.requestwarningsr   corer   distutils._logr   r   r   r   r   <module>r      s2     	       m} mr   