Ñò
mÈKc           @   s˜   d  Z  d Z d d k Z d d k Z d d k Z d d k Z d d k Z d d k Z d d k l	 Z	 d d k
 Td d k l Z d e	 f d „  ƒ  YZ d S(	   sh   distutils.command.register

Implements the Distutils 'register' command (register with the repository).
s9   $Id: register.py 77719 2010-01-24 00:57:20Z tarek.ziade $iÿÿÿÿN(   t   PyPIRCCommand(   t   *(   t   logt   registerc           B   s…   e  Z d  Z e i d g Z e i d d g 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   verifyc         C   s   t  i |  ƒ d |  _ d  S(   Ni    (   R    t   initialize_optionst   list_classifiers(   t   self(    (    s0   /usr/lib/python2.6/distutils/command/register.pyR      s    c         C   s\   |  i  ƒ  |  i ƒ  |  i ƒ  |  i o |  i ƒ  n# |  i o |  i ƒ  n |  i ƒ  d  S(   N(   t   finalize_optionst   _set_configt   check_metadatat   dry_runt   verify_metadataR   t   classifierst   send_metadata(   R   (    (    s0   /usr/lib/python2.6/distutils/command/register.pyt   run   s    




c         C   sï   |  i  i } g  } x? d D]7 } t | | ƒ o t | | ƒ p | i | ƒ q q W| o! |  i d t i | d ƒ ƒ n | i o# | i	 p |  i d d ƒ që nC | i
 o# | i p |  i d d	 ƒ që n |  i d
 d d ƒ d S(   sï   Ensure that all required elements of meta-data (name, version,
           URL, (author and author_email) or (maintainer and
           maintainer_email)) are supplied by the Distribution object; warn if
           any are missing.
        t   namet   versiont   urls   missing required meta-data: s   , s)   missing meta-data: if 'author' supplied, s#   'author_email' must be supplied toos-   missing meta-data: if 'maintainer' supplied, s'   'maintainer_email' must be supplied toos4   missing meta-data: either (author and author_email) s%   or (maintainer and maintainer_email) s   must be suppliedN(   s   names   versionR   (   t   distributiont   metadatat   hasattrt   getattrt   appendt   warnt   stringt   joint   authort   author_emailt
   maintainert   maintainer_email(   R   R   t   missingt   attr(    (    s0   /usr/lib/python2.6/distutils/command/register.pyR
   *   s(      	

	

	c         C   s·   |  i  ƒ  } | h  j oA | d |  _ | d |  _ | d |  _ | d |  _ t |  _ nZ |  i d |  i f j o t d |  i ƒ ‚ n |  i d j o |  i |  _ 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$   t   Truet
   has_configt   DEFAULT_REPOSITORYt
   ValueErrort   False(   R   t   config(    (    s0   /usr/lib/python2.6/distutils/command/register.pyR	   H   s    c         C   s%   t  i |  i d ƒ } | i ƒ  GHd S(   s8    Fetch the list of classifiers from the server.
        s   ?:action=list_classifiersN(   t   urllib2t   urlopenR#   t   read(   R   t   response(    (    s0   /usr/lib/python2.6/distutils/command/register.pyR   Y   s    c         C   s1   |  i  |  i d ƒ ƒ \ } } d | | f GHd 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_data(   R   t   codet   result(    (    s0   /usr/lib/python2.6/distutils/command/register.pyR   _   s    c   
      C   sã  |  i  o d } |  i } |  i } n d } d } } d i ƒ  } xU | | j oG |  i d t i ƒ t ƒ  } | p
 d } qE | | j o	 d GHqE qE W| d j ogx | p t d ƒ } qª Wx | p t i d ƒ } qÅ Wt	 i
 ƒ  } t i |  i ƒ d	 } | i |  i | | | ƒ |  i |  i d
 ƒ | ƒ \ } } |  i d | | f t i ƒ |  i  o¦ | d j o™ |  i d t i ƒ |  i d |  i ƒ  t i ƒ d } x5 | i ƒ  d j o! t d ƒ } | p
 d } qªqªW| i ƒ  d j o |  i | | ƒ q
