Current File : //usr/lib/python2.7/site-packages/euca2ools/commands/s3/putobject.pyc
�
��Xc@s�ddlZddlZddlZddlZddlZddlmZddlZddlm	Z	ddl
Z
ddlmZddl
Zdee	fd��YZdefd��YZdS(	i����N(tArg(tFileTransferProgressBarMixin(t	S3Requestt	PutObjectcBseZdZeddddd(dd�eddddd(dd	�ed
dedd(dd�ed
dd(dd)�eddd(dd�eddddddddddd(dd �ed!dej�gZd"Z	d#�Z
d$�Zd%�Zd&�Z
dd'�ZRS(*s�Upload an object to the server

Note that uploading a large file to a region other than the one the bucket is may result in "Broken pipe" errors or other connection problems that this program cannot detect.tsourcetmetavartFILEtroute_tothelpsfile to upload (required)tdests
BUCKET/KEYs6bucket and key name to upload the object to (required)s--sizettypesPthe number of
                bytes to upload (required when reading from stdin)s--acltchoicestprivatespublic-readspublic-read-writesauthenticated-readsbucket-owner-readsbucket-owner-full-controls
aws-exec-reads--mime-types%MIME type for the file being uploadeds--retrytretriestactiontstore_consttconstitdefaultis'retry interrupted uploads up to 5 timess--progressbar-labeltPUTcKs,tj||�d|_tj�|_dS(N(Rt__init__tNonetlast_upload_errort	threadingtLockt_lock(tselftkwargs((sC/usr/lib/python2.7/site-packages/euca2ools/commands/s3/putobject.pyR@s	cCs]tj|�|jddkri|jjd�dkrMtjjd��ntt	j
|jd�}n�t|jdtj
�r�tj|jdd|jjd��}nJ|jjd�dkr�tjjd��nt|jd|jd�}||jd<|jdjd�\}}}|s>tjjd��n|sYtjjd	��ndS(
NRt-tsizes0argument --size is required when uploading stdins8argument --size is required when uploading a file objectR	t/s)destination bucket name must be non-emptys&destination key name must be non-empty(Rt	configuretargstgetRtrequestbuildert
exceptionst
ArgumentErrort_FileObjectExtenttsyststdint
isinstancetsixtstring_typest
from_filenamet	partition(RRtbuckett_tkey((sC/usr/lib/python2.7/site-packages/euca2ools/commands/s3/putobject.pyRFs*
	%	
		cCsf|jd|_|jjd�r9|jd|jd<n|jjd�rb|jd|jd<ndS(NR	tacls	x-amz-aclt	mime_typesContent-Type(RtpathR theaders(R((sC/usr/lib/python2.7/site-packages/euca2ools/commands/s3/putobject.pyt
preprocess^s
c
Cs=|j�|jd}t|j�|jd<tjd|jd|fdi|jjd�p`dd6�}t	|_
|j�|jjd	�p�|j}|j
d
|d|j�}|j�x0|j�r�|j|j��tjd�q�W|j�|j�|j�|j� |jdk	r3|j�nWdQXdS(
NRsContent-LengthttargetRRR
itretries_lefttprogressbar_labeltlabeltmaxvalg�������?(R3RtbytesRR2RtThreadttry_sendR tTruetdaemontstarttfilenametget_progressbartis_alivetupdatettellttimetsleeptfinishtjointcloseRRR(RRt
upload_threadt
pbar_labeltpbar((sC/usr/lib/python2.7/site-packages/euca2ools/commands/s3/putobject.pytmainfs(

	"	





c	Cs�||_|dkr8|jr8|jjd�d}nyl|j�}|j}|jdj�jd�}||kr�|jj	d||�t
jjd��nWn�t
jjk
rD}t
|t
jj�r|dkr|jjd|�|j�|j||d�Sn|j�$|jj	d	d
t�||_WdQXdStk
r�}|j�$|jj	d	d
t�||_WdQXdSXdS(Nis@source cannot rewind, so requested retries will not be attemptedtETagt"s*corrupt upload (our MD5: %s, their MD5: %ss#upload was corrupted during transits/retrying upload (%i retry attempt(s) remaining)is
upload failedtexc_info(tbodyt
can_rewindtlogtnoticetsendtread_hexdigestR2tlowertstripterrorR!R"tClientErrorR'tTimeoutErrortinfotrewindR;RR<Rt	Exception(RRR5tresponsetour_md5t	their_md5terr((sC/usr/lib/python2.7/site-packages/euca2ools/commands/s3/putobject.pyR;�s:			
	


N(Rspublic-readspublic-read-writesauthenticated-readsbucket-owner-readsbucket-owner-full-controls
aws-exec-read(t__name__t
__module__tDESCRIPTIONRRtinttargparsetSUPPRESStARGStMETHODRRR3RLR;(((sC/usr/lib/python2.7/site-packages/euca2ools/commands/s3/putobject.pyR)s.				R$cBs}eZdd�Zd�Zedd��Zed��Zd�Z	d�Z
dd�Zed��Zd	�Z
d
�ZRS(cCspt|_||_||_||_d|_tj�|_t	|jd�rc|jj
�|_n	d|_dS(NiRC(
tFalsetclosedR?tfileobjRt_FileObjectExtent__bytes_readthashlibtmd5t_FileObjectExtent__md5thasattrRCt_FileObjectExtent__initial_posR(RRlRR?((sC/usr/lib/python2.7/site-packages/euca2ools/commands/s3/putobject.pyR�s					cCs|jS(N(R(R((sC/usr/lib/python2.7/site-packages/euca2ools/commands/s3/putobject.pyt__len__�scCs:|dkr!tjj|�}n|t|�|d|�S(NR?(Rt	euca2oolstutiltget_filesizetopen(tclsR?R((sC/usr/lib/python2.7/site-packages/euca2ools/commands/s3/putobject.pyR*�scCst|jd�o|jdk	S(Ntseek(RqRlRrR(R((sC/usr/lib/python2.7/site-packages/euca2ools/commands/s3/putobject.pyRQ�scCs|jj�t|_dS(N(RlRHR<Rk(R((sC/usr/lib/python2.7/site-packages/euca2ools/commands/s3/putobject.pyRH�s
cCsj|j|j}|dkr(t��nt|j�}|| }|jt|�7_|jj|�|S(Ni(RRmt
StopIterationtnextRltlenRpRB(Rt	remainingtchunk((sC/usr/lib/python2.7/site-packages/euca2ools/commands/s3/putobject.pyR{�s
i����cCso|j|j}|dkr%|}nt||�}|jj|�}|jt|�7_|jj|�|S(Ni(RRmtminRltreadR|RpRB(RRR}t	chunk_lenR~((sC/usr/lib/python2.7/site-packages/euca2ools/commands/s3/putobject.pyR��s	cCs
|jj�S(N(Rpt	hexdigest(R((sC/usr/lib/python2.7/site-packages/euca2ools/commands/s3/putobject.pyRU�scCset|jd�s!td��n|jdk	s6t�|jj|j�d|_tj	�|_
dS(NRysfile object is not seekablei(RqRlt	TypeErrorRrRtAssertionErrorRyRmRnRoRp(R((sC/usr/lib/python2.7/site-packages/euca2ools/commands/s3/putobject.pyR\�s	cCs|jS(N(Rm(R((sC/usr/lib/python2.7/site-packages/euca2ools/commands/s3/putobject.pyRC�sN(RbRcRRRstclassmethodR*tpropertyRQRHR{R�RUR\RC(((sC/usr/lib/python2.7/site-packages/euca2ools/commands/s3/putobject.pyR$�s			
	(RfRnR%RRDR!Rtrequestbuilder.exceptionstrequestbuilder.mixinsRR(teuca2ools.commands.s3Rteuca2ools.utilRtRtobjectR$(((sC/usr/lib/python2.7/site-packages/euca2ools/commands/s3/putobject.pyt<module>s}