Current File : //usr/lib/python2.7/site-packages/euca2ools/commands/s3/__init__.pyc
�
��Xc@s�ddlZddlZddlZddlZddlmZddlZddlZddlZddl	Zddl
Z
ddlZddlm
Z
ddlmZdejjfd��YZdejjfd��YZd	�Zd
�ZdS(i����N(tArg(t	Euca2ools(tAWSErrortS3cBsYeZdZdZdZdZeddddd	d
�gZd�Zd�Z	d
�Z
RS(ts3sObject storage servicetEUCA_DEFAULT_REGIONtAWS_DEFAULT_REGIONtS3_URLs-Us--urltmetavartURLthelps#object storage service endpoint URLcCst|��dS(N(R(tselftresponse((sB/usr/lib/python2.7/site-packages/euca2ools/commands/s3/__init__.pythandle_http_error5scCs2tjjjj|�}|js@tjjjjd|�}ntjjjj|j�}|j||�\}}|r�|j||fS|j	j
d�}x{|j�D]m\}}tjjjj|�}	|j||	�\}}|r�|j	jdd|�}
|
p|||fSq�Wt
dj|���dS(s�
        Given a URL, try to return its associated region, bucket, and
        key names based on this object's endpoint info as well as all
        S3 endpoints given in the configuration.
        shttp://ss3-urltnametregionsgURL '{0}' matches no known object storage endpoints.  Supply one via the command line or configuration.N(tsixtmovesturllibtparseturlparsetschemetendpointt_S3__match_pathtregion_nametconfigtget_all_region_optionstitemstget_region_optiont
ValueErrortformat(Rturlt
parsed_urltparsed_own_urltbuckettkeyts3_urlstsectiontconf_urltparsed_conf_urlR((sB/usr/lib/python2.7/site-packages/euca2ools/commands/s3/__init__.pytresolve_url_to_location9s"			c
Csg|j|jkr�|j}|jd�s7|d7}n|jj|d�d}|jdd�\}}|jjd|j|j|j|j|j|j||�	n�|jj|j�rQ|jjd|jd�d}|jd�}|jj	d�r|jd}n	|j}|jjd|j|j|j|j|j|j||�	nd}d}||fS(Nt/is/URL path match:  %s://%s%s + %s://%s%s -> %s/%st.is0URL vhost match:  %s://%s%s + %s://%s%s -> %s/%s(tnetloctpathtendswithtsplittlogtdebugRtrsplittlstript
startswithtNone(Rtgiventservicetservice_pathtcpathR"R#((sB/usr/lib/python2.7/site-packages/euca2ools/commands/s3/__init__.pyt__match_pathTs.	

 	
(RR(t__name__t
__module__tNAMEtDESCRIPTIONt
REGION_ENVVARt
URL_ENVVARRtARGSR
R(R(((sB/usr/lib/python2.7/site-packages/euca2ools/commands/s3/__init__.pyR+s		t	S3RequestcBsPeZeZeZejjj	Z
d�Zd�Zd�Z
d�Zd�ZRS(cKs#tjjj||�d|_dS(Ni(trequestbuildertrequesttBaseRequestt__init__tredirects_left(Rtkwargs((sB/usr/lib/python2.7/site-packages/euca2ools/commands/s3/__init__.pyREwscCsdtjjj|�|j�r`|jjd�tjjj	j
|j�}|j�||_ndS(Nsswitching to HmacV4Auth(RBRCRDt	configuret_S3Request__should_use_sigv4R/tinfotauthtawst
HmacV4Autht
from_other(RRK((sB/usr/lib/python2.7/site-packages/euca2ools/commands/s3/__init__.pyRH{s
cCs|jj|jjd��S(Nss3-force-sigv4(Rtconvert_to_boolR(R((sB/usr/lib/python2.7/site-packages/euca2ools/commands/s3/__init__.pyt__should_use_sigv4�s	c	Cs�|j�|j�r@tjjjj|jd|dd�}n!tjjjj|jd|�}|jj	d|j
d|jd|jd|�S(sm
        Get a pre-signed URL for this request that expires after a given
        number of seconds.
        ttimeouttpayload_hashsUNSIGNED-PAYLOADtmethodR,tparamsRK(
t
preprocessRIRBRKRLtQueryHmacV4AuthRNtQueryHmacV1AuthR6tget_request_urlRSR,RT(RRQRK((sB/usr/lib/python2.7/site-packages/euca2ools/commands/s3/__init__.pytget_presigned_url2�s
cCsG|jdkr-|jjdditd6�|jj|jjditd6�|jjd�|jjd�d}d|jkr�|d	j|jd�7}n|jj|d
t�d|jkr�dj|jd�}nd
}t	j
jjj
|jj�}dj||j�}tjj|��ntjjj||�SdS(Ni-s-- response content --
textratappends-- end of response content --sresult: inter-region redirects%Aborting due to inter-region redirecttEndpoints to {0}texc_infotBuckets"{0}" tsuBucket {0}is not available from endpoint "{1}".  Ensure the object storage service URL matches the bucket's location.(tstatus_codeR/R0tTrueRttextterrortelementsRRRRRRR6RR+RBt
exceptionstClientErrorRCRDthandle_server_error(RterrtmsgR"tparsed((sB/usr/lib/python2.7/site-packages/euca2ools/commands/s3/__init__.pyRg�s&#(R:R;RtSUITERt
SERVICE_CLASSRBRKRLt
HmacV1Autht
AUTH_CLASSRERHRIRYRg(((sB/usr/lib/python2.7/site-packages/euca2ools/commands/s3/__init__.pyRArs		
		cCs�t|�dkr!td��nt|�dkrBtd��nx@|D]8}|tjtjdkrItdj|���qIqIWdS(Nisname is too shorti�sname is too longs.-_sinvalid character '{0}'(tlenRtstringt
ascii_letterstdigitsR(R"tchar((sB/usr/lib/python2.7/site-packages/euca2ools/commands/s3/__init__.pytvalidate_generic_bucket_name�s
cCs�t|�dkr!td��nt|�dkrBtd��n|jd�r`td��n|jd�r~td��n|jd�}x�|D]�}t|�dkr�td	��nx@|D]8}|tjtjd
kr�tdj|���q�q�W|dtjtjkr4tdj|d���n|d
tjtjkr�tdj|d
���q�q�Wt|�dkr�y*g|jd�D]}t	|�^q�Wntk
r�q�Xtd��ndS(Nisname is too shorti?sname is too longR*sname may not start with '.'sname may not end with '.'isname may not contain '..'t-sinvalid character '{0}'s3character '{0}' may not begin part of a bucket namei����s1character '{0}' may not end part of a bucket nameis-name must not be formatted like an IP address(
RoRR3R-R.Rptascii_lowercaseRrRtint(R"tlabelstlabelRstchunk((sB/usr/lib/python2.7/site-packages/euca2ools/commands/s3/__init__.pytvalidate_dns_bucket_name�s6

		*
(tosRptsysRRBRtrequestbuilder.auth.awstrequestbuilder.exceptionstrequestbuilder.requesttrequestbuilder.servicetrequestsRteuca2ools.commandsRteuca2ools.exceptionsRR6tBaseServiceRRCRDRARtR{(((sB/usr/lib/python2.7/site-packages/euca2ools/commands/s3/__init__.pyt<module>s GC