Current File : //usr/lib/python2.7/site-packages/euca2ools/commands/s3/getobject.pyo
�
��Xc@s�ddlZddlZddlZddlmZddlmZddlm	Z	ddl
Z
ddlmZddl
Zdee	fd��YZdS(i����N(tArg(t
ArgumentError(tFileTransferProgressBarMixin(t	S3Requestt	GetObjectc
BsqeZdZeddddddd�eddddd	ddd
ddd�gZd
�Zd�Zd�ZRS(s Retrieve objects from the servertsourcetmetavars
BUCKET/KEYtroute_tothelps!the object to download (required)s-otdesttPATHtdefaultt.sDwhere to download to.  If this names a
                directory the object will be written to a file inside of that
                directory.  If this is is "-" the object will be written to
                stdout.  Otherwise it will be written to a file with the name
                given.  (default:  current directory)cCs3tj|�|jdjd�\}}}|sAtd��n|sVtd��nt|jjd�tj�r/|jddkr�t	j
|jd<q/tjj
|jd�rtjj|�}|s�td��ntjj|jd|�}t|d�|jd<q/t|jdd�|jd<ndS(	NRt/s!source must contain a bucket namessource must contain a key nameR	t-sHspecify a complete file path with -o to download objects that end in '/'tw(Rt	configuretargst	partitionRt
isinstancetgettsixtstring_typestsyststdouttostpathtisdirtbasenametjointopen(tselftbuckett_tkeyRt	dest_path((sC/usr/lib/python2.7/site-packages/euca2ools/commands/s3/getobject.pyR2s 
cCs|jd|_dS(NR(RR(R((sC/usr/lib/python2.7/site-packages/euca2ools/commands/s3/getobject.pyt
preprocessIsc	CsF|j�d}tj�}tj�}|j�}|jjd�}|rt|jd|jddt	|��}n|jd|jd�}|j
�xw|jdtj
�D]`}|jdj|�|t|�7}|j|�|j|�|dk	r�|j|�q�q�W|jdj�|j�|ru|t	|�kru|jjd||�td	j||���n|jjd
d�j�jd�}t|�d
krtd�|D��r|j�|kr|jjd||j��tdj||j����qnii|j�d6|j�d6|d6|jd6S(NisContent-LengthtlabelRtmaxvalt
chunk_sizeR	sQrejecting download due to Content-Length size mismatch (expected: %i, actual: %i)sGdownloaded file appears to be corrupt (expected size: {0}, actual: {1})tETagtt"i css|]}|dkVqdS(t0123456789abcdefN((t.0tchar((sC/usr/lib/python2.7/site-packages/euca2ools/commands/s3/getobject.pys	<genexpr>nssFrejecting download due to ETag MD5 mismatch (expected: %s, actual: %s)sFdownloaded file appears to be corrupt (expected MD5: {0}, actual: {1})tmd5tsha1tsize(R$thashlibR.R/tsendtheadersRtget_progressbarRtinttstarttiter_contentt	euca2oolstBUFSIZEtwritetlentupdatetNonetflushtfinishtlogterrortRuntimeErrortformattlowertstriptallt	hexdigest(	Rt
bytes_writtent
md5_digestt
sha_digesttresponsetcontent_lengthtpbartchunktetag((sC/usr/lib/python2.7/site-packages/euca2ools/commands/s3/getobject.pytmainLsH





	$	
N(	t__name__t
__module__tDESCRIPTIONRR=tARGSRR$RP(((sC/usr/lib/python2.7/site-packages/euca2ools/commands/s3/getobject.pyR's		(R1tos.pathRRtrequestbuilderRtrequestbuilder.exceptionsRtrequestbuilder.mixinsRRteuca2ools.commands.s3Rteuca2ools.bundle.pipesR8R(((sC/usr/lib/python2.7/site-packages/euca2ools/commands/s3/getobject.pyt<module>s