ó
8Þ	Pc           @   sØ   d  Z  d d l Z d d l Z d d l Z d d l m Z m Z m Z d d l m	 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 d l m Z d d	 l m Z d
 e f d „  ƒ  YZ d S(   s`   distutils.command.upload

Implements the Distutils 'upload' subcommand (upload package to PyPI).iÿÿÿÿN(   t   urlopent   Requestt	   HTTPError(   t   standard_b64encode(   t   md5(   t   DistutilsOptionError(   t   PyPIRCCommand(   t   spawn(   t   logt   uploadc           B   sU   e  Z d  Z e j d d g Z e j d g Z d „  Z d „  Z d	 „  Z d
 „  Z	 RS(   s   upload binary package to PyPIt   signt   ss   sign files to upload using gpgs	   identity=t   is   GPG identity used to sign filesc         C   s>   t  j |  ƒ d |  _ d |  _ d |  _ t |  _ d  |  _ d  S(   Nt    i    (	   R   t   initialize_optionst   usernamet   passwordt   show_responset   FalseR
   t   Nonet   identity(   t   self(    (    s.   /usr/lib/python2.7/distutils/command/upload.pyR      s    				c         C   sª   t  j |  ƒ |  j r/ |  j r/ t d ƒ ‚ n  |  j ƒ  } | i  k r~ | d |  _ | d |  _ | d |  _ | d |  _	 n  |  j r¦ |  j
 j r¦ |  j
 j |  _ n  d  S(   Ns.   Must use --sign for --identity to have meaningR   R   t
   repositoryt   realm(   R   t   finalize_optionsR   R
   R   t   _read_pypircR   R   R   R   t   distribution(   R   t   config(    (    s.   /usr/lib/python2.7/distutils/command/upload.pyR   &   s    c         C   sR   |  j  j s t d ƒ ‚ n  x0 |  j  j D]" \ } } } |  j | | | ƒ q( Wd  S(   Ns'   No dist file created in earlier command(   R   t
   dist_filesR   t   upload_file(   R   t   commandt	   pyversiont   filename(    (    s.   /usr/lib/python2.7/distutils/command/upload.pyt   run8   s    c   "      C   s  t  j  |  j ƒ \ } } } } } }	 | s6 | s6 |	 rL t d |  j ƒ ‚ n  | dG k rk t d | ƒ ‚ n  |  j r¾ d d d | g }
 |  j r¨ d |  j g |
 d	 d	 +n  t |
 d
 |  j ƒn  t | d ƒ } z | j ƒ  } Wd  | j	 ƒ  X|  j
 j } i d d 6d d 6| j ƒ  d 6| j ƒ  d 6t j j | ƒ | f d 6| d 6| d 6t | ƒ j ƒ  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} d% } | d& k rRt  j! ƒ  \ } } } | rwd' | | f } qwn% | d( k rwd) t  j  d* d+ ƒ } n  | | d, <|  j r½t j j | ƒ d- t | d- ƒ j ƒ  f | d. <n  d/ t" |  j# d0 |  j$ ƒ } d1 } d2 | } | d3 } t% j% ƒ  } xá | j& ƒ  D]Ó \ } } t' | t( ƒ s5| g } n  x© | D]¡ } t' | t) ƒ rld4 | d5 } | d+ } n d% } | j* | ƒ | j* d6 | ƒ | j* | ƒ | j* d7 ƒ | j* | ƒ | r<| d8 d9 k r<| j* d: ƒ q<q<WqW| j* | ƒ | j* d: ƒ | j+ ƒ  } |  j, d; | |  j f t- j. ƒ i d< | d= 6t/ t0 | ƒ ƒ d> 6| d? 6} t1 |  j d@ | dA | ƒ} yj t2 | ƒ } | j3 ƒ  } | j4 } |  j5 rÚd: j6 dB dC t7 j ƒ  dB dC f ƒ }  |  j, |  t- j. ƒ n  WnT t8 j9 k
 r}! |  j, t/ |! ƒ t- j: ƒ d  St; k
 r1}! |! j< } |! j4 } n X| dD k r^|  j, dE | | f t- j. ƒ n |  j, dF | | f t- j: ƒ d  S(H   Ns   Incompatible url %st   httpt   httpss   unsupported schema t   gpgs   --detach-signs   -as   --local-useri   t   dry_runt   rbt   file_uploads   :actiont   1t   protcol_versiont   namet   versiont   contentt   filetypeR   t
   md5_digests   1.0t   metadata_versiont   summaryt	   home_paget   authort   author_emailt   licenset   descriptiont   keywordst   platformt   classifierst   download_urlt   providest   requirest	   obsoletesR   t	   bdist_rpms   built for %s %st
   bdist_dumbs   built for %st   tersei   t   comments   .asct   gpg_signatures   Basic t   :s3   --------------GHSKFJDLGDS7543FJKLFHRE75642756743254s   
--s   --s   ;filename="%s"i    s*   
Content-Disposition: form-data; name="%s"s   

iÿÿÿÿs   s   
s   Submitting %s to %ss    multipart/form-data; boundary=%ss   Content-types   Content-lengtht   Authorizationt   datat   headerst   -iK   iÈ   s   Server response (%s): %ss   Upload failed (%s): %s(   R"   R#   (=   t   urlparseR   t   AssertionErrorR
   R   R   R%   t   opent   readt   closeR   t   metadatat   get_namet   get_versiont   ost   patht   basenameR   t	   hexdigestt   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_obsoletesR7   t   distR   R   R   t   StringIOt   itemst
   isinstancet   listt   tuplet   writet   getvaluet   announceR   t   INFOt   strt   lenR   R    t   getcodet   msgR   t   joint   rt   sockett   errort   ERRORR   t   code("   R   R   R   R    t   schemat   netloct   urlt   paramst   queryt	   fragmentst   gpg_argst   fR,   t   metaRD   R@   R`   R+   t   idt   autht   boundaryt   sep_boundaryt   end_boundaryt   bodyt   keyt   valuet   fnRE   t   requestt   resultt   statust   reasonRm   t   e(    (    s.   /usr/lib/python2.7/distutils/command/upload.pyR   >   sÆ    $			
	 

 
			&	(   s   signR   s   sign files to upload using gpg(   s	   identity=R   s   GPG identity used to sign files(
   t   __name__t
   __module__R5   R   t   user_optionst   boolean_optionsR   R   R!   R   (    (    (    s.   /usr/lib/python2.7/distutils/command/upload.pyR	      s    
			(   t   __doc__RO   Rp   R7   t   urllib2R    R   R   t   base64R   RG   t	   cStringIORa   t   hashlibR   t   distutils.errorsR   t   distutils.coreR   t   distutils.spawnR   t	   distutilsR   R	   (    (    (    s.   /usr/lib/python2.7/distutils/command/upload.pyt   <module>   s   