509318396
Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­
<!DOCTYPE html>
<html>
3
Ävh�  ã               @   s°   d Z ddlmZ ddlmZ ddlm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dlmZ ddlmZmZ ddlmZ d	d
lmZ dd„ ZG dd„ deƒZdS )zpupload_docs

Implements a Distutils 'upload_docs' subcommand (upload documentation to
PyPI's pythonhosted.org).
é    )Ústandard_b64encode)Úlog)ÚDistutilsOptionErrorN)Úsix)Úhttp_clientÚurllib)Úiter_entry_pointsé   )Úuploadc             C   s   t jr
dnd}| jd|ƒS )NÚsurrogateescapeÚstrictzutf-8)r   ÚPY3Úencode)ÚsÚerrors© r   ú!/usr/lib/python3.6/upload_docs.pyÚ_encode   s    r   c               @   s‚   e Zd ZdZdZdddej fddgZejZdd„ ZdefgZ	dd„ Z
dd„ Zdd„ Zdd„ Zedd„ ƒZedd„ ƒZdd„ ZdS )Úupload_docszhttps://pypi.python.org/pypi/zUpload documentation to PyPIzrepository=Úrzurl of repository [default: %s]úshow-responseNú&display full response text from serverúupload-dir=údirectory to uploadc             C   s$   | j d kr xtddƒD ]}dS W d S )Nzdistutils.commandsÚbuild_sphinxT)Ú
upload_dirr   )ÚselfZepr   r   r   Ú
has_sphinx/   s    
zupload_docs.has_sphinxr   c             C   s   t j| ƒ d | _d | _d S )N)r
   Úinitialize_optionsr   Ú
