ó
è¾bc           @   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 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   DistutilsErrort   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   sX   |  j  j s! d } t | ƒ ‚ n  x0 |  j  j D]" \ } } } |  j | | | ƒ q. Wd  S(   NsH   Must create and upload files in one command (e.g. setup.py sdist upload)(   R   t
   dist_filesR   t   upload_file(   R   t   msgt   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  | dE 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* | ƒ q<WqW| j* | ƒ | j+ ƒ  } |  j, d8 | |  j f t- j. ƒ i d9 | d: 6t/ t0 | ƒ ƒ d; 6| d< 6} t1 |  j d= | d> | ƒ} yj t2 | ƒ } | j3 ƒ  } | j4 } |  j5 r§d? j6 d@ dA | j ƒ  d@ dA f ƒ }  |  j, |  t- j. ƒ n  WnV t7 j8 k
 rÜ}! |  j, t/ |! ƒ t- j9 ƒ ‚  n% t: k
 r }! |! j; } |! j4 } n X| dB k r-|  j, dC | | f t- j. ƒ n/ dD | | f }  |  j, |  t- j9 ƒ t< |  ƒ ‚ d  S(F   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   

s   Submitting %s to %ss    multipart/form-data; boundary=%ss   Content-types   Content-lengtht   Authorizationt   datat   headerss   
t   -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_obsoletesR9   t   distR   R   R   t   StringIOt   itemst
   isinstancet   listt   tuplet   writet   getvaluet   announceR	   t   INFOt   strt   lenR   R    t   getcodeR   R   t   joint   sockett   errort   ERRORR   t   codeR   ("   R   R    R!   R"   t   schemat   netloct   urlt   paramst   queryt	   fragmentst   gpg_argst   fR.   t   metaRF   RB   Rb   R-   t   idt   autht   boundaryt   sep_boundaryt   end_boundaryt   bodyt   keyt   valuet   fnRG   t   requestt   resultt   statust   reasonR   t   e(    (    s.   /usr/lib/python2.7/distutils/command/upload.pyR   @   sÂ    $			
	 

 
			&	(   R   R   s   sign files to upload using gpg(   s	   identity=R   s   GPG identity used to sign files(
   t   __name__t
   __module__R7   R   t   user_optionst   boolean_optionsR   R   R#   R   (    (    (    s.   /usr/lib/python2.7/distutils/command/upload.pyR
      s    
			(   t   __doc__RQ   Rp   R9   t   urllib2R    R   R   t   base64R   RI   t	   cStringIORc   t   hashlibR   t   distutils.errorsR   R   t   distutils.coreR   t   distutils.spawnR   t	   distutilsR	   R
   (    (    (    s.   /usr/lib/python2.7/distutils/command/upload.pyt   <module>   s   