qßnÒ| d j oUh d d 6}	 d |	 d <|	 d <|	 d <d# |	 d <x  |	 d p t d ƒ |	 d <qOWx˜ |	 d |	 d j o‚ x# |	 d p t i d ƒ |	 d <qŠWx# |	 d p t i d ƒ |	 d <q°W|	 d |	 d j o d |	 d <d# |	 d <d GHqrqrWx  |	 d p t d ƒ |	 d <qW|  i |	 ƒ \ } } | d j o d | | f GHqßd GHd GHnp | d  j ob h d! d 6}	 d |	 d <x  |	 d p t d" ƒ |	 d <q—W|  i |	 ƒ \ } } d | | f GHn 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   xt    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   :actionR   R"   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$   R1   R2   t   _get_rc_filet   lowert   _store_pypirct   None(
   R   t   choiceR!   R"   t   choicest   autht   hostR3   R4   t   data(    (    s0   /usr/lib/python2.6/distutils/command/register.pyR   g   sœ    
	
 	
  
	
	 
    

 	
 c         C   s  |  i  i } h | d 6d d 6| i ƒ  d 6| i ƒ  d 6| i ƒ  d 6| i ƒ  d 6| i ƒ  d 6| i ƒ  d	 6| i ƒ  d
 6| i	 ƒ  d 6| i
 ƒ  d 6| i ƒ  d 6| i ƒ  d 6| i ƒ  d 6| i ƒ  d 6| i ƒ  d 6| i ƒ  d 6} | d p | d p | d o d | d <n | S(   Ns   :actions   1.0t   metadata_versionR   R   t   summaryt	   home_pageR   R   t   licenset   descriptiont   keywordst   platformR   t   download_urlt   providest   requirest	   obsoletess   1.1(   R   R   t   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   metaRS   (    (    s0   /usr/lib/python2.6/distutils/command/register.pyR2   Ý   s,    !c         C   s[  |  i  d | d |  i f t i ƒ d } d | } | d } t i ƒ  } x¾ | i ƒ  D]° \ } } t | ƒ t g  ƒ t d ƒ f j o | g } n xo | D]g } | i | ƒ | i d | ƒ | i d ƒ | i | ƒ | o" | d d	 j o | i d
 ƒ qœ qœ WqW W| i | ƒ | i d
 ƒ | i ƒ  } h d | d 6t	 t
 | ƒ ƒ d 6}	 t i |  i | |	 ƒ }
 t i t i d | ƒ ƒ } d } y | i |
 ƒ } Wnp t i j
 o8 } |  i o | i i ƒ  } n | i | i f } nK t i j
 o } d t	 | ƒ f } n" X|  i o | i ƒ  } n d } |  i o d d G| Gd d GHn | S(   sC    Post a query to the server, and return a string response.
        s   Registering %s to %sR   s3   --------------GHSKFJDLGDS7543FJKLFHRE75642756743254s   
--s   --s*   
Content-Disposition: form-data; name="%s"s   

iÿÿÿÿs   s   
s/   multipart/form-data; boundary=%s; charset=utf-8s   Content-types   Content-lengtht   password_mgrR7   iô  iÈ   t   OKt   -iK   (    (   iÈ   Rq   (   RD   R#   R   RE   t   StringIOt   itemst   typet   writet   getvaluet   strt   lenR-   t   Requestt   build_openert   HTTPBasicAuthHandlert   opent	   HTTPErrort   show_responset   fpR/   R3   t   msgt   URLError(   R   RS   RQ   t   boundaryt   sep_boundaryt   end_boundaryt   bodyt   keyt   valuet   headerst   reqt   openerR4   t   e(    (    s0   /usr/lib/python2.6/distutils/command/register.pyR1   ù   sT    

 % 


N(   s   list-classifiersNs    list the valid Trove classifiers(   t   __name__t
   __module__RX   R    t   user_optionsRN   t   boolean_optionsR   R   R
   R	   R   R   R   R2   R1   (    (    (    s0   /usr/lib/python2.6/distutils/command/register.pyR      s    
							v	(   t   __doc__t   __revision__t   osR   R-   RG   RI   Rs   t   distutils.coreR    t   distutils.errorst	   distutilsR   R   (    (    (    s0   /usr/lib/python2.6/distutils/command/register.pyt   <module>   s   <
