B
    ãUvg›  ã               @   sš   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 d dlmZ d d	lmZ G d
d„ de
j	ƒZ	dS )é    N)Ústandard_b64encode)Úlog)Úupload)Úspawn)ÚDistutilsError)ÚurlopenÚRequest)Ú	HTTPError)Úurlparsec               @   s8   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ ZdS )r   za
    Override default upload behavior to obtain password
    in a variety of different ways.
    c          
   C   s&   zt j | ¡ W d |  dtj¡ X d S )NzjWARNING: Uploading via this command is deprecated, use twine to upload instead (https://pypi.org/p/twine/))Úorigr   ÚrunÚannouncer   ÚWARN)Úself© r   úA/tmp/pip-install-r_9ig3yj/setuptools/setuptools/command/upload.pyr      s
    z
upload.runc             C   s8   t j | ¡ | jpt ¡ | _| jp0|  ¡ p0|  ¡ | _d S )N)	r   r   Úfinalize_optionsÚusernameÚgetpassÚgetuserÚpasswordÚ_load_password_from_keyringÚ_prompt_for_password)r   r   r   r   r   "   s    
zupload.finalize_optionsc              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
ƒ}| ¡ }W d Q R X | j	j
}dd| ¡ | ¡ tj |¡|f||t |¡ ¡ t| ¡ ƒ| ¡ | ¡ | ¡ | ¡ | ¡ | ¡ | ¡ | ¡ | ¡ | ¡ | ¡ |  ¡ | !¡ dœ}d|d< | jrdtj |¡d t|d d
ƒ ¡ f|d< | j"d | j#  $d¡}dt%|ƒ &d¡ }d}d| $d¡ }|d }t' (¡ }x¤| )¡ D ]˜\}}d| }t*|t+ƒsÚ|g}xr|D ]j}t,|ƒt-kr|d|d  7 }|d }nt|ƒ $d¡}| .|¡ | .| $d¡¡ | .d¡ | .|¡ qàW q¸W | .|¡ | /¡ }d|| jf }|  0|t1j2¡ d| tt3|ƒƒ|d œ}t4| j||d!}yt5|ƒ}| 6¡ }|j7}W nf t8k
rô } z|j9}|j7}W d d }~X Y n8 t:k
r* } z|  0t|ƒt1j;¡ ‚ W d d }~X Y nX |d"kr’|  0d#||f t1j2¡ | j<r´t=| d$d%d&„ ƒ|ƒ}|d k	r´d' >d(|d(f¡}|  0|t1j2¡ n"d)||f }|  0|t1j;¡ t?|ƒ‚d S )*NzIncompatible url %s)ÚhttpÚhttpszunsupported schema Zgpgz--detach-signz-az--local-useré   )Údry_runÚrbZfile_uploadÚ1)z:actionZprotocol_versionÚnameÚversionÚcontentZfiletypeÚ	pyversionZ
md5_digestÚmetadata_versionÚsummaryZ	home_pageÚauthorÚauthor_emailÚlicenseÚdescriptionÚkeywordsÚplatformÚclassifiersÚdownload_urlÚprovidesÚrequiresÚ	obsoletesÚ Ú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-lengthÚAuthorization)ÚdataÚheaderséÈ   zServer response (%s): %sÚ_read_pypi_responsec             S   s   d S )Nr   )Úxr   r   r   Ú<lambda>ª   ó    z$upload.upload_file.<locals>.<lambda>Ú
zK---------------------------------------------------------------------------zUpload failed (%s): %s)@r
   Ú
repositoryÚAssertionErrorÚsignÚidentityr   r   ÚopenÚreadÚdistributionÚmetadataÚget_nameÚget_versionÚosÚpathÚbasenameÚhashlibÚmd5Ú	hexdigestÚstrZget_metadata_versionÚget_descriptionÚget_urlÚget_contactÚget_contact_emailÚget_licenceÚget_long_descriptionÚget_keywordsÚget_platformsÚget_classifiersÚget_download_urlÚget_providesÚget_requiresÚget_obsoletesr   r   Úencoder   ÚdecodeÚioÚBytesIOÚitemsÚ
isinstanceÚlistÚtypeÚtupleÚwriteÚgetvaluer   r   ÚINFOÚlenr   r   ÚgetcodeÚmsgr	   ÚcodeÚOSErrorÚERRORÚshow_responseÚgetattrÚjoinr   ) r   Úcommandr"   ÚfilenameZschemaÚnetlocÚurlÚparamsÚqueryZ	fragmentsZgpg_argsÚfr!   Úmetar6   Ú	user_passÚauthÚboundaryZsep_boundaryZend_boundaryÚbodyÚkeyÚvalueÚtitlerj   r7   ÚrequestÚresultÚstatusÚreasonÚeÚtextr   r   r   Úupload_file0   s´    










zupload.upload_filec             C   s2   yt dƒ}| | j| j¡S  tk
r,   Y nX dS )zM
        Attempt to load password from keyring. Suppress Exceptions.
        ÚkeyringN)Ú
__import__Zget_passwordr>   r   Ú	Exception)r   r‡   r   r   r   r   ³   s
    z"upload._load_password_from_keyringc          	   C   s&   yt   ¡ S  ttfk
r    Y nX dS )zH
        Prompt for a password on the tty. Suppress Exceptions.
        N)r   r‰   ÚKeyboardInterrupt)r   r   r   r   r   ½   s    zupload._prompt_for_passwordN)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r†   r   r   r   r   r   r   r      s   
 
r   )r^   rH   rK   r   Úbase64r   Ú	distutilsr   Údistutils.commandr   r   Údistutils.spawnr   Zdistutils.errorsr   Z*setuptools.extern.six.moves.urllib.requestr   r   Z(setuptools.extern.six.moves.urllib.errorr	   Z(setuptools.extern.six.moves.urllib.parser
   r   r   r   r   Ú<module>   s   