ó
OyTLc           @   sò   d  Z  d d l Td d l m Z d d l m Z d d l m Z y d d l m	 Z	 Wn! e
 k
 rw d d l	 m	 Z	 n Xd 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 Z d d l Z d e f d	 „  ƒ  YZ d S(
   s`   distutils.command.upload

Implements the Distutils 'upload' subcommand (upload package to PyPI).iÿÿÿÿ(   t   *(   t   Command(   t   spawn(   t   log(   t   md5Nt   uploadc           B   sc   e  Z d  Z d Z d d d e f d d d g Z d d g Z d „  Z d „  Z d „  Z	 d „  Z
 RS(   s   upload binary package to PyPIs   http://pypi.python.org/pypis   repository=t   rs   url of repository [default: %s]s   show-responses&   display full response text from servert   signt   ss   sign files to upload using gpgs	   identity=t   is   GPG identity used to sign filesc         C   s:   d |  _  d |  _ d |  _ d |  _ t |  _ d  |  _ d  S(   Nt    i    (   t   usernamet   passwordt
   repositoryt   show_responset   FalseR   t   Nonet   identity(   t   self(    (    s=   /usr/lib/python2.7/dist-packages/setuptools/command/upload.pyt   initialize_options'   s    					c         C   s)  |  j  r" |  j r" t d ƒ ‚ n  t j j d ƒ rt j j t j d d ƒ } t j j | ƒ r|  j	 d | ƒ t
 j
 i d d 6d d 6d d 6ƒ } | j | ƒ |  j sÅ | j d	 d ƒ |  _ n  |  j sæ | j d	 d ƒ |  _ n  |  j s
| j d	 d ƒ |  _ q
qn  |  j s%|  j |  _ n  d  S(
   Ns.   Must use --sign for --identity to have meaningt   HOMEs   .pypircs   Using PyPI login from %sR
   R   R   R   s   server-login(   R   R   t   DistutilsOptionErrort   ost   environt   has_keyt   patht   joint   existst   announcet   ConfigParsert   readR   t   getR   R   t   DEFAULT_REPOSITORY(   R   t   rct   config(    (    s=   /usr/lib/python2.7/dist-packages/setuptools/command/upload.pyt   finalize_options/   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(   t   distributiont
   dist_filesR   t   upload_file(   R   t   commandt	   pyversiont   filename(    (    s=   /usr/lib/python2.7/dist-packages/setuptools/command/upload.pyt   runF   s    c         C   s+  |  j  rS d d d | g } |  j r= d |  j g | d d +n  t | d |  j ƒn  t | d ƒ } | j ƒ  } | j ƒ  t j j	 | ƒ } d } | d	 k rÄ |  j
 j ƒ  rÄ d
 t j d d ƒ } n  i d d 6d d 6|  j
 j ƒ  d 6|  j
 j ƒ  d 6| | f d 6| d 6| d 6t | ƒ j ƒ  d 6}	 | d k rct j ƒ  \ }
 } } |
 rˆd |
 | f } qˆn% | d k rˆd t j d d ƒ } n  | |	 d <|  j  rÎt j j	 | ƒ d t | d ƒ j ƒ  f |	 d <n  d t j |  j d |  j ƒ j ƒ  } d  } d! | } | d" } t j ƒ  } xù |	 j ƒ  D]ë \ } } t | ƒ t g  ƒ k rX| g } n  x¸ | D]° } t | ƒ t k r’d# | d$ } | d } n d } t | ƒ } | j | ƒ | j d% | ƒ | j | ƒ | j d& ƒ | j | ƒ | r_| d' d( k r_| j d) ƒ q_q_Wq(W| j | ƒ | j d) ƒ | j ƒ  } |  j d* | |  j f t  j! ƒ t" j" |  j ƒ \ } } } } } } | r–| r–| sœt# ‚ | d+ k rºt$ j% | ƒ } n+ | d, k rØt$ j& | ƒ } n t# d- | ‚ d }	 t  j! } yu | j' ƒ  | j( d. | ƒ | j) d/ d0 | ƒ | j) d1 t t* | ƒ ƒ ƒ | j) d2 | ƒ | j+ ƒ  | j, | ƒ Wn0 t- j. k
 r›} |  j t | ƒ t  j/ ƒ d  SX| j0 ƒ  } | j1 d3 k rÝ|  j d4 | j1 | j2 f t  j! ƒ n# |  j d5 | j1 | j2 f t  j/ ƒ |  j3 r'd6 d7 G| j ƒ  Gd6 d7 GHn  d  S(8   Nt   gpgs   --detach-signs   -as   --local-useri   t   dry_runt   rbR
   t	   bdist_eggs   built on %st   tersei   t   file_uploads   :actiont   1t   protcol_versiont   namet   versiont   contentt   filetypeR(   t
   md5_digestt	   bdist_rpms   built for %s %st
   bdist_dumbs   built for %st   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 %st   httpt   httpss   unsupported schema t   POSTs   Content-types    multipart/form-data; boundary=%ss   Content-lengtht   AuthorizationiÈ   s   Server response (%s): %ss   Upload failed (%s): %st   -iK   (4   R   R   R   R,   t   openR   t   closeR   R   t   basenameR$   t   has_ext_modulest   platformt   get_namet   get_versionR   t	   hexdigestt   distt   base64t   encodestringR   R   t   stript   StringIOt   itemst   typet   tuplet   strt   writet   getvalueR   R   R   t   INFOt   urlparset   AssertionErrort   httplibt   HTTPConnectiont   HTTPSConnectiont   connectt
   putrequestt	   putheadert   lent
   endheaderst   sendt   sockett   errort   ERRORt   getresponset   statust   reasonR   (   R   R'   R(   R)   t   gpg_argst   fR5   RD   R:   t   dataRJ   R4   t   idt   autht   boundaryt   sep_boundaryt   end_boundaryt   bodyt   keyt   valuet   fnt   schemat   netloct   urlt   paramst   queryt	   fragmentsR=   t   loglevelt   eR   (    (    s=   /usr/lib/python2.7/dist-packages/setuptools/command/upload.pyR&   L   s¬    			

	 '

 $	
	

	N(   s   show-responseNs&   display full response text from server(   s   signR   s   sign files to upload using gpg(   s	   identity=R	   s   GPG identity used to sign files(   t   __name__t
   __module__t   descriptionR    R   t   user_optionst   boolean_optionsR   R#   R*   R&   (    (    (    s=   /usr/lib/python2.7/dist-packages/setuptools/command/upload.pyR      s   
  				(   t   __doc__t   distutils.errorst   distutils.coreR   t   distutils.spawnR   t	   distutilsR   t   hashlibR   t   ImportErrorR   Ra   RF   R   RX   RK   RV   t	   cStringIORN   R   (    (    (    s=   /usr/lib/python2.7/dist-packages/setuptools/command/upload.pyt   <module>   s"   
