3
¿ÞL]›  ã               @   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j| ƒ W d | j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   ú?/tmp/pip-build-69lrc5qx/setuptools/setuptools/command/upload.pyr      s
    z
upload.runc             C   s8   t jj| ƒ | jptjƒ | _| jp0| jƒ p0| jƒ | _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ƒ�}|jƒ }W d Q R X | j	j
}dd|jƒ |jƒ tjj|ƒ|f||tj|ƒjƒ t|jƒ ƒ|jƒ |jƒ |jƒ |jƒ |jƒ |jƒ |jƒ |jƒ |jƒ |jƒ |jƒ |j ƒ |j!ƒ dœ}d|d< | j�rdt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�r|d|d  7 }|d }nt|ƒj$dƒ}|j.|ƒ |j.|j$dƒƒ |j.dƒ |j.|ƒ �qàW �q¸W |j.|ƒ |j/ƒ }d|| jf }| j0|t1j2ƒ d | tt3|ƒƒ|d!œ}t4| j||d"�}yt5|ƒ}|j6ƒ }|j7}W nf t8k
�rô } z|j9}|j7}W Y d d }~X n8 t:k
�r* } z| j0t|ƒt1j;ƒ ‚ W Y d d }~X nX |d#k�rš| j0d$||f t1j2ƒ | j<�r¼t=| d%d&d'„ ƒ|ƒ}|d k	�r¼d(j>d)d* |d)d* fƒ}| j0|t1j2ƒ n"d+||f }| j0|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>ª   s    z$upload.upload_file.<locals>.<lambda>Ú
ú-éK   zUpload failed (%s): %s)r   r   )@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Útitlerk   r7   ÚrequestÚresultÚstatusÚreasonÚeÚtextr   r   r   Úupload_file0   s´    










zupload.upload_filec             C   s2   yt dƒ}|j| 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 j ƒ 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_   rI   rL   r   Úbase64r   Ú	distutilsr   Údistutils.commandr   r   Údistutils.spawnr   Ú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   