FRTc@sWddlZddlZddlZddlZddlmZddlmZddlm Z ddlm Z ddl m Z m Z ddl mZddlmZdd lmZdd lmZdd lmZdd lmZdd lmZddlmZddl m!Z!dZ"dZ#dZ$dZ%ej&dZ'defdYZdS(iN(thandler(t ResultSet(tGSResponseError(tInvalidAclError(tACLtCannedACLStrings(tSupportedPermissions(tVersionedBucketListResultSet(tCors(tLifecycleConfig(tKey(tPolicy(tBucket(tget_utf8_value(tsixtdefaultObjectAcltacltcorst lifecycles"
(?P
.*)
R c BsueZdZdZdZdZdZd/d/edZ dZ dZ d/d/d/d/dZ d/d/d e e d/d/d/d Zd d d d d/d Zd Zd/d/d/d/dZd d/d/d/d/d/dZd/dZdZdZd d/d/d/dZd d/d/d/dZd/dZe dZd d/d/dd/d/d/dZd d/d/d/d/d/dZd/dZd/dZd/dZd/dZdZ e d/dZ!e d/d Z"e d/d!Z#d/d"Z$d/d#Z%d/d/d$Z&d/d%Z'd/d&Z(d/d/d/d'Z)d/d(Z*d/d)Z+d/d*Z,d/d+Z-d/d,Z.d/d-Z/d/d.Z0RS(0s)Represents a Google Cloud Storage bucket.sm %ssX %s%ss#%ss%scCs tt|j|||dS(N(tsuperR t__init__(tselft connectiontnamet key_class((s;/opt/freeware/lib/python2.7/site-packages/boto/gs/bucket.pyR<scCsdS(N(tNone(RRtattrsR((s;/opt/freeware/lib/python2.7/site-packages/boto/gs/bucket.pyt startElement?scCsD|dkr||_n(|dkr0||_nt|||dS(NtNamet CreationDate(Rt creation_datetsetattr(RRtvalueR((s;/opt/freeware/lib/python2.7/site-packages/boto/gs/bucket.pyt endElementBs     c Csg}|r |jd|n|rix@tj|D],\}}|jd|tj|fq6Wny"|j||d|\} } WnMtk r} | jdkrd| jkrd|j |f| _nnX| S(sfReturns a Key instance for an object in this bucket. Note that this method uses a HEAD request to check for the existence of the key. :type key_name: string :param key_name: The name of the key to retrieve :type response_headers: dict :param response_headers: A dictionary containing HTTP headers/values that will override any headers associated with the stored object in the response. See http://goo.gl/06N3b for details. :type version_id: string :param version_id: Unused in this subclass. :type generation: int :param generation: A specific generation number to fetch the key at. If not specified, the latest generation is fetched. :rtype: :class:`boto.gs.key.Key` :returns: A Key object from this bucket. s generation=%ss%s=%st query_args_lit ForbiddensAccess denied to 'gs://%s/%s'.( tappendRt iteritemsturllibtquotet_get_key_internalRtstatustreasonR( Rtkey_nametheaderst version_idtresponse_headerst generationR"trktrvtkeytrespte((s;/opt/freeware/lib/python2.7/site-packages/boto/gs/bucket.pytget_keyJs'tSTANDARDc Cse| r%| pi} t| | dt|trI|j|jd|n|j|d|dS(sFSets or changes a bucket's default ACL. :type acl_or_str: string or :class:`boto.gs.acl.ACL` :param acl_or_str: A canned ACL string (see :data:`~.gs.acl.CannedACLStrings`) or an ACL object. :type headers: dict :param headers: Additional headers to set during the request. s"Attempt to set S3 Policy on GS ACLR,N(RSR RRtset_def_xml_aclRUtset_def_canned_acl(RRWR,((s;/opt/freeware/lib/python2.7/site-packages/boto/gs/bucket.pyt set_def_acl6s cCs|jjd|j|d|d|}|j}|jdkr|jdkrtj|}|ru|jdnd}|rd|}t j t||}qn|jj j |j|j |n|S( sBProvides common functionality for get_xml_acl and _get_acl_helper.tGETR;R,iitdetailssP
%s. Note that Full Control access is required to access ACLs.
N(Rt make_requestRtreadR)tERROR_DETAILS_REGEXtsearchtgroupRtretsubtprovidertstorage_response_errorR*(RR+R,R;tresponsetbodytmatchR]((s;/opt/freeware/lib/python2.7/site-packages/boto/gs/bucket.pyt_get_xml_acl_helperGs   cCsJ|j|||}t|}tj||}tjj|||S(s:Provides common functionality for get_acl and get_def_acl.(RjRRt XmlHandlertxmltsaxt parseString(RR+R,R;RhRth((s;/opt/freeware/lib/python2.7/site-packages/boto/gs/bucket.pyt_get_acl_helperZs  cCs0t}|r|d|7}n|j|||S(sReturns the ACL of the bucket or an object in the bucket. :param str key_name: The name of the object to get the ACL for. If not specified, the ACL for the bucket will be returned. :param dict headers: Additional headers to set during the request. :type version_id: string :param version_id: Unused in this subclass. :param int generation: If specified, gets the ACL for a specific generation of a versioned object. If not specified, the current version is returned. This parameter is only valid when retrieving the ACL of an object, not a bucket. :rtype: :class:`.gs.acl.ACL` s&generation=%s(t STANDARD_ACLRp(RR+R,R-R/R;((s;/opt/freeware/lib/python2.7/site-packages/boto/gs/bucket.pytget_aclbscCs0t}|r|d|7}n|j|||S(sReturns the ACL string of the bucket or an object in the bucket. :param str key_name: The name of the object to get the ACL for. If not specified, the ACL for the bucket will be returned. :param dict headers: Additional headers to set during the request. :type version_id: string :param version_id: Unused in this subclass. :param int generation: If specified, gets the ACL for a specific generation of a versioned object. If not specified, the current version is returned. This parameter is only valid when retrieving the ACL of an object, not a bucket. :rtype: str s&generation=%s(RqRj(RR+R,R-R/R;((s;/opt/freeware/lib/python2.7/site-packages/boto/gs/bucket.pyt get_xml_aclzscCs|jd|tS(sReturns the bucket's default ACL. :param dict headers: Additional headers to set during the request. :rtype: :class:`.gs.acl.ACL` RC(Rpt DEF_OBJ_ACL(RR,((s;/opt/freeware/lib/python2.7/site-packages/boto/gs/bucket.pyt get_def_aclsc CsT|p i}d} |r.|||jjjtloggingR,N(tset_subresource(RR,txml_str((s;/opt/freeware/lib/python2.7/site-packages/boto/gs/bucket.pytdisable_loggingscCsjt|tr|j}nd}|d|}|rF|d|}n|d}|jd|d|dS(sEnable logging on a bucket. :type target_bucket: bucket or string :param target_bucket: The bucket to log to. :type target_prefix: string :param target_prefix: The prefix which should be prepended to the generated log files written to the target_bucket. :param dict headers: Additional headers to send with the request. s/s%ss%%ss RR,N(RSR RR(Rt target_buckett target_prefixR,R((s;/opt/freeware/lib/python2.7/site-packages/boto/gs/bucket.pytenable_loggings   cCs|jjd|jddd|}|j}tjj||jdkrs|jjj |j|j |ntj j }tj j |d}|j|||fS(sMReturns the current status of logging configuration on the bucket as unparsed XML. :param dict headers: Additional headers to send with the request. :rtype: 2-Tuple :returns: 2-tuple containing: 1) A dictionary containing the parsed XML response from GCS. The overall structure is: * Logging * LogObjectPrefix: Prefix that is prepended to log objects. * LogBucket: Target bucket for log objects. 2) Unparsed XML describing the bucket's logging configuration. R\R;RR,iN(RR^RR_tbototlogtdebugR)ReRfR*t jsonresponsetElementRkRtparse(RR,RgRhR4Ro((s;/opt/freeware/lib/python2.7/site-packages/boto/gs/bucket.pytget_logging_config_with_xmls    cCs|j|dS(sReturns the current status of logging configuration on the bucket. :param dict headers: Additional headers to send with the request. :rtype: dict :returns: A dictionary containing the parsed XML response from GCS. The overall structure is: * Logging * LogObjectPrefix: Prefix that is prepended to log objects. * LogBucket: Target bucket for log objects. i(R(RR,((s;/opt/freeware/lib/python2.7/site-packages/boto/gs/bucket.pytget_logging_config#sc Cs|r|j|}nd}|r2|j|}nd}|j||f}|jjdt|jdt|ddd|}|j}|jdkrt S|jj j |j|j |dS( sQConfigure this bucket to act as a website :type main_page_suffix: str :param main_page_suffix: Suffix that is appended to a request that is for a "directory" on the website endpoint (e.g. if the suffix is index.html and you make a request to samplebucket/images/ the data that is returned will be for the object with the key name images/index.html). The suffix must not be empty and must not include a slash character. This parameter is optional and the property is disabled if excluded. :type error_key: str :param error_key: The object key name to use when a 400 error occurs. This parameter is optional and the property is disabled if excluded. :param dict headers: Additional headers to send with the request. RCRvRwR;t websiteConfigR,iN( tWebsiteMainPageFragmenttWebsiteErrorFragmentt WebsiteBodyRR^R RR_R)R}ReRfR*(Rtmain_page_suffixt error_keyR,tmain_page_fragt error_fragRhRg((s;/opt/freeware/lib/python2.7/site-packages/boto/gs/bucket.pytconfigure_website3s   cCs|j|dS(s6Returns the current status of website configuration on the bucket. :param dict headers: Additional headers to send with the request. :rtype: dict :returns: A dictionary containing the parsed XML response from GCS. The overall structure is: * WebsiteConfiguration * MainPageSuffix: suffix that is appended to request that is for a "directory" on the website endpoint. * NotFoundPage: name of an object to serve when site visitors encounter a 404. i(t"get_website_configuration_with_xml(RR,((s;/opt/freeware/lib/python2.7/site-packages/boto/gs/bucket.pytget_website_configuration[scCs|jjd|jddd|}|j}tjj||jdkrs|jjj |j|j |ntj j }tj j |d}|j|||fS(sReturns the current status of website configuration on the bucket as unparsed XML. :param dict headers: Additional headers to send with the request. :rtype: 2-Tuple :returns: 2-tuple containing: 1) A dictionary containing the parsed XML response from GCS. The overall structure is: * WebsiteConfiguration * MainPageSuffix: suffix that is appended to request that is for a "directory" on the website endpoint. * NotFoundPage: name of an object to serve when site visitors encounter a 404 2) Unparsed XML describing the bucket's website configuration. R\R;RR,iN(RR^RR_RRRR)ReRfR*RRRkRR(RR,RgRhR4Ro((s;/opt/freeware/lib/python2.7/site-packages/boto/gs/bucket.pyRms   cCs|jd|dS(sRemove the website configuration from this bucket. :param dict headers: Additional headers to send with the request. R,N(R(RR,((s;/opt/freeware/lib/python2.7/site-packages/boto/gs/bucket.pytdelete_website_configurationscCs|jjd|jddd|}|j}tjj||jdkrs|jjj |j|j |ntj j }tj j |d j||d}d|ko|ddkS( sdReturns the current status of versioning configuration on the bucket. :rtype: bool R\R;t versioningR,itVersioningConfigurationtStatustEnabledN(RR^RR_RRRR)ReRfR*RRRkRR(RR,RgRht resp_json((s;/opt/freeware/lib/python2.7/site-packages/boto/gs/bucket.pytget_versioning_statuss    cCsC|tkr|jd}n |jd}|jd|d|dS(sConfigure versioning for this bucket. :param bool enabled: If set to True, enables versioning on this bucket. If set to False, disables versioning. :param dict headers: Additional headers to send with the request. Rt SuspendedRR,N(R}tVersioningBodyR(RtenabledR,treq_body((s;/opt/freeware/lib/python2.7/site-packages/boto/gs/bucket.pytconfigure_versionings  cCs|jjd|jdtd|}|j}tjj||jdkrt }t j ||}t j j|||S|jjj|j|j|dS(s Returns the current lifecycle configuration on the bucket. :rtype: :class:`boto.gs.lifecycle.LifecycleConfig` :returns: A LifecycleConfig object that describes all current lifecycle rules in effect for the bucket. R\R;R,iN(RR^Rt LIFECYCLE_ARGR_RRRR)R RRkRlRmRnReRfR*(RR,RgRhtlifecycle_configRo((s;/opt/freeware/lib/python2.7/site-packages/boto/gs/bucket.pytget_lifecycle_configs   c Cs|j}|jjdt|jdt|dtd|}|j}|jdkratS|jj j |j|j |dS(s Configure lifecycle for this bucket. :type lifecycle_config: :class:`boto.gs.lifecycle.LifecycleConfig` :param lifecycle_config: The lifecycle configuration you want to configure for this bucket. RvRwR;R,iN( RURR^R RRR_R)R}ReRfR*(RRR,RlRgRh((s;/opt/freeware/lib/python2.7/site-packages/boto/gs/bucket.pytconfigure_lifecycles    N(1t__name__t __module__t__doc__RRRRRtGSKeyRRR!R5tFalseR=RHRMRPRXR[RjRpRrRsRuR{RTRVRZRYRRRRRRRRRRRRRRRRRRR(((s;/opt/freeware/lib/python2.7/site-packages/boto/gs/bucket.pyR 1sv  ,  ? (  ,        #   '  '    $ " (  "  '  #    ((RcR&txml.saxRlRRtboto.resultsetRtboto.exceptionRRt boto.gs.aclRRRRtboto.gs.bucketlistresultsetRt boto.gs.corsRtboto.gs.lifecycleR t boto.gs.keyR Rt boto.s3.aclR tboto.s3.bucketR tS3Buckett boto.utilsR t boto.compatRRtRqR~RtcompileR`(((s;/opt/freeware/lib/python2.7/site-packages/boto/gs/bucket.pyts.