;
Ñâ"Ic               @   sž   d  Z  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 Z d d l	 m
 Z
 d d l Td d l m Z d „  Z Gd „  d	 e
 ƒ Z d S(
   uh   distutils.command.register

Implements the Distutils 'register' command (register with the repository).
u;   $Id: register.py 64385 2008-06-18 20:49:58Z jeremy.hylton $i    N(   u   PyPIRCCommand(   u   *(   u   logc             C   s*   t  j j |  ƒ t  j j ƒ  t  j j ƒ  S(   N(   u   sysu   stdoutu   writeu   flushu   stdinu   readline(   u   prompt(    (    u7   /mit/python/lib/python3.0/distutils/command/register.pyu	   raw_input   s    c             B   s‹   |  Ee  Z d  Z e j d g Z e j d d g Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d	 „  Z d
 „  Z d „  Z d d „ Z d S(   u7   register the distribution with the Python package indexu   list-classifiersu    list the valid Trove classifiersu   verifyc             C   s   t  j |  ƒ d |  _ d  S(   Ni    (   u   PyPIRCCommandu   initialize_optionsu   list_classifiers(   u   self(    (    u7   /mit/python/lib/python3.0/distutils/command/register.pyu   initialize_options!   s    c             C   s\   |  j  ƒ  |  j ƒ  |  j ƒ  |  j o |  j ƒ  n# |  j o |  j ƒ  n |  j ƒ  d  S(   N(   u   finalize_optionsu   _set_configu   check_metadatau   dry_runu   verify_metadatau   list_classifiersu   classifiersu   send_metadata(   u   self(    (    u7   /mit/python/lib/python3.0/distutils/command/register.pyu   run%   s    




c             C   sì   |  j  j } g  } x? d D]7 } t | | ƒ o t | | ƒ p | j | ƒ q q W| o |  j d d j | ƒ ƒ n | j o# | j p |  j d d ƒ qè nC | j	 o# | j
 p |  j d d	 ƒ qè n |  j d
 d d ƒ d S(   uï   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.
        u   nameu   versionu   urlu   missing required meta-data: u   , u)   missing meta-data: if 'author' supplied, u#   'author_email' must be supplied toou-   missing meta-data: if 'maintainer' supplied, u'   'maintainer_email' must be supplied toou4   missing meta-data: either (author and author_email) u%   or (maintainer and maintainer_email) u   must be suppliedN(   u   nameu   versionu   url(   u   distributionu   metadatau   hasattru   getattru   appendu   warnu   joinu   authoru   author_emailu
   maintaineru   maintainer_email(   u   selfu   metadatau   missingu   attr(    (    u7   /mit/python/lib/python3.0/distutils/command/register.pyu   check_metadata0   s(      	

	

	c             C   s·   |  j  ƒ  } | i  k oA | d |  _ | d |  _ | d |  _ | d |  _ d |  _ nZ |  j d |  j f k o t d |  j ƒ ‚ n |  j d k o |  j |  _ n d	 |  _ d S(
   u:    Reads the configuration file and set attributes.
        u   usernameu   passwordu
   repositoryu   realmu   pypiu   %s not found in .pypircNTF(
   u   _read_pypircu   usernameu   passwordu
   repositoryu   realmu   Trueu
   has_configu   DEFAULT_REPOSITORYu
   ValueErroru   False(   u   selfu   config(    (    u7   /mit/python/lib/python3.0/distutils/command/register.pyu   _set_configN   s    c             C   s3   |  j  d } t j j | ƒ } t | j ƒ  ƒ d S(   u8    Fetch the list of classifiers from the server.
        u   ?:action=list_classifiersN(   u
   repositoryu   urllibu   requestu   urlopenu   printu   read(   u   selfu   urlu   response(    (    u7   /mit/python/lib/python3.0/distutils/command/register.pyu   classifiers_   s    c             C   s6   |  j  |  j d ƒ ƒ \ } } t d | | f ƒ d S(   uF    Send the metadata to the package index server to be checked.
        u   verifyu   Server response (%s): %sN(   u   post_to_serveru   build_post_datau   print(   u   selfu   codeu   result(    (    u7   /mit/python/lib/python3.0/distutils/command/register.pyu   verify_metadataf   s    c       
      C   sé  |  j  o d } |  j } |  j } n d } d } } d j ƒ  } xW | | k oI t d d d ƒt ƒ  } | p
 d } qE | | k o t d ƒ qE qE W| d k oRx | p t d	 ƒ } q¬ Wx | p t j d
 ƒ } qÇ Wt j j	 ƒ  } t j
 j |  j ƒ d } | j |  j | | | ƒ |  j |  j d ƒ | ƒ \ } } t d | | f ƒ |  j  o” | d k o‡ t d ƒ t d |  j ƒ  ƒ d } x5 | j ƒ  d k o! t d ƒ } | p
 d } q—q—W| j ƒ  d k o |  j | | ƒ q÷qånë| d k oii d d 6}	 d |	 d <|	 d <|	 d <d% |	 d <x  |	 d p t d	 ƒ |	 d <q<Wx |	 d |	 d k o‡ x# |	 d p t j d
 ƒ |	 d <qwWx# |	 d p t j d ƒ |	 d <qW|	 d |	 d k o" d |	 d <d% |	 d <t d ƒ q_q_Wx  |	 d p t d ƒ |	 d <qÿW|  j |	 ƒ \ } } | d k o t d | | f ƒ qåt d  ƒ t d! ƒ nu | d" k og i d# d 6}	 d |	 d <x  |	 d p t d$ ƒ |	 d <q˜W|  j |	 ƒ \ } } t d | | f ƒ n d% S(&   u_   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.

        u   1u   xu    u   1 2 3 4uâ   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]: u   endu    u&   Please choose one of the four options!u
   Username: u
   Password: i   u   submitu   Server response (%s): %siÈ   uA   I can store your PyPI login so future submissions will be faster.u    (the login will be stored in %s)u   Xu   ynu   Save your login (y/N)?u   nu   yu   2u   useru   :actionu   nameu   passwordu   emailu   confirmu
    Confirm: u!   Password and confirm don't match!u
      EMail: u"   You will receive an email shortly.u7   Follow the instructions in it to complete registration.u   3u   password_resetu   Your email address: N(   u
   has_configu   usernameu   passwordu   splitu   printu	   raw_inputu   getpassu   urllibu   requestu   HTTPPasswordMgru   parseu   urlparseu
   repositoryu   add_passwordu   realmu   post_to_serveru   build_post_datau   _get_rc_fileu   loweru   _store_pypircu   None(
   u   selfu   choiceu   usernameu   passwordu   choicesu   authu   hostu   codeu   resultu   data(    (    u7   /mit/python/lib/python3.0/distutils/command/register.pyu   send_metadatan   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 p | d p | d o d | d <n | S(   Nu   :actionu   1.0u   metadata_versionu   nameu   versionu   summaryu	   home_pageu   authoru   author_emailu   licenseu   descriptionu   keywordsu   platformu   classifiersu   download_urlu   providesu   requiresu	   obsoletesu   1.1(   u   distributionu   metadatau   get_nameu   get_versionu   get_descriptionu   get_urlu   get_contactu   get_contact_emailu   get_licenceu   get_long_descriptionu   get_keywordsu   get_platformsu   get_classifiersu   get_download_urlu   get_providesu   get_requiresu   get_obsoletes(   u   selfu   actionu   metau   data(    (    u7   /mit/python/lib/python3.0/distutils/command/register.pyu   build_post_dataÞ   s,    !c             C   s¦  |  j  d | d |  j f t j ƒ d } d | } | d } t j ƒ  } xÓ | j ƒ  D]Å \ } } t | ƒ t g  ƒ t d ƒ f k o | g } n x„ | D]| } t | ƒ j	 d ƒ } | j
 | ƒ | j
 d | ƒ | j
 d ƒ | j
 | ƒ | o" | d	 d
 k o | j
 d ƒ qœ qœ WqW W| j
 | ƒ | j
 d ƒ | j ƒ  } i d | d 6t t | ƒ ƒ d 6}	 t j j |  j | |	 ƒ }
 t j j t j j d | ƒ ƒ } d } y | j |
 ƒ } Wnš t j j k
 oJ } z4 |  j o | j j ƒ  } n | j | j f } WYd d } ~ Xn` t j j k
 o- } z d t | ƒ f } WYd d } ~ Xn" X|  j o | j ƒ  } n d } |  j o t d d | d d ƒ n | S(   uC    Post a query to the server, and return a string response.
        u   Registering %s to %su   nameu3   --------------GHSKFJDLGDS7543FJKLFHRE75642756743254u   
--u   --u   utf-8u*   
Content-Disposition: form-data; name="%s"u   

iÿÿÿÿu   u   
u/   multipart/form-data; boundary=%s; charset=utf-8u   Content-typeu   Content-lengthu   password_mgru    Niô  iÈ   u   OKu   -iK   (    (   iÈ   u   OK(   u   announceu
   repositoryu   logu   INFOu   iou   StringIOu   itemsu   typeu   stru   encodeu   writeu   getvalueu   lenu   urllibu   requestu   Requestu   build_openeru   HTTPBasicAuthHandleru   openu   erroru	   HTTPErroru   show_responseu   fpu   readu   codeu   msgu   URLErroru   print(   u   selfu   datau   authu   boundaryu   sep_boundaryu   end_boundaryu   bodyu   keyu   valueu   headersu   requ   openeru   resultu   e(    (    u7   /mit/python/lib/python3.0/distutils/command/register.pyu   post_to_serverú   sV    

 % 	
%&

N(   u   list-classifiersNu    list the valid Trove classifiers(   u   __name__u
   __module__u   descriptionu   PyPIRCCommandu   user_optionsu   Noneu   boolean_optionsu   initialize_optionsu   runu   check_metadatau   _set_configu   classifiersu   verify_metadatau   send_metadatau   build_post_datau   post_to_server(   u
   __locals__(    (    u7   /mit/python/lib/python3.0/distutils/command/register.pyu   register   s   
 
							p	u   register(   u   __doc__u   __revision__u   osu   stringu   getpassu   iou   urllib.parseu   urllibu   urllib.requestu   distutils.coreu   PyPIRCCommandu   distutils.errorsu	   distutilsu   logu	   raw_inputu   register(    (    (    u7   /mit/python/lib/python3.0/distutils/command/register.pyu   <module>   s   $
	