3
]]                 @   s   d 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	m
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 G d
d deZdS )zm
distutils.command.upload

Implements the Distutils 'upload' subcommand (upload package to a package
index).
    N)standard_b64encode)urlopenRequest	HTTPError)urlparse)DistutilsErrorDistutilsOptionError)PyPIRCCommand)spawn)logc               @   sJ   e Zd ZdZejddg Zejdg Zdd	 Zd
d Zdd Z	dd Z
dS )uploadzupload binary package to PyPIsignssign files to upload using gpg	identity=iGPG identity used to sign filesc             C   s,   t j|  d| _d| _d| _d| _d | _d S )N r   F)r	   initialize_optionsusernamepasswordshow_responser   identity)self r   ./usr/lib/python3.6/distutils/command/upload.pyr       s    
zupload.initialize_optionsc             C   sv   t j|  | jr | j r td| j }|i krX|d | _|d | _|d | _|d | _	| j rr| j
jrr| j
j| _d S )Nz.Must use --sign for --identity to have meaningr   r   
repositoryrealm)r	   finalize_optionsr   r   r   Z_read_pypircr   r   r   r   distribution)r   Zconfigr   r   r   r   (   s    




zupload.finalize_optionsc             C   s>   | j jsd}t|x$| j jD ]\}}}| j||| qW d S )NzHMust create and upload files in one command (e.g. setup.py sdist upload))r   Z
dist_filesr   upload_file)r   msgcommand	pyversionfilenamer   r   r   run:   s
    z
upload.runc       $      C   s  t | j\}}}}}}	|s"|s"|	r0td| j |d/krDtd| | jr|ddd|g}
| jrnd| jg|
d	d	< t|
| jd
 t|d}z|j }W d |j	  X | j
j}dd|j |j tjj||f||tj|j d|j |j |j |j |j |j |j |j |j |j |j |j |j  d}d}|dkrZt!j" \}}}|rtd||f }n|dkrtdt!j!dd }||d< | jrtjj|d t|d dj f|d< | j#d | j$ j%d}dt&|j'd }d}d|j%d }|d }t(j) }x|j* D ]\}}d | }t+|t,s |g}xr|D ]j}t-|t.krR|d!|d"  7 }|d }nt/|j%d#}|j0| |j0|j%d# |j0d$ |j0| q&W qW |j0| |j1 }d%|| jf }| j2|t3j4 d&| t/t5||d'}t6| j||d(}yt7|}|j8 } |j9}!W nf t:k
r: }" z|"j;} |"j9}!W Y d d }"~"X n8 t<k
rp }" z| j2t/|"t3j=  W Y d d }"~"X nX | d)kr| j2d*| |!f t3j4 | j>r| j?|}#d+j@d,d- |#d,d- f}| j2|t3j4 n"d.| |!f }| j2|t3j= tA|d S )0NzIncompatible url %shttphttpszunsupported schema Zgpgz--detach-signz-az--local-user   )dry_runrbZfile_upload1z1.0)z:actionZprotocol_versionnameversioncontentZfiletyper#   Z
md5_digestZmetadata_versionZsummaryZ	home_pageZauthorZauthor_emailZlicensedescriptionkeywordsplatformZclassifiersZdownload_urlZprovidesZrequiresZ	obsoletesr   Z	bdist_rpmzbuilt for %s %sZ
bdist_dumbzbuilt for %s   )Ztersecommentz.ascZgpg_signature:asciizBasic z3--------------GHSKFJDLGDS7543FJKLFHRE75642756743254s   
--s   --
z+
Content-Disposition: form-data; name="%s"z; filename="%s"r   zutf-8s   

zSubmitting %s to %sz multipart/form-data; boundary=%s)zContent-typezContent-lengthZAuthorization)dataheaders   zServer response (%s): %s
-K   zUpload failed (%s): %s)r&   r'   )Br   r   AssertionErrorr   r   r
   r)   openreadcloser   ZmetadataZget_nameZget_versionospathbasenamehashlibZmd5Z	hexdigestZget_descriptionZget_urlZget_contactZget_contact_emailZget_licenceZget_long_descriptionZget_keywordsZget_platformsZget_classifiersZget_download_urlZget_providesZget_requiresZget_obsoletesr1   distr   r   encoder   decodeioBytesIOitems
isinstancelisttypetuplestrwritegetvalueZannouncer   INFOlenr   r   Zgetcoder!   r   codeOSErrorZERRORr   Z_read_pypi_responsejoinr   )$r   r"   r#   r$   ZschemaZnetlocZurlZparamsZqueryZ	fragmentsZgpg_argsfr.   metar6   r3   rD   r-   idZ	user_passZauthboundaryZsep_boundaryZend_boundaryZbodykeyvaluetitler!   r7   ZrequestresultZstatusreasonetextr   r   r   r    B   s    













zupload.upload_fileN)r   r   r   )r   r   r   )__name__
__module____qualname__r/   r	   Zuser_optionsZboolean_optionsr   r   r%   r    r   r   r   r   r      s    r   )__doc__r@   rG   r1   rC   base64r   Zurllib.requestr   r   r   Zurllib.parser   Zdistutils.errorsr   r   Zdistutils.corer	   Zdistutils.spawnr
   Z	distutilsr   r   r   r   r   r   <module>   s   