ó
ÓnùWc           @   sþ   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	 m
 Z
 d d l m Z d d l m Z d d l m Z d d l m Z m Z m Z m Z m Z e rÒ d	 n d
 Z d d „ Z d e f d „  ƒ  YZ d S(   sp   upload_docs

Implements a Distutils 'upload_docs' subcommand (upload documentation to
PyPI's pythonhosted.org).
iÿÿÿÿN(   t   standard_b64encode(   t   iter_entry_points(   t   log(   t   DistutilsOptionError(   t   upload(   t   httplibt   urlparset   unicodet	   iteritemst   PY3t   surrogateescapet   stricts   utf-8c         C   s#   t  |  t ƒ r |  j | t ƒ S|  S(   N(   t
   isinstanceR   t   encodet   errors(   t   st   encoding(    (    sE   /var/www/html/venv/build/setuptools/setuptools/command/upload_docs.pyt   b   s    t   upload_docsc           B   s{   e  Z d  Z d d d e j f d d g Z e j Z d „  Z d	 e f g Z	 d
 „  Z
 d „  Z d „  Z d „  Z d „  Z RS(   s   Upload documentation to PyPIs   repository=t   rs   url of repository [default: %s]s   show-responses&   display full response text from servers   upload-dir=s   directory to uploadc         C   s1   |  j  d  k r- x t d d ƒ D] } t SWn  d  S(   Ns   distutils.commandst   build_sphinx(   t
   upload_dirt   NoneR   t   True(   t   selft   ep(    (    sE   /var/www/html/venv/build/setuptools/setuptools/command/upload_docs.pyt
   has_sphinx0   s    R   c         C   s#   t  j |  ƒ d  |  _ d  |  _ d  S(   N(   R   t   initialize_optionsR   R   t
   target_dir(   R   (    (    sE   /var/www/html/venv/build/setuptools/setuptools/command/upload_docs.pyR   7   s    	c         C   s¤   t  j |  ƒ |  j d  k rs |  j ƒ  rF |  j d ƒ } | j |  _ qŒ |  j d ƒ } t j	 j
 | j d ƒ |  _ n |  j d ƒ |  j |  _ |  j d |  j ƒ d  S(   NR   t   buildt   docsR   s   Using upload directory %s(   R   t   finalize_optionsR   R   R   t   get_finalized_commandt   builder_target_dirR   t   ost   patht   joint
   build_baset   ensure_dirnamet   announce(   R   R   R   (    (    sE   /var/www/html/venv/build/setuptools/setuptools/command/upload_docs.pyR   <   s    c   
      C   s÷   t  j | d ƒ } zÓ |  j |  j ƒ x¼ t j |  j ƒ D]¨ \ } } } | |  j k rs | rs t d |  j ƒ ‚ n  xj | D]b } t j j | | ƒ } | t	 |  j ƒ j
 t j j ƒ } t j j | | ƒ }	 | j | |	 ƒ qz Wq8 WWd  | j ƒ  Xd  S(   Nt   ws'   no files found in upload directory '%s'(   t   zipfilet   ZipFilet   mkpathR   R"   t   walkR   R#   R$   t   lent   lstript   sept   writet   close(
   R   t   filenamet   zip_filet   roott   dirst   filest   namet   fullt   relativet   dest(    (    sE   /var/www/html/venv/build/setuptools/setuptools/command/upload_docs.pyt   create_zipfileJ   s    ""c         C   sŽ   x! |  j  ƒ  D] } |  j | ƒ q Wt j ƒ  } |  j j j ƒ  } t j j	 | d | ƒ } z |  j
 | ƒ |  j | ƒ Wd  t j | ƒ Xd  S(   Ns   %s.zip(   t   get_sub_commandst   run_commandt   tempfilet   mkdtempt   distributiont   metadatat   get_nameR"   R#   R$   R;   t   upload_filet   shutilt   rmtree(   R   t   cmd_namet   tmp_dirR7   R3   (    (    sE   /var/www/html/venv/build/setuptools/setuptools/command/upload_docs.pyt   run[   s    c         C   s`  t  | d ƒ } | j ƒ  } | j ƒ  |  j j } i d d 6| j ƒ  d 6t j j | ƒ | f d 6} t	 |  j
 d |  j ƒ } t | ƒ } t r¢ | j d ƒ } n  d | } d	 } t	 d
 ƒ t	 | ƒ }	 |	 t	 d ƒ }
 g  } xÿ t | ƒ D]ñ \ } } d | } t | t ƒ s| g } n  x½ | D]µ } t | ƒ t k rZ| d | d 7} | d } n t	 | ƒ } | j |	 ƒ | j t	 | ƒ ƒ | j t	 d ƒ ƒ | j | ƒ | r#| d t	 d ƒ k r#| j t	 d ƒ ƒ q#q#Wqë W| j |
 ƒ | j t	 d ƒ ƒ t	 d ƒ j | ƒ } |  j d |  j t j ƒ t |  j ƒ \ } } } } } } | re| re| skt ‚ | d k r‰t j | ƒ } n. | d k r§t j | ƒ } n t d | ƒ ‚ d } y{ | j ƒ  | j  d | ƒ d | } | j! d | ƒ | j! d t" t# | ƒ ƒ ƒ | j! d | ƒ | j$ ƒ  | j% | ƒ Wn> t& j' k
 rxt( j) ƒ  d } |  j t" | ƒ t j* ƒ d  SX| j+ ƒ  } | j, d k rº|  j d | j, | j- f t j ƒ nz | j, d  k r| j. d! ƒ } | d  k r÷d" | j ƒ  } n  |  j d# | t j ƒ n# |  j d$ | j, | j- f t j* ƒ |  j0 r\d% d& | j ƒ  d% d& f GHn  d  S('   Nt   rbt
   doc_uploads   :actionR7   t   contentt   :t   asciis   Basic s3   --------------GHSKFJDLGDS7543FJKLFHRE75642756743254s   
