FRTc@sddlZddlZddlmZmZddlZddlmZddl Z ddl m Z ddl m Z ddlmZddlmZddlmZdd lmZmZd Zd Zd efd YZdefdYZdefdYZdefdYZdefdYZdefdYZdefdYZ defdYZ!de fdYZ"dS(iN(tsixturllib(tdetect_potential_s3sigv4(tAWSAuthConnection(thandler(tBucket(tKey(t ResultSet(tBotoClientErrortS3ResponseErrorcCs#|djstdntS(sJ Bucket names must not contain uppercase characters. We check for this by appending a lowercase character and testing with islower(). Note this also covers cases like numeric bucket names with dashes. >>> check_lowercase_bucketname("Aaaa") Traceback (most recent call last): ... BotoClientError: S3Error: Bucket names cannot contain upper-case characters when using either the sub-domain or virtual hosting calling format. >>> check_lowercase_bucketname("1234-5678-9123") True >>> check_lowercase_bucketname("abcdefg1234") True tasuBucket names cannot contain upper-case characters when using either the sub-domain or virtual hosting calling format.(tislowerRtTrue(tn((s?/opt/freeware/lib/python2.7/site-packages/boto/s3/connection.pytcheck_lowercase_bucketname(scsfd}|S(Ncs2t|dkr%t|dr%n||S(Nii(tlenR(targstkwargs(tf(s?/opt/freeware/lib/python2.7/site-packages/boto/s3/connection.pytwrapperBs"((RR((Rs?/opt/freeware/lib/python2.7/site-packages/boto/s3/connection.pytassert_case_insensitiveAst_CallingFormatcBs>eZdZddZdZddZddZRS(cCsdS(Nt((tselftservertbucket((s?/opt/freeware/lib/python2.7/site-packages/boto/s3/connection.pytget_bucket_serverKsRcCsCd|}||j||7}||j|j||7}|S(Ns%s://(t build_hosttget_pathtbuild_path_base(Rt connectiontprotocolRRtkeyturl_base((s?/opt/freeware/lib/python2.7/site-packages/boto/s3/connection.pytbuild_url_baseNs cCs$|dkr|S|j||SdS(NR(R(RRR((s?/opt/freeware/lib/python2.7/site-packages/boto/s3/connection.pyRTs cCsItjj|}d}|dkr1d|}n|dtjj|S(NRt/s/%s(tbototutilstget_utf8_valueRtparsetquote(RRR tpath((s?/opt/freeware/lib/python2.7/site-packages/boto/s3/connection.pytbuild_auth_pathZs   cCs&tjj|}dtjj|S(Ns/%s(R$R%R&RR'R((RRR ((s?/opt/freeware/lib/python2.7/site-packages/boto/s3/connection.pyRas(t__name__t __module__RR"RR*R(((s?/opt/freeware/lib/python2.7/site-packages/boto/s3/connection.pyRIs     tSubdomainCallingFormatcBseZedZRS(cCsd||fS(Ns%s.%s((RRR((s?/opt/freeware/lib/python2.7/site-packages/boto/s3/connection.pyRhs(R+R,RR(((s?/opt/freeware/lib/python2.7/site-packages/boto/s3/connection.pyR-fstVHostCallingFormatcBseZedZRS(cCs|S(N((RRR((s?/opt/freeware/lib/python2.7/site-packages/boto/s3/connection.pyRos(R+R,RR(((s?/opt/freeware/lib/python2.7/site-packages/boto/s3/connection.pyR.mstOrdinaryCallingFormatcBseZdZddZRS(cCs|S(N((RRR((s?/opt/freeware/lib/python2.7/site-packages/boto/s3/connection.pyRvsRcCsCtjj|}d}|r/|d|7}n|tjj|S(NR#s%s/(R$R%R&RR'R((RRR t path_base((s?/opt/freeware/lib/python2.7/site-packages/boto/s3/connection.pyRys (R+R,RR(((s?/opt/freeware/lib/python2.7/site-packages/boto/s3/connection.pyR/ts t(ProtocolIndependentOrdinaryCallingFormatcBseZddZRS(RcCs?d}||j||7}||j|j||7}|S(Ns//(RRR(RRRRRR R!((s?/opt/freeware/lib/python2.7/site-packages/boto/s3/connection.pyR"s(R+R,R"(((s?/opt/freeware/lib/python2.7/site-packages/boto/s3/connection.pyR1stLocationcBs>eZdZdZdZdZdZdZdZdZ dZ RS( RtEUs us-west-1s us-west-2s sa-east-1sap-northeast-1sap-southeast-1sap-southeast-2s cn-north-1( R+R,tDEFAULTR3tUSWesttUSWest2tSAEastt APNortheastt APSoutheastt APSoutheast2tCNNorth1(((s?/opt/freeware/lib/python2.7/site-packages/boto/s3/connection.pyR2stNoHostProvidedcBseZRS((R+R,(((s?/opt/freeware/lib/python2.7/site-packages/boto/s3/connection.pyR<stHostRequiredErrorcBseZRS((R+R,(((s?/opt/freeware/lib/python2.7/site-packages/boto/s3/connection.pyR=st S3ConnectioncBseZejjdddZejjdddZdZdde ddddde ddedde de e ddd Z ed Zd Zd Zd ZdZdddddddddd Zddde ddddZddde e de ddZddZddZe ddZddZe ddZdejddZddZdddddddddZ RS(ts3thostss3.amazonaws.comtcalling_formats)boto.s3.connection.SubdomainCallingFormats)Signature=%s&Expires=%d&AWSAccessKeyId=%siR#tawscCst}| tkr$t}|j} nt| tjrNtjj | } n| |_ ||_ ||_ t t|j| ||||||||d| d| d| d|d|d|d|d| |rd |jkrtd qndS( Ntdebugthttps_connection_factoryR)tprovidertsecurity_tokentsuppress_consec_slashestvalidate_certst profile_names hmac-v4-s3s6When using SigV4, you must specify a 'host' parameter.(tFalseR<R t DefaultHostt isinstanceRt string_typesR$R%t find_classRAt bucket_classtanontsuperR>t__init__t_required_auth_capabilityR=(Rtaws_access_key_idtaws_secret_access_keyt is_securetporttproxyt proxy_portt proxy_usert proxy_passR@RCRDRAR)RERORFRGRPRHRItno_host_provided((s?/opt/freeware/lib/python2.7/site-packages/boto/s3/connection.pyRRs(       cCs|jrdgSdgSdS(NRPR?(RP(R((s?/opt/freeware/lib/python2.7/site-packages/boto/s3/connection.pyRSs ccs x|jD] }|Vq WdS(N(tget_all_buckets(RR((s?/opt/freeware/lib/python2.7/site-packages/boto/s3/connection.pyt__iter__scCs|j|dk S(N(tlookuptNone(Rt bucket_name((s?/opt/freeware/lib/python2.7/site-packages/boto/s3/connection.pyt __contains__scCs ||_dS(sX Set the Bucket class associated with this bucket. By default, this would be the boto.s3.key.Bucket class but if you want to subclass that for some reason this allows you to associate your new class. :type bucket_class: class :param bucket_class: A subclass of Bucket that can be more specific N(RO(RRO((s?/opt/freeware/lib/python2.7/site-packages/boto/s3/connection.pytset_bucket_classs cCsGt|tjstddtjtjj|dj|fS(sX Taken from the AWS book Python examples and modified for use with boto s;Policy document must include a valid expiration Time objects({"expiration": "%s", "conditions": [%s]}t,( RLttimet struct_timetAssertionErrortstrftimeR$R%tISO8601tjoin(Rtexpiration_timet conditions((s?/opt/freeware/lib/python2.7/site-packages/boto/s3/connection.pytbuild_post_policys ipthttptSTANDARDc Cs|dkrg}n| dkr*g} ntjttj|} | jd||jdr| jd|td n| jd||r| jd||jidd6|d6n|r| jd ||jid d6|d6n|r| jd |n|jjrd|jid d6|jjd6| jd |jjn| r|jidd6| d6| jd| n| r|jidd6| d6| jd| n|j | | } t j | }|jidd6|d6|jidd6|j d6|j j|}|jidd6|d6|jidd6|d6d||jj|j|f}i|d6|d6S(s Taken from the AWS book Python examples and modified for use with boto This only returns the arguments required for the post form, not the actual form. This does not return the file input field which also needs to be added :type bucket_name: string :param bucket_name: Bucket to submit to :type key: string :param key: Key name, optionally add ${filename} to the end to attach the submitted filename :type expires_in: integer :param expires_in: Time (in seconds) before this expires, defaults to 6000 :type acl: string :param acl: A canned ACL. One of: * private * public-read * public-read-write * authenticated-read * bucket-owner-read * bucket-owner-full-control :type success_action_redirect: string :param success_action_redirect: URL to redirect to on success :type max_content_length: integer :param max_content_length: Maximum size for this file :type http_method: string :param http_method: HTTP Method to use, "http" or "https" :type storage_class: string :param storage_class: Storage class to use for storing the object. Valid values: STANDARD | REDUCED_REDUNDANCY :type server_side_encryption: string :param server_side_encryption: Specifies server-side encryption algorithm to use when Amazon S3 creates an object. Valid values: None | AES256 :rtype: dict :return: A dictionary containing field names/values as well as a url to POST to .. code-block:: python s{"bucket": "%s"}s ${filename}s["starts-with", "$key", "%s"]s {"key": "%s"}s {"acl": "%s"}tacltnametvalues!{"success_action_redirect": "%s"}tsuccess_action_redirects["content-length-range", 0, %i]sx-amz-security-tokens{"x-amz-security-token": "%s"}sx-amz-storage-classs{"x-amz-storage-class": "%s"}sx-amz-server-side-encryptions&{"x-amz-server-side-encryption": "%s"}tpolicytAWSAccessKeyIdt signatureR s%s://%s/tactiontfieldsN(R`RetgmtimetinttappendtendswithRRERFRmtbase64t b64encodeRTt _auth_handlert sign_stringRARt server_name(RRaR t expires_inRpRstmax_content_lengtht http_methodRxRlt storage_classtserver_side_encryptiont expirationRtt policy_b64Rvturl((s?/opt/freeware/lib/python2.7/site-packages/boto/s3/connection.pytbuild_post_form_argssR:        Rc  Cs|jj||} |jj||} |jj|j|} | jdra| d } ni} |dk r|| d', validate=False) bucket.get_all_keys(maxkeys=0) :type bucket_name: string :param bucket_name: The name of the bucket :type headers: dict :param headers: Additional headers to pass along with the request to AWS. :type validate: boolean :param validate: If ``True``, it will try to verify the bucket exists on the service-side. (Default: ``True``) RN(t head_bucketRO(RRatvalidateR((s?/opt/freeware/lib/python2.7/site-packages/boto/s3/connection.pyt get_buckets%cCs|jd|d|}|j}|jdkrC|j||S|jdkr|jj|j|j|}d|_d|_|nf|jdkr|jj|j|j|}d|_d |_|n|jj|j|j|d S( s| Determines if a bucket exists by name. If the bucket does not exist, an ``S3ResponseError`` will be raised. :type bucket_name: string :param bucket_name: The name of the bucket :type headers: dict :param headers: Additional headers to pass along with the request to AWS. :returns: A object tHEADRiit AccessDenieds Access Deniedit NoSuchBuckets#The specified bucket does not existN( RRRRORERRt error_codet error_message(RRaRRRterr((s?/opt/freeware/lib/python2.7/site-packages/boto/s3/connection.pyRs,            cCs0y|j||d|}Wn d}nX|S(sR Attempts to get a bucket from S3. Works identically to ``S3Connection.get_bucket``, save for that it will return ``None`` if the bucket does not exist instead of throwing an exception. :type bucket_name: string :param bucket_name: The name of the bucket :type headers: dict :param headers: Additional headers to pass along with the request to AWS. :type validate: boolean :param validate: If ``True``, it will try to fetch all keys within the given bucket. (Default: ``True``) RN(RR`(RRaRRR((s?/opt/freeware/lib/python2.7/site-packages/boto/s3/connection.pyR_'s  cCst||r?|r)|||jjs1tPUTRtdataiiN( RREt acl_headerR2R4RRRtstorage_create_errorRROR(RRaRtlocationRtRRR((s?/opt/freeware/lib/python2.7/site-packages/boto/s3/connection.pyt create_bucket@s$      cCsX|jd|d|}|j}|jdkrT|jj|j|j|ndS(s Removes an S3 bucket. In order to remove the bucket, it must first be empty. If the bucket is not empty, an ``S3ResponseError`` will be raised. :type bucket_name: string :param bucket_name: The name of the bucket :type headers: dict :param headers: Additional headers to pass along with the request to AWS. tDELETERiN(RRRRERR(RRRRR((s?/opt/freeware/lib/python2.7/site-packages/boto/s3/connection.pyt delete_bucketos   c Cs't||jr|j}nt|tr9|j}n|jj||} tjjd| |jj ||} tjjd| |jj |j |} |r| d|7} tjjd| | d|7} tjjd| nt t |j|| ||| | |d|d| S(Nspath=%ss auth_path=%sRtoverride_num_retriest retry_handler(RLRORqRRARR$tlogRCR*RRRQR>R( RRRR RRt query_argstsenderRRR)RR@((s?/opt/freeware/lib/python2.7/site-packages/boto/s3/connection.pyRs&   N(!R+R,R$tconfigtgetRKtDefaultCallingFormatRR`R R<RRJRRRRSR^RbRcRmRRRR]RRRR_R2R4RRR(((s?/opt/freeware/lib/python2.7/site-packages/boto/s3/connection.pyR>sP       p   9 * -.   (#txml.saxRR}t boto.compatRRRet boto.authRt boto.utilsR$tboto.connectionRRtboto.s3.bucketRt boto.s3.keyRtboto.resultsetRtboto.exceptionRR RRtobjectRR-R.R/R1R2R<R=R>(((s?/opt/freeware/lib/python2.7/site-packages/boto/s3/connection.pyts,