ó
è¾bc           @   sz   d  Z  d 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
 d e f d „  ƒ  YZ d S(	   sh   distutils.command.register

Implements the Distutils 'register' command (register with the repository).
s   $Id$iÿÿÿÿN(   t   warn(   t   PyPIRCCommand(   t   logt   registerc           B   s¦   e  Z d  Z e j d d g Z e j d d d g 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 RS(   s7   register the distribution with the Python package indexs   list-classifierss    list the valid Trove classifierst   strictsB   Will stop the registering if the meta-data are not fully compliantt   verifyt   checkc         C   s   t  S(   N(   t   True(   t   self(    (    s0   /usr/lib/python2.7/distutils/command/register.pyt   <lambda>   t    c         C   s#   t  j |  ƒ d |  _ d |  _ d  S(   Ni    (   R   t   initialize_optionst   list_classifiersR   (   R   (    (    s0   /usr/lib/python2.7/distutils/command/register.pyR       s    	c         C   s>   t  j |  ƒ i d |  j f d 6d d 6} | |  j j d <d  S(   NR   R   i   t   restructuredtextR   (   R   i   (   R   t   finalize_optionsR   t   distributiont   command_options(   R   t   check_options(    (    s0   /usr/lib/python2.7/distutils/command/register.pyR   %   s    
c         C   sr   |  j  ƒ  |  j ƒ  x! |  j ƒ  D] } |  j | ƒ q! W|  j rN |  j ƒ  n  |  j rd |  j ƒ  n
 |  j ƒ  d  S(   N(	   R   t   _set_configt   get_sub_commandst   run_commandt   dry_runt   verify_metadataR   t   classifierst   send_metadata(   R   t   cmd_name(    (    s0   /usr/lib/python2.7/distutils/command/register.pyt   run,   s    

		c         C   sL   t  d t ƒ |  j j d ƒ } | j ƒ  |  j | _ d | _ | j ƒ  d S(   s   Deprecated API.sd   distutils.command.register.check_metadata is deprecated,               use the check command insteadR   i   N(   R    t   PendingDeprecationWarningR   t   get_command_objt   ensure_finalizedR   R   R   (   R   R   (    (    s0   /usr/lib/python2.7/distutils/command/register.pyt   check_metadata;   s    

	c         C   s±   |  j  ƒ  } | i  k rX | d |  _ | d |  _ | d |  _ | d |  _ t |  _ nU |  j d |  j f k r† t d |  j ƒ ‚ n  |  j d k r¤ |  j |  _ n  t	 |  _ d S(   s:    Reads the configuration file and set attributes.
        t   usernamet   passwordt
   repositoryt   realmt   pypis   %s not found in .pypircN(
   t   _read_pypircR   R    R!   R"   R   t
   has_configt   DEFAULT_REPOSITORYt
   ValueErrort   False(   R   t   config(    (    s0   /usr/lib/python2.7/distutils/command/register.pyR   E   s    c         C   s-   t  j |  j d ƒ } t j | j ƒ  ƒ d S(   s8    Fetch the list of classifiers from the server.
        s   ?:action=list_classifiersN(   t   urllib2t   urlopenR!   R   t   infot   read(   R   t   response(    (    s0   /usr/lib/python2.7/distutils/command/register.pyR   V   s    c         C   s9   |  j  |  j d ƒ ƒ \ } } t j d | | f ƒ d S(   sF    Send the metadata to the package index server to be checked.
        R   s   Server response (%s): %sN(   t   post_to_servert   build_post_dataR   R,   (   R   t   codet   result(    (    s0   /usr/lib/python2.7/distutils/command/register.pyR   \   s    c   
      C   sæ  |  j  r$ d } |  j } |  j } n d } d } } d j ƒ  } xO | | k r‘ |  j d t j ƒ t ƒ  } | sz d } qC | | k rC d GHqC qC W| d k rx | s¶ t d ƒ } q¡ Wx | sÒ t j d ƒ } qº Wt	 j
 ƒ  } t j |  j ƒ d	 } | j |  j | | | ƒ |  j |  j d
 ƒ | ƒ \ } } |  j d | | f t j ƒ | d k râ|  j  rp| |  j _ q|  j d t j ƒ |  j d |  j ƒ  t j ƒ d } x1 | j ƒ  d k rÙt d ƒ } | s©d } q©q©W| j ƒ  d k r|  j | | ƒ qqânÝ| d k roi d d 6}	 d |	 d <|	 d <|	 d <d# |	 d <x |	 d sbt d ƒ |	 d <qEWx |	 d |	 d k rõx! |	 d st j d ƒ |	 d <q}Wx! |	 d sÁt j d ƒ |	 d <q¡W|	 d |	 d k rfd |	 d <d# |	 d <d GHqfqfWx |	 d st d ƒ |	 d <qùW|  j |	 ƒ \ } } | d k rRt j d | | f ƒ qât j d ƒ t j d ƒ ns | d  k râi d! d 6}	 d |	 d <x |	 d s²t d" ƒ |	 d <q•W|  j |	 ƒ \ } } t j d | | f ƒ n  d# 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.

        t   1t   xR
   s   1 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: i   t   submits   Server response (%s): %siÈ   sA   I can store your PyPI login so future submissions will be faster.s    (the login will be stored in %s)t   Xt   yns   Save your login (y/N)?t   nt   yt   2t   users   :actiont   nameR    t   emailt   confirms
    Confirm: s!   Password and confirm don't match!s
      EMail: s"   You will receive an email shortly.s7   Follow the instructions in it to complete registration.t   3t   password_resets   Your email address: N(   R%   R   R    t   splitt   announceR   t   INFOt	   raw_inputt   getpassR*   t   HTTPPasswordMgrt   urlparseR!   t   add_passwordR"   R/   R0   R   t   _get_rc_filet   lowert   _store_pypirct   NoneR,   (
   R   t   choiceR   R    t   choicest   autht   hostR1   R2   t   data(    (    s0   /usr/lib/python2.7/distutils/command/register.pyR   d   sŒ    		
				
		
	



c         C   s  |  j  j } i | d 6d d 6| j ƒ  d 6| j ƒ  d 6| j ƒ  d 6| j ƒ  d 6| j ƒ  d 6| j ƒ  d	 6| j ƒ  d
 6| j	 ƒ  d 6| j
 ƒ  d 6| j ƒ  d 6| j ƒ  d 6| j ƒ  d 6| j ƒ  d 6| j ƒ  d 6| j ƒ  d 6} | d s| d s| d rd | d <n  | S(   Ns   :actions   1.0t   metadata_versionR<   t   versiont   summaryt	   home_paget   authort   author_emailt   licenset   descriptiont   keywordst   platformR   t   download_urlt   providest   requirest	   obsoletess   1.1(   R   t   metadatat   get_namet   get_versiont   get_descriptiont   get_urlt   get_contactt   get_contact_emailt   get_licencet   get_long_descriptiont   get_keywordst   get_platformst   get_classifierst   get_download_urlt   get_providest   get_requirest   get_obsoletes(   R   t   actiont   metaRQ   (    (    s0   /usr/lib/python2.7/distutils/command/register.pyR0   ß   s,    c         C   s³  d | k r3 |  j  d | d |  j f t j ƒ n  d } d | } | d } g  } x¹ | j ƒ  D]« \ } } t | ƒ t g  ƒ t d ƒ f k rœ | g } n  xl | D]d } | j | ƒ | j d | ƒ | j d ƒ | j | ƒ | r£ | d d	 k r£ | j d
 ƒ q£ q£ Wq` W| j | ƒ | j d
 ƒ g  }	 xC | D]; }
 t |
 t ƒ rd|	 j |
 j	 d ƒ ƒ q6|	 j |
 ƒ q6Wd j
 |	 ƒ }	 i d | d 6t t |	 ƒ ƒ d 6} t j |  j |	 | ƒ } t j t j d | ƒ ƒ } d } y | j | ƒ } Wnj t j k
 r9} |  j r$| j j ƒ  } n  | j | j f } nF t j k
 r`} d t | ƒ f } n X|  j ry| j ƒ  } n  d } |  j r¯d d } |  j  d | | | f ƒ n  | S(   sC    Post a query to the server, and return a string response.
        R<   s   Registering %s to %ss3   --------------GHSKFJDLGDS7543FJKLFHRE75642756743254s   
--s   --s*   
Content-Disposition: form-data; name="%s"s   

iÿÿÿÿs   s   
s   utf-8R
   s/   multipart/form-data; boundary=%s; charset=utf-8s   Content-types   Content-lengtht   password_mgriô  iÈ   t   OKt   -iK   s   %s%s%s(    (   iÈ   Rs   (   RB   R!   R   RC   t   itemst   typet   appendt
   isinstancet   unicodet   encodet   joint   strt   lenR*   t   Requestt   build_openert   HTTPBasicAuthHandlert   opent	   HTTPErrort   show_responset   fpR-   R1   t   msgt   URLError(   R   RQ   RO   t   boundaryt   sep_boundaryt   end_boundaryt   chunkst   keyt   valuet   bodyt   chunkt   headerst   reqt   openerR2   t   et   dashes(    (    s0   /usr/lib/python2.7/distutils/command/register.pyR/   û   s`    


$			
N(   s   list-classifiersNs    list the valid Trove classifiers(   R   NsB   Will stop the registering if the meta-data are not fully compliant(   t   __name__t
   __module__RY   R   t   user_optionsRL   t   boolean_optionst   sub_commandsR   R   R   R   R   R   R   R   R0   R/   (    (    (    s0   /usr/lib/python2.7/distutils/command/register.pyR      s&     
				
				{	(   t   __doc__t   __revision__R*   RE   RG   t   warningsR    t   distutils.coreR   t	   distutilsR   R   (    (    (    s0   /usr/lib/python2.7/distutils/command/register.pyt   <module>   s   