target_dir)r   r   r   r   r   6   s    
zupload_docs.initialize_optionsc             C   sˆ   t j| ƒ | jd krN| jƒ r0| jdƒ}|j| _q`| jdƒ}tjj	|j
dƒ| _n| jdƒ | j| _d| jkrttjdƒ | jd| j ƒ d S )Nr   ÚbuildZdocsr   zpypi.python.orgz3Upload_docs command is deprecated. Use RTD instead.zUsing upload directory %s)r
   Úfinalize_optionsr   r   Zget_finalized_commandZbuilder_target_dirr   ÚosÚpathÚjoinZ
build_baseZensure_dirnameÚ
repositoryr   ÚwarnÚannounce)r   r   r    r   r   r   r!   ;   s    







zupload_docs.finalize_optionsc             C   s¼   t j|dƒ}z | j| jƒ xŽtj| jƒD ]~\}}}|| jkrT| rTd}t|| j ƒ‚xP|D ]H}tjj||ƒ}|t	| jƒd … j
tjjƒ}	tjj|	|ƒ}
|j||
ƒ qZW q(W W d |jƒ  X d S )NÚwz'no files found in upload directory '%s')ÚzipfileZZipFileZmkpathr   r"   Úwalkr   r#   r$   ÚlenÚlstripÚsepÚwriteÚclose)r   ÚfilenameÚzip_fileÚrootÚdirsÚfilesZtmplÚnameZfullZrelativeÚdestr   r   r   Úcreate_zipfileK   s    
zupload_docs.create_zipfilec             C   sl   x| j ƒ D ]}| j|ƒ q
W tjƒ }| jjjƒ }tjj	|d| ƒ}z| j
|ƒ | j|ƒ W d tj|ƒ X d S )Nz%s.zip)Zget_sub_commandsZrun_commandÚtempfileZmkdtempÚdistributionÚmetadataÚget_namer"   r#   r$   r7   Úupload_fileÚshutilZrmtree)r   Zcmd_nameZtmp_dirr5   r1   r   r   r   Úrun[   s    
zupload_docs.runc             c   s”   | \}}d| }t |tƒs |g}xn|D ]f}t |tƒrN|d|d  7 }|d }nt|ƒ}|V  t|ƒV  dV  |V  |r&|dd … dkr&dV  q&W d S )	Nz*
Content-Disposition: form-data; name="%s"z; filename="%s"r   r	   s   

ó   ó   
éÿÿÿÿ)Ú
isinstanceÚlistÚtupler   )ÚitemÚsep_boundaryÚkeyÚvaluesÚtitleÚvaluer   r   r   Ú_build_parti   s    




zupload_docs._build_partc             C   sn   d}d| }|d }|df}t j| j|d�}t||jƒ ƒ}tjj|ƒ}tj||ƒ}	d|jdƒ }
dj	|	ƒ|
fS )	z=
        Build up the MIME payload for the POST data
        s3   --------------GHSKFJDLGDS7543FJKLFHRE75642756743254s   
--s   --r@   )rF   z multipart/form-data; boundary=%sÚasciió    )
Ú	functoolsÚpartialrK   ÚmapÚitemsÚ	itertoolsÚchainÚfrom_iterableÚdecoder$   )ÚclsÚdataÚboundaryrF   Zend_boundaryZ	end_itemsZbuilderZpart_groupsÚpartsZ
body_itemsÚcontent_typer   r   r   Ú_build_multipart}   s    zupload_docs._build_multipartc             C   sP  t |dƒ�}|jƒ }W d Q R X | jj}d|jƒ tjj|ƒ|fdœ}t| j	d | j
 ƒ}t|ƒ}tjrn|jdƒ}d| }| j|ƒ\}}	d| j }
| j|
tjƒ tjj| jƒ\}}}}}}| rÈ| rÈ| sÌt‚|dkràtj|ƒ}n |d	krôtj|ƒ}ntd
| ƒ‚d}yZ|jƒ  |jd|ƒ |	}|jd|ƒ |jdtt|ƒƒƒ |jd|ƒ |j ƒ  |j!|ƒ W n6 t"j#k
�r” } z| jt|ƒtj$ƒ d S d }~X nX |j%ƒ }|j&dk�rÊd|j&|j'f }
| j|
tjƒ nb|j&dk�r|j(dƒ}|d k�röd|jƒ  }d| }
| j|
tjƒ nd|j&|j'f }
| j|
tj$ƒ | j)�rLt*dd |jƒ dd ƒ d S )NÚrbZ
doc_upload)z:actionr5   Úcontentú:rL   zBasic zSubmitting documentation to %sZhttpZhttpszunsupported schema Ú ZPOSTzContent-typezContent-lengthZAuthorizationéÈ   zServer response (%s): %si-  ZLocationzhttps://pythonhosted.org/%s/zUpload successful. Visit %szUpload failed (%s): %sú-éK   )+ÚopenÚreadr9   r:   r;   r"   r#   Úbasenamer   ZusernameZpasswordr   r   r   rU   r[   r%   r'   r   ÚINFOr   ÚparseZurlparseÚAssertionErrorr   ZHTTPConnectionZHTTPSConnectionZconnectZ
putrequestZ	putheaderÚstrr+   Z
endheadersÚsendÚsocketÚerrorZERRORZgetresponseZstatusÚreasonZ	getheaderZshow_responseÚprint)r   r0   Úfr]   ÚmetarW   ZcredentialsZauthZbodyZctÚmsgZschemaZnetlocZurlZparamsZqueryZ	fragmentsZconnrZ   Úer   Úlocationr   r   r   r<   �   s`    



zupload_docs.upload_file)r   Nr   )r   Nr   )Ú__name__Ú
__module__Ú__qualname__ZDEFAULT_REPOSITORYÚdescriptionr
   Zuser_optionsZboolean_optionsr   Zsub_commandsr   r!   r7   r>   ÚstaticmethodrK   Úclassmethodr[   r<   r   r   r   r   r      s"   
 
r   )Ú__doc__Úbase64r   Z	distutilsr   Zdistutils.errorsr   r"   rk   r)   r8   r=   rR   rN   Zsetuptools.externr   Zsetuptools.extern.six.movesr   r   Zpkg_resourcesr   r
   r   r   r   r   r   r   Ú<module>   s    