--s   --s*   
Content-Disposition: form-data; name="%s"s   ; filename="%s"i    i   s   

iÿÿÿÿs   s   
t    s   Submitting documentation to %st   httpt   httpss   unsupported schema t   POSTs    multipart/form-data; boundary=%ss   Content-types   Content-lengtht   AuthorizationiÈ   s   Server response (%s): %si-  t   Locations   https://pythonhosted.org/%s/s   Upload successful. Visit %ss   Upload failed (%s): %st   -iK   (1   t   opent   readR1   R@   RA   RB   R"   R#   t   basenameR   t   usernamet   passwordR    R	   t   decodeR   R   t   listt   typet   tuplet   appendR$   R'   t
   repositoryR   t   INFOR   t   AssertionErrorR   t   HTTPConnectiont   HTTPSConnectiont   connectt
   putrequestt	   putheadert   strR-   t
   endheaderst   sendt   sockett   errort   syst   exc_infot   ERRORt   getresponset   statust   reasont	   getheaderR   t   show_response(   R   R2   t   fRK   t   metat   datat   credentialst   autht   boundaryt   sep_boundaryt   end_boundaryt   bodyt   keyt   valuest   titlet   valuet   schemat   netloct   urlt   paramst   queryt	   fragmentst   connt   content_typet   eR   t   location(    (    sE   /var/www/html/venv/build/setuptools/setuptools/command/upload_docs.pyRC   i   s    



!



	N(   s   show-responseNs&   display full response text from server(   s   upload-dir=Ns   directory to upload(   t   __name__t
   __module__t   descriptionR   t   DEFAULT_REPOSITORYR   t   user_optionst   boolean_optionsR   t   sub_commandsR   R   R;   RH   RC   (    (    (    sE   /var/www/html/venv/build/setuptools/setuptools/command/upload_docs.pyR   #   s    							(   t   __doc__R"   Rj   R)   R>   Rl   RD   t   base64R    t   pkg_resourcesR   t	   distutilsR   t   distutils.errorsR   t   distutils.command.uploadR   t   setuptools.compatR   R   R   R   R	   R   R   R   (    (    (    sE   /var/www/html/venv/build/setuptools/setuptools/command/upload_docs.pyt   <module>   s   (