³ò
 ›\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 Z d d k	 Z	 d d k
 l Z d d k Td e f d „  ƒ  YZ d S(   sh   distutils.command.register

Implements the Distutils 'register' command (register with the repository).
s=   $Id: register.py 56542 2007-07-25 16:24:08Z martin.v.loewis $iÿÿÿÿN(   t   Command(   t   *t   registerc           B   s“   e  Z d  Z d Z d d d e f d d g Z d	 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   http://pypi.python.org/pypis   repository=t   rs   url of repository [default: %s]s   list-classifierss    list the valid Trove classifierss   show-responses&   display full response text from servert   verifyc         C   s   d  |  _ d |  _ d |  _ d  S(   Ni    (   t   Nonet
   repositoryt   show_responset   list_classifiers(   t   self(    (    s0   /usr/lib/python2.5/distutils/command/register.pyt   initialize_options    s    		c         C   s$   |  i  d  j o |  i |  _  n d  S(   N(   R   R   t   DEFAULT_REPOSITORY(   R	   (    (    s0   /usr/lib/python2.5/distutils/command/register.pyt   finalize_options%   s    c         C   sH   |  i  ƒ  |  i o |  i ƒ  n# |  i o |  i ƒ  n |  i ƒ  d  S(   N(   t   check_metadatat   dry_runt   verify_metadataR   t   classifierst   send_metadata(   R	   (    (    s0   /usr/lib/python2.5/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.5/distutils/command/register.pyR   2   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.5/distutils/command/register.pyR   P   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.5/distutils/command/register.pyR   V   s    c         C   sŠ  d } d } } d, } t i i d ƒ oƒ t i i t i d d ƒ } t i i | ƒ oP d | GHt i ƒ  } | i | ƒ | i	 d d ƒ } | i	 d d ƒ } d	 } q¬ n d
 i
 ƒ  } xF | | j o8 d Gt ƒ  } | p
 d	 } q» | | j o	 d GHq» q» W| d	 j o£x | p t d ƒ } qWx | p t i d ƒ } q,Wt i ƒ  } t i |  i ƒ d } | i d | | | ƒ |  i |  i d ƒ | ƒ \ }	 }
 d |	 |
 f GHt i i d ƒ oë | d, j oÞ |	 d j oÑ t i i t i d d ƒ } d GHd | GHd } x5 | i ƒ  d j o! t d ƒ } | p
 d } qqW| i ƒ  d j oR t | d ƒ } | i d | | f ƒ | i ƒ  y t i | d ƒ Wq©q©Xq­q†nÖ| d j oWh  d d  <} d | d! <| d <| d" <d, | d# <x  | d! p t d ƒ | d! <qôWx˜ | d | d# j o‚ x# | d p t i d ƒ | d <q/Wx# | d# p t i d$ ƒ | d# <qUW| d | d# j o d | d <d, | d# <d% GHqqWx  | d" p t d& ƒ | d" <q²W|  i | ƒ \ }	 }
 |	 d j o d |	 |
 f GHq†d' GHd( GHnr | d) j od h  d* d  <} 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
            [server-login] containing username and password entries (both
            in clear text). Eg:

                [server-login]
                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   xt    t   HOMEs   .pypircs   Using PyPI login from %ss   server-logint   usernamet   passwordt   1s   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   pypit   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   ws'   [server-login]
username:%s
password:%s
i€  t   2t   users   :actionR   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   t   ost   environt   has_keyt   pathR   t   existst   ConfigParserR&   t   gett   splitt	   raw_inputt   getpassR$   t   HTTPPasswordMgrt   urlparseR   t   add_passwordR(   R)   t   lowert   opent   writet   closet   chmod(   R	   t   choiceR/   R0   t   configt   rct   choicest   autht   hostR*   R+   t   ft   data(    (    s0   /usr/lib/python2.5/distutils/command/register.pyR   ]   s°    
	 	
  -	 	

    

 	
 c         C   s8  |  i  i } h  | d <d d <| i ƒ  d <| i ƒ  d <| i ƒ  d <| i ƒ  d <| i ƒ  d <| i ƒ  d	 <| i ƒ  d
 <| i	 ƒ  d <| i
 ƒ  d <| i ƒ  d <| i ƒ  d <| i ƒ  d <| i ƒ  d <| i ƒ  d <| i ƒ  d <} | 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   metaRX   (    (    s0   /usr/lib/python2.5/distutils/command/register.pyR)   ×   s,    		!c         C   sP  d } d | } | d } t  i  ƒ  } xÓ | i ƒ  D]Å \ } } t | ƒ t g  ƒ t d ƒ f j o | g } n x„ | D]| } t | ƒ i d ƒ } | i | ƒ | i d | ƒ | i d ƒ | i | ƒ | o" | d d j o | i d	 ƒ qx qx Wq3 W| i | ƒ | i d	 ƒ | i ƒ  } h  d
 | d <t t | ƒ ƒ d <}	 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.
        s3   --------------GHSKFJDLGDS7543FJKLFHRE75642756743254s   
--s   --s   utf-8s*   
Content-Disposition: form-data; name="%s"s   

iÿÿÿÿs   s   
s/   multipart/form-data; boundary=%s; charset=utf-8s   Content-types   Content-lengtht   password_mgrR-   iô  iÈ   t   OKt   -iK   (    (   iÈ   Rv   (   t   StringIOt   itemst   typet   unicodet   encodeRN   t   getvaluet   strt   lenR$   t   RequestR   t   build_openert   HTTPBasicAuthHandlerRM   t	   HTTPErrorR   t   fpR&   R*   t   msgt   URLError(   R	   RX   RU   t   boundaryt   sep_boundaryt   end_boundaryt   bodyt   keyt   valuet   headerst   reqt   openerR+   t   e(    (    s0   /usr/lib/python2.5/distutils/command/register.pyR(   ó   sR    

 % 


N(   s   list-classifiersNs    list the valid Trove classifiers(   s   show-responseNs&   display full response text from server(   t   __name__t
   __module__R]   R   R   t   user_optionst   boolean_optionsR
   R   R   R   R   R   R   R)   R(   (    (    (    s0   /usr/lib/python2.5/distutils/command/register.pyR      s$   
  									z	(   t   __doc__t   __revision__t   sysR?   R   R$   RH   RJ   Rx   RD   t   distutils.coreR    t   distutils.errorsR   (    (    (    s0   /usr/lib/python2.5/distutils/command/register.pys   <module>   s   H
