
    ޣ                        S r SSKJr  SSKJr  SSKJr   " S S\5      r " S S\5      r " S	 S
\5      r	 " S S\5      r
 " S S\
5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S \5      r " S! S"\5      r " S# S$\5      r " S% S&\5      r " S' S(\5      r " S) S*\5      rg+),z8Gsutil API for interacting with cloud storage providers.    )absolute_import)division)unicode_literalsc                   n   \ rS rSrSr      S0S jrS rS1S jrS1S jrS2S	 jr	S
 r
S3S jr     S4S jrS2S jr    S5S jrS1S jr " S S\5      r " S S\5      r     S4S jr   S3S jr  S1S jr   S3S jr     S4S jr " S S\5      rSSSS\R2                  SSSSSS4S jr        S6S jr       S7S jr          S8S jr         S9S  jr    S5S! jr   S3S" jr    S3S# jr!S2S$ jr"S2S% jr#S2S& jr$    S5S' jr%S2S( jr&S2S) jr'S* r(S+ r)S, r* S:S- jr+S. r,S/r-g);CloudApi   ao  Abstract base class for interacting with cloud storage providers.

Implementations of the gsutil Cloud API are not guaranteed to be thread-safe.
Behavior when calling a gsutil Cloud API instance simultaneously across
threads is undefined and doing so will likely cause errors. Therefore,
a separate instance of the gsutil Cloud API should be instantiated per-thread.
Nr   c
                 p    Xl         X l        X0l        X@l        XPl        X`l        Xpl        Xl        Xl        g)a  Performs necessary setup for interacting with the cloud storage provider.

Args:
  bucket_storage_uri_class: boto storage_uri class, used by APIs that
                            provide boto translation or mocking.
  logger: logging.logger for outputting log messages.
  status_queue: Queue for relaying status to UI.
  provider: Default provider prefix describing cloud storage provider to
            connect to.
  debug: Debug level for the API implementation (0..3).
  http_headers (dict|None): Arbitrary headers to be included in every request.
  trace_token: Google internal trace token to pass to the API
               implementation (string).
  perf_trace_token: Performance trace token to use when making API calls.
  user_project: Project to be billed for this request.
N)	bucket_storage_uri_classloggerstatus_queueproviderdebughttp_headerstrace_tokenperf_trace_tokenuser_project)
selfr
   r   r   r   r   r   r   r   r   s
             "platform/gsutil/gslib/cloud_api.py__init__CloudApi.__init__   s7    4 %=!K$MJ$",$    c                     [        S5      e)z%Returns the service account email id.z'GetServiceAccountId must be overridden.NotImplementedErrorr   s    r   GetServiceAccountIdCloudApi.GetServiceAccountIdC   s    
G
HHr   c                     [        S5      e)a  Gets Bucket metadata.

Args:
  bucket_name: Name of the bucket.
  provider: Cloud storage provider to connect to.  If not present,
            class-wide default is used.
  fields: If present, return only these Bucket metadata fields, for
          example, ['logging', 'defaultObjectAcl']

Raises:
  ArgumentException for errors during input validation.
  ServiceException for errors interacting with cloud storage providers.

Returns:
  Bucket object.
zGetBucket must be overloadedr   r   bucket_namer   fieldss       r   	GetBucketCloudApi.GetBucketG   s    " <
==r   c                     [        S5      e)a  Returns an IAM policy for the specified Bucket.

Args:
  bucket_name: Name of the bucket.
  provider: Cloud storage provider to connect to.  If not present,
            class-wide default is used.
  fields: If present, return only the IAM policy fields specified.

Raises:
  ArgumentException for errors during input validation.
  ServiceException for errors interacting with the cloud storage providers.

Returns:
  Policy object of the bucket.
z%GetBucketIamPolicy must be overloadedr   r   s       r   GetBucketIamPolicyCloudApi.GetBucketIamPolicyZ         E
FFr   c                     [        S5      e)a  Sets an IAM policy for the specified Bucket.

Args:
  bucket_name: Name of the bucket.
  policy: A Policy object describing the IAM policy.
  provider: Cloud storage provider to connect to.  If not present,
            class-wide default is used.

Raises:
  ArgumentException for errors during input validation.
  ServiceException for errors interacting with the cloud storage providers.

Returns:
  Policy object of the bucket. May differ from input Policy.
z%SetBucketIamPolicy must be overloadedr   )r   r    policyr   s       r   SetBucketIamPolicyCloudApi.SetBucketIamPolicyl   r'   r   c	                     [        S5      e)a  Sign a url using service account's system managed private key.

Args:
  method: The HTTP method to be used with the signed URL.
  duration: timedelta for which the constructed signed URL should be valid.
  path: String path to the bucket or object for signing, in the form
      'bucket' or 'bucket/object'.
  generation: If not None, specifies a version of an object for signing.
  logger: logging.Logger for warning and debug output.
  region: Geographic region in which the requested resource resides.
  signed_headers: Dict containing the header  info like host
      content-type etc.
  string_to_sign_debug: If true AND logger is enabled for debug level,
      print string to sign to debug. Used to differentiate user's
      signed URL from the probing permissions-check signed URL.

Raises:
  ArgumentException for errors during input validation.
  ServiceException for errors interacting with cloud storage providers.
  CommandException for errors because of invalid account used for signing.

Returns:
  The signed url.
zSignUrl must be overloadedr   )	r   methoddurationpath
generationr   regionsigned_headersstring_to_sign_debugs	            r   SignUrlCloudApi.SignUrl~   s    4 :
;;r   c                     [        S5      e)a  Lists bucket metadata for the given project.

Args:
  project_id: Project owning the buckets, default from config if None.
  provider: Cloud storage provider to connect to.  If not present,
            class-wide default is used.
  fields: If present, return only these metadata fields for the listing,
          for example:
          ['items/logging', 'items/defaultObjectAcl'].
          Note that the WildcardIterator class should be used to list
          buckets instead of calling this function directly.  It amends
          the fields definition from get-like syntax such as
          ['logging', 'defaultObjectAcl'] so that the caller does not
          need to prepend 'items/' or specify fields necessary for listing
          (like nextPageToken).

Raises:
  ArgumentException for errors during input validation.
  ServiceException for errors interacting with cloud storage providers.

Returns:
  Iterator over Bucket objects.
zListBuckets must be overloadedr   )r   
project_idr   r!   s       r   ListBucketsCloudApi.ListBuckets   s    0 >
??r   c                     [        S5      e)a  Updates bucket metadata for the bucket with patch semantics.

Args:
  bucket_name: Name of bucket to update.
  metadata: Bucket object defining metadata to be updated.
  canned_acl: Canned ACL to apply to the bucket.
  canned_def_acl: Canned default object ACL to apply to the bucket.
  preconditions: Preconditions for the request.
  provider: Cloud storage provider to connect to.  If not present,
            class-wide default is used.
  fields: If present, return only these Bucket metadata fields.

Raises:
  ArgumentException for errors during input validation.
  ServiceException for errors interacting with cloud storage providers.

Returns:
  Bucket object describing new bucket metadata.
zPatchBucket must be overloadedr   )r   r    metadata
canned_aclcanned_def_aclpreconditionsr   r!   s           r   PatchBucketCloudApi.PatchBucket   s    6 >
??r   c                     [        S5      e)ah  Locks the Retention Policy on the bucket.

Args:
  bucket_name: Name of bucket to update.
  metageneration: Bucket metageneration to use as a precondition.
  provider: Cloud storage provider to connect to. If not present,
            class-wide default is used.

Raises:
  ServiceException for errors interacting with cloud storage providers.

Returns:
  None
z&LockRetentionPolicy must be overloadedr   )r   r    metagenerationr   s       r   LockRetentionPolicyCloudApi.LockRetentionPolicy   s     F
GGr   c                     [        S5      e)aR  Creates a new bucket with the specified metadata.

Args:
  bucket_name: Name of the new bucket.
  project_id: Project owner of the new bucket, default from config if None.
  metadata: Bucket object defining new bucket metadata.
  provider: Cloud storage provider to connect to.  If not present,
            class-wide default is used.
  fields: If present, return only these Bucket metadata fields.

Raises:
  ArgumentException for errors during input validation.
  ServiceException for errors interacting with cloud storage providers.

Returns:
  Bucket object describing new bucket metadata.
zCreateBucket must be overloadedr   )r   r    r7   r;   r   r!   s         r   CreateBucketCloudApi.CreateBucket   s    . ?
@@r   c                     [        S5      e)a|  Deletes a bucket.

Args:
  bucket_name: Name of the bucket to delete.
  preconditions: Preconditions for the request.
  provider: Cloud storage provider to connect to.  If not present,
            class-wide default is used.

Raises:
  ArgumentException for errors during input validation.
  ServiceException for errors interacting with cloud storage providers.

Returns:
  None.
zDeleteBucket must be overloadedr   )r   r    r>   r   s       r   DeleteBucketCloudApi.DeleteBucket   s      ?
@@r   c                        \ rS rSrSrSrSrSrg)CloudApi.CsObjectOrPrefixTypei  z1Enum class for describing CsObjectOrPrefix types.objectprefix N)__name__
__module____qualname____firstlineno____doc__OBJECTPREFIX__static_attributes__rO   r   r   CsObjectOrPrefixTyperL     s    ;FFr   rX   c                       \ rS rSrSrS rSrg)CloudApi.CsObjectOrPrefixi  z(Container class for ListObjects results.c                     Xl         X l        g)zStores a ListObjects result.

Args:
  data: Root object, either an apitools Object or a string Prefix.
  datatype: CsObjectOrPrefixType of data.
Ndatadatatype)r   r]   r^   s      r   r   "CloudApi.CsObjectOrPrefix.__init__  s     imr   r\   NrP   rQ   rR   rS   rT   r   rW   rO   r   r   CsObjectOrPrefixrZ     s
    2r   ra   c                     [        S5      e)aH  Lists objects (with metadata) and prefixes in a bucket.

Args:
  bucket_name: Bucket containing the objects.
  prefix: Prefix for directory-like behavior.
  delimiter: Delimiter for directory-like behavior.
  all_versions: If true, list all object versions.
  provider: Cloud storage provider to connect to.  If not present,
            class-wide default is used.
  fields: If present, return only these metadata fields for the listing,
          for example:
          ['items/acl', 'items/updated', 'prefixes'].
          Note that the WildcardIterator class should be used to list
          objects instead of calling this function directly.  It amends
          the fields definition from get-like syntax such as
          ['acl', 'updated'] so that the caller does not need to
          prepend 'items/' or specify any fields necessary for listing
          (such as prefixes or nextPageToken).

Raises:
  ArgumentException for errors during input validation.
  ServiceException for errors interacting with cloud storage providers.

Returns:
  Iterator over CsObjectOrPrefix wrapper class.
zListObjects must be overloadedr   )r   r    rN   	delimiterall_versionsr   r!   s          r   ListObjectsCloudApi.ListObjects  s    B >
??r   c                     [        S5      e)a  Gets IAM policy for specified Object.

Args:
  bucket_name: Bucket containing the object.
  object_name: Name of the object.
  generation: Generation of the object to retrieve.
  provider: Cloud storage provider to connect to.  If not present,
            class-wide default is used.
  fields: If present, return only the IAM policy fields specified.

Raises:
  ArgumentException for errors during input validation.
  ServiceException for errors interacting with cloud storage providers.

Returns:
  Object IAM policy.
z%GetObjectIamPolicy must be overloadedr   r   r    object_namer0   r   r!   s         r   GetObjectIamPolicyCloudApi.GetObjectIamPolicyB      . E
FFr   c                     [        S5      e)a  Sets IAM policy for specified Object.

Args:
  bucket_name: Bucket containing the object.
  object_name: Name of the object.
  policy: IAM Policy object.
  generation: Generation of the object to which the IAM policy will apply.
  provider: Cloud storage provider to connect to. If not present,
            class-wide default is used.

Raises:
  ArgumentException for errors during input validation.
  ServiceException for errors interacting with cloud storage providers.

Returns:
  Policy object of the object. May differ from input Policy.
z%SetObjectIamPolicy must be overloadedr   )r   r    ri   r)   r0   r   s         r   SetObjectIamPolicyCloudApi.SetObjectIamPolicy[  rl   r   c                     [        S5      e)a  Gets object metadata.

If decryption is supported by the implementing class, this function will
read decryption keys from configuration and appropriately retry requests to
encrypted objects with the correct key.

Args:
  bucket_name: Bucket containing the object.
  object_name: Object name.
  generation: Generation of the object to retrieve.
  provider: Cloud storage provider to connect to.  If not present,
            class-wide default is used.
  fields: If present, return only these Object metadata fields, for
          example, ['acl', 'updated'].

Raises:
  ArgumentException for errors during input validation.
  ServiceException for errors interacting with cloud storage providers.

Returns:
  Object object.
z$GetObjectMetadata must be overloadedr   rh   s         r   GetObjectMetadataCloudApi.GetObjectMetadatat  s    8 D
EEr   c	                     [        S5      e)a  Updates object metadata with patch semantics.

Args:
  bucket_name: Bucket containing the object.
  object_name: Object name for object.
  metadata: Object object defining metadata to be updated.
  canned_acl: Canned ACL to be set on the object.
  generation: Generation (or version) of the object to update.
  preconditions: Preconditions for the request.
  provider: Cloud storage provider to connect to.  If not present,
            class-wide default is used.
  fields: If present, return only these Object metadata fields.

Raises:
  ArgumentException for errors during input validation.
  ServiceException for errors interacting with cloud storage providers.

Returns:
  Updated object metadata.
z&PatchObjectMetadata must be overloadedr   )	r   r    ri   r;   r<   r0   r>   r   r!   s	            r   PatchObjectMetadataCloudApi.PatchObjectMetadata  s    : F
GGr   c                        \ rS rSrSrSrSrSrg)CloudApi.DownloadStrategyi  z,Enum class for specifying download strategy.oneshot	resumablerO   N)rP   rQ   rR   rS   rT   ONE_SHOT	RESUMABLErW   rO   r   r   DownloadStrategyrw     s    6HIr   r|   Fc                     [        S5      e)ax  Gets object data.

Args:
  bucket_name: Bucket containing the object.
  object_name: Object name.
  download_stream: Stream to send the object data to.
  provider: Cloud storage provider to connect to.  If not present,
            class-wide default is used.
  generation: Generation of the object to retrieve.
  object_size: Total size of the object being downloaded.
  compressed_encoding: If true, object is stored with a compressed encoding.
  download_strategy: Cloud API download strategy to use for download.
  start_byte: Starting point for download (for resumable downloads and
              range requests). Can be set to negative to request a range
              of bytes (python equivalent of [:-3])
  end_byte: Ending byte number, inclusive, for download (for range
            requests). If None, download the rest of the object.
  progress_callback: Optional callback function for progress notifications.
                     Receives calls with arguments
                     (bytes_transferred, total_size).
  serialization_data: Implementation-specific JSON string of a dict
                      containing serialization information for the download.
  digesters: Dict of {string : digester}, where string is a name of a hash
             algorithm, and digester is a validation digester that supports
             update(bytes) and digest() using that algorithm.
             Implementation can set the digester value to None to indicate
             bytes were not successfully digested on-the-fly.
  decryption_tuple: Optional utils.encryption_helper.CryptoKeyWrapper for
                    decrypting an encrypted object.

Raises:
  ArgumentException for errors during input validation.
  ServiceException for errors interacting with cloud storage providers.

Returns:
  Content-encoding string if it was detected that the server sent an encoded
  object during transfer, None otherwise.
z!GetObjectMedia must be overloadedr   )r   r    ri   download_streamr   r0   object_sizecompressed_encodingdownload_strategy
start_byteend_byteprogress_callbackserialization_data	digestersdecryption_tuples                  r   GetObjectMediaCloudApi.GetObjectMedia  s    j A
BBr   c                     [        S5      e)al  Uploads object data and metadata.

Args:
  upload_stream: Seekable stream of object data.
  object_metadata: Object metadata for new object.  Must include bucket
                   and object name.
  canned_acl: Optional canned ACL to apply to object. Overrides ACL set
              in object_metadata.
  size: Optional object size.
  preconditions: Preconditions for the request.
  progress_callback: Optional callback function for progress notifications.
                     Receives calls with arguments
                     (bytes_transferred, total_size).
  encryption_tuple: Optional utils.encryption_helper.CryptoKeyWrapper for
                    encrypting the uploaded object.
  provider: Cloud storage provider to connect to.  If not present,
            class-wide default is used.
  fields: If present, return only these Object metadata fields.
  gzip_encoded: Whether to use gzip transport encoding for the upload.

Raises:
  ArgumentException for errors during input validation.
  ServiceException for errors interacting with cloud storage providers.

Returns:
  Object object for newly created destination object.
zUploadObject must be overloadedr   )r   upload_streamobject_metadatar<   sizer>   r   encryption_tupler   r!   gzip_encodeds              r   UploadObjectCloudApi.UploadObject  s    L ?
@@r   c
                     [        S5      e)a  Uploads object data and metadata.

Args:
  upload_stream: Stream of object data. May not be seekable.
  object_metadata: Object metadata for new object.  Must include bucket
                   and object name.
  canned_acl: Optional canned ACL to apply to object. Overrides ACL set
              in object_metadata.
  preconditions: Preconditions for the request.
  progress_callback: Optional callback function for progress notifications.
                     Receives calls with arguments
                     (bytes_transferred, total_size), but fills in only
                     bytes_transferred.
  encryption_tuple: Optional utils.encryption_helper.CryptoKeyWrapper for
                    encrypting the uploaded object.
  provider: Cloud storage provider to connect to.  If not present,
            class-wide default is used.
  fields: If present, return only these Object metadata fields.
  gzip_encoded: Whether to use gzip transport encoding for the upload.

Raises:
  ArgumentException for errors during input validation.
  ServiceException for errors interacting with cloud storage providers.

Returns:
  Object object for newly created destination object.
z(UploadObjectStreaming must be overloadedr   )
r   r   r   r<   r>   r   r   r   r!   r   s
             r   UploadObjectStreamingCloudApi.UploadObjectStreaming  s    J H
IIr   c                     [        S5      e)ae  Uploads object data and metadata using a resumable upload strategy.

Args:
  upload_stream: Seekable stream of object data.
  object_metadata: Object metadata for new object.  Must include bucket
                   and object name.
  canned_acl: Optional canned ACL to apply to object. Overrides ACL set
              in object_metadata.
  size: Total size of the object.
  preconditions: Preconditions for the request.
  serialization_data: Dict of {'url' : UploadURL} allowing for uploads to
                      be resumed.
  tracker_callback: Callback function taking a upload URL string.
                    Guaranteed to be called when the implementation gets an
                    upload URL, allowing the caller to resume the upload
                    across process breaks by saving the upload URL in
                    a tracker file.
  progress_callback: Optional callback function for progress notifications.
                     Receives calls with arguments
                     (bytes_transferred, total_size).
  encryption_tuple: Optional utils.encryption_helper.CryptoKeyWrapper for
                    encrypting the uploaded object.
  provider: Cloud storage provider to connect to.  If not present,
            class-wide default is used.
  fields: If present, return only these Object metadata fields when the
          upload is complete.
  gzip_encoded: Whether to use gzip transport encoding for the upload.

Raises:
  ArgumentException for errors during input validation.
  ServiceException for errors interacting with cloud storage providers.

Returns:
  Object object for newly created destination object.
z(UploadObjectResumable must be overloadedr   )r   r   r   r<   r   r>   r   tracker_callbackr   r   r   r!   r   s                r   UploadObjectResumableCloudApi.UploadObjectResumable>  s    ` H
IIr   c                     [        S5      e)a7  Copies an object in the cloud.

Args:
  src_obj_metadata: Object metadata for source object.  Must include
                    bucket name, object name, and etag.
  dst_obj_metadata: Object metadata for new object.  Must include bucket
                    and object name.
  src_generation: Generation of the source object to copy.
  canned_acl: Optional canned ACL to apply to destination object. Overrides
              ACL set in dst_obj_metadata.
  preconditions: Destination object preconditions for the request.
  progress_callback: Optional callback function for progress notifications.
                     Receives calls with arguments
                     (bytes_transferred, total_size).
  max_bytes_per_call: Integer describing maximum number of bytes
                      to rewrite per service call.
  encryption_tuple: Optional utils.encryption_helper.CryptoKeyWrapper for
                    encrypting the destination object.
  decryption_tuple: Optional utils.encryption_helper.CryptoKeyWrapper for
                    decrypting the source object. If supplied without
                    encryption_tuple, destination object will be written
                    without customer-supplied encryption.
  provider: Cloud storage provider to connect to.  If not present,
            class-wide default is used.
  fields: If present, return only these Object metadata fields.

Raises:
  ArgumentException for errors during input validation.
  ServiceException for errors interacting with cloud storage providers.

Returns:
  Object object for newly created destination object.
zCopyObject must be overloadedr   )r   src_obj_metadatadst_obj_metadatasrc_generationr<   r>   r   max_bytes_per_callr   r   r   r!   s               r   
CopyObjectCloudApi.CopyObjectr  s    Z =
>>r   c                     [        S5      e)ah  Composes an object in the cloud.

Args:
  src_objs_metadata: List of ComposeRequest.SourceObjectsValueListEntries
                     specifying the objects to compose.
  dst_obj_metadata: Metadata for the destination object including bucket
                    and object name.
  preconditions: Destination object preconditions for the request.
  encryption_tuple: Optional utils.encryption_helper.CryptoKeyWrapper for
                    decrypting source objects and encrypting the destination
                    object.
  provider: Cloud storage provider to connect to.  If not present,
            class-wide default is used.
  fields: If present, return only these Object metadata fields.

Raises:
  ArgumentException for errors during input validation.
  ServiceException for errors interacting with cloud storage providers.

Returns:
  Composed object metadata.
z ComposeObject must be overloadedr   )r   src_objs_metadatar   r>   r   r   r!   s          r   ComposeObjectCloudApi.ComposeObject  s    : @
AAr   c                     [        S5      e)a  Deletes an object.

Args:
  bucket_name: Name of the containing bucket.
  object_name: Name of the object to delete.
  preconditions: Preconditions for the request.
  generation: Generation (or version) of the object to delete; if None,
              deletes the live object.
  provider: Cloud storage provider to connect to.  If not present,
            class-wide default is used.

Raises:
  ArgumentException for errors during input validation.
  ServiceException for errors interacting with cloud storage providers.

Returns:
  None.
zDeleteObject must be overloadedr   )r   r    ri   r>   r0   r   s         r   DeleteObjectCloudApi.DeleteObject  s    0 ?
@@r   c                     [        S5      e)a  Creates a notification subscription for changes to objects in a bucket.

Args:
  bucket_name: Bucket containing the objects.
  address: Address to which to send notifications.
  channel_id: Unique ID string for the channel.
  token: If present, token string is delivered with each notification.
  provider: Cloud storage provider to connect to.  If not present,
            class-wide default is used.
  fields: If present, return only these Channel metadata fields.

Raises:
  ArgumentException for errors during input validation.
  ServiceException for errors interacting with cloud storage providers.

Returns:
  Channel object describing the notification subscription.
zWatchBucket must be overloadedr   )r   r    address
channel_idtokenr   r!   s          r   WatchBucketCloudApi.WatchBucket  s    2 >
??r   c                     [        S5      e)a  Stops a notification channel.

Args:
  channel_id: Unique ID string for the channel.
  resource_id: Version-agnostic ID string for the channel.
  provider: Cloud storage provider to connect to.  If not present,
            class-wide default is used.

Raises:
  ArgumentException for errors during input validation.
  ServiceException for errors interacting with cloud storage providers.

Returns:
  None.
zStopChannel must be overloadedr   )r   r   resource_idr   s       r   StopChannelCloudApi.StopChannel  s      >
??r   c                     [        S5      e)aj  Lists object change notifications for a bucket.

Args:
  bucket_name: Bucket containing the objects
  provider: Cloud storage provider to connect to.  If not present,
            class-wide default is used.

Raises:
  ArgumentException for errors during input validation.
  ServiceException for errors interacting with cloud storage providers.

Returns:
  None.
zListChannels must be overloadedr   r   r    r   s      r   ListChannelsCloudApi.ListChannels  s     ?
@@r   c                     [        S5      e)ap  Get the GCS-owned service account representing this project.

Args:
  project_number: the project in question.
  provider: Cloud storage provider to connect to.  If not present,
            class-wide default is used.

Raises:
  ServiceException for errors interacting with cloud storage providers.

Returns:
  Service account object (with email_address string field)
z+GetProjectServiceAccount must be overloadedr   )r   project_numberr   s      r   GetProjectServiceAccount!CloudApi.GetProjectServiceAccount  s     K
LLr   c                     [        S5      e)a  Creates a new notification with the specified parameters.

Args:
  bucket_name: (Required) Name of the bucket.
  pubsub_topic: (Required) Cloud Pub/Sub topic to which to publish.
  payload_format: (Required) payload format, must be 'JSON' or 'NONE'.
  event_types: (Opt) List of event type filters, e.g. 'OBJECT_FINALIZE'.
  custom_attributes: (Opt) Dictionary of custom attributes.
  object_name_prefix: (Opt) Filter on object name.
  provider: Cloud storage provider to connect to.  If not present,
            class-wide default is used.

Raises:
  ArgumentException for errors during input validation.
  ServiceException for errors interacting with cloud storage providers.

Returns:
  Notification object describing new notificationConfig
z+CreateNotificationConfig must be overloadedr   )r   r    pubsub_topicpayload_formatevent_typescustom_attributesobject_name_prefixr   s           r   CreateNotificationConfig!CloudApi.CreateNotificationConfig(  s    6 K
LLr   c                     [        S5      e)a  Deletes a notification.

Args:
  bucket_name: (Required) Name of the bucket.
  notification: (Required) Integer name of the notification.
  provider: Cloud storage provider to connect to.  If not present,
            class-wide default is used.

Raises:
  ArgumentException for errors during input validation.
  ServiceException for errors interacting with cloud storage providers.

Returns:
  None
z+DeleteNotificationConfig must be overloadedr   )r   r    notificationr   s       r   DeleteNotificationConfig!CloudApi.DeleteNotificationConfigE  s      K
LLr   c                     [        S5      e)ao  Lists notification configs in a bucket.

Args:
  bucket_name: Name of the bucket.
  provider: Cloud storage provider to connect to.  If not present,
            class-wide default is used.

Raises:
  ArgumentException for errors during input validation.
  ServiceException for errors interacting with cloud storage providers.

Yields:
  List of notification objects.
z)ListNotificationConfig must be overloadedr   r   s      r   ListNotificationConfigs CloudApi.ListNotificationConfigsW  s     I
JJr   c                     [        S5      e)a  Creates a new HMAC key for the specified service account.

Args:
  project_id: Project ID owning the service account for which the key is to
              be created.
  service_account_email: Email address of the service account for which to
                          create a key.

Raises:
    NotImplementedError: not implemented TODO(tuckerkirven)

Returns
  The key metadata and the secret key material.
z CreateHmacKey must be overloadedr   )r   r7   service_account_emails      r   CreateHmacKeyCloudApi.CreateHmacKeyh  s     @
AAr   c                     [        S5      e)zDeletes an HMAC key.

Args:
  project_id: Project ID owning the requested key.
  access_id: Name of the HMAC key to be deleted.

Raises:
    NotImplementedError: not implemented TODO(tuckerkirven)
z DeleteHmacKey must be overloadedr   r   r7   	access_ids      r   DeleteHmacKeyCloudApi.DeleteHmacKeyy  s     @
AAr   c                     [        S5      e)a1  Retrieves an HMAC key's metadata.

Args:
  project_id: Project ID owning the service account of the requested key.
  access_id: Name of the HMAC key for which the metadata is being requested.

Raises:
    NotImplementedError: not implemented TODO(tuckerkirven)

Returns:
  Metadata for the specified key.
zGetHmacKey must be overloadedr   r   s      r   
GetHmacKeyCloudApi.GetHmacKey  s     =
>>r   c                     [        S5      e)a  Lists HMAC keys matching the criteria.

Args:
    project_id: Name of the project from which to list HMAC keys.
    service_account_email: If present, only keys for the given service
                           account will be returned.
    show_deleted_keys: If set, show keys in the DELETED state.
Raises:
    NotImplementedError: not implemented TODO(tuckerkirven)

Yields:
  List of HMAC key metadata objects.
zListHmacKeys must be overloadedr   )r   r7   r   show_deleted_keyss       r   ListHmacKeysCloudApi.ListHmacKeys  s    " ?
@@r   c                     [        S5      e)a  Updates the state of an HMAC key.

Args:
  project_id: Project ID owning the service account of the updated key.
  access_id: Name of the HMAC key being updated.
  state: The state to which the key should be updated.
  etag: None or a string matching the key's etag to ensure the appropriate
        version of the key is updated.

Raises:
    NotImplementedError: not implemented TODO(tuckerkirven)

Returns:
    The updated key metadata.
z UpdateHmacKey must be overloadedr   )r   r7   r   stateetags        r   UpdateHmacKeyCloudApi.UpdateHmacKey  s      @
AAr   )	r
   r   r   r   r   r   r   r   r   )Nr   NNNNNNN)NNN)NNNNN)NNNN)NNNNNNNF)NNNNNNF)
NNNNNNNNNF)	NNNNNNNNN)F).rP   rQ   rR   rS   rT   r   r   r"   r%   r*   r4   r8   r?   rC   rF   rI   rM   rX   ra   re   rj   rn   rq   rt   r|   rz   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rW   rO   r   r   r   r      sB      $ "%HI>&G$G$<8@: "!% $@:H& #  A2A$V 
   #!@L %)"& $G: %)"&G8 $(!%#FD &*%)(,#'!%H>  # $!%).'7'@'@ !"'+(,#&*5Ct #!%%)$(  %&AV (,*..2-1%)#').%JT (,!%*./3-1.2-1%)#').0Jn !% ##'$("&"&-?d #'%)!BD "&" A< @6@$A"M( ,01526(,M:M$K"B"
B?$ &+A&Br   r   c                   "    \ rS rSrSrSS jrSrg)Preconditionsi  zGPreconditions class for specifying preconditions to cloud API requests.Nc                     Xl         X l        g)a0  Instantiates a Preconditions object.

Args:
  gen_match: Perform request only if generation of target object
             matches the given integer. Ignored for bucket requests.
  meta_gen_match: Perform request only if metageneration of target
                  object/bucket matches the given integer.
N	gen_matchmeta_gen_match)r   r   r   s      r   r   Preconditions.__init__  s     N(r   r   r   r`   rO   r   r   r   r     s
    O
)r   r   c                       \ rS rSrSrSrg)EncryptionExceptioni  z@Exception raised when an encrypted resource cannot be decrypted.rO   NrP   rQ   rR   rS   rT   rW   rO   r   r   r   r     s    Hr   r   c                   *    \ rS rSrSrS rS rS rSrg)ArgumentExceptioni  zException raised when arguments to a Cloud API method are invalid.

This exception is never raised as a result of a failed call to a cloud
storage provider.
c                 :    [         R                  U 5        Xl        g r   )	Exceptionr   reason)r   r   s     r   r   ArgumentException.__init__  s    tKr   c                     [        U 5      $ r   strr   s    r   __repr__ArgumentException.__repr__      t9r   c                 P    U R                   R                  < SU R                  < 3$ )Nz: )	__class__rP   r   r   s    r   __str__ArgumentException.__str__  s    ~~..<<r   )r   N	rP   rQ   rR   rS   rT   r   r   r   rW   rO   r   r   r   r     s    =r   r   c                       \ rS rSrSrSrg)ProjectIdExceptioni  zHException raised when a Project ID argument is required but not present.rO   Nr   rO   r   r   r   r         Pr   r   c                   .    \ rS rSrSrSS jrS rS rSrg)	ServiceExceptioni  zException raised when a cloud storage provider request fails.

This exception is raised only as a result of a failed remote call.
Nc                 R    [         R                  U 5        Xl        X l        X0l        g r   )r   r   r   statusbody)r   r   r   r  s       r   r   ServiceException.__init__  s    tKKIr   c                     [        U 5      $ r   r   r   s    r   r   ServiceException.__repr__  r   r   c                     SU R                   R                  -  nU R                  (       a  USU R                  -  -  nUSU R                  -  -  nU R                  (       a  USU R                  -  -  nU$ )Nz%s:z %sz
%s)r   rP   r   r   r  )r   messages     r   r   ServiceException.__str__  sb    dnn---G{{$$gut{{""Gyy$))##gNr   )r  r   r   r   r   rO   r   r   r   r     s    
r   r   c                       \ rS rSrSrSrg)RetryableServiceExceptioni  z)Exception class for retryable exceptions.rO   Nr   rO   r   r   r	  r	    s    1r   r	  c                       \ rS rSrSrSrg)ResumableDownloadExceptioni  z>Exception raised for res. downloads that can be retried later.rO   Nr   rO   r   r   r  r        Fr   r  c                       \ rS rSrSrSrg)ResumableUploadExceptioni  zHException raised for res. uploads that can be retried w/ same upload ID.rO   Nr   rO   r   r   r  r    r   r   r  c                       \ rS rSrSrSrg)!ResumableUploadStartOverExceptioni	  zGException raised for res. uploads that can be retried w/ new upload ID.rO   Nr   rO   r   r   r  r  	  s    Or   r  c                       \ rS rSrSrSrg)ResumableUploadAbortExceptioni  zDException raised for resumable uploads that cannot be retried later.rO   Nr   rO   r   r   r  r    s    Lr   r  c                       \ rS rSrSrSrg)AuthenticationExceptioni  z>Exception raised for errors during the authentication process.rO   Nr   rO   r   r   r  r    r  r   r  c                       \ rS rSrSrSrg)PreconditionExceptioni  z+Exception raised for precondition failures.rO   Nr   rO   r   r   r  r    s    3r   r  c                       \ rS rSrSrSrg)NotFoundExceptioni  z4Exception raised when a resource is not found (404).rO   Nr   rO   r   r   r  r    s    <r   r  c                   0   ^  \ rS rSrSrSU 4S jjrSrU =r$ )BucketNotFoundExceptioni  z;Exception raised when a bucket resource is not found (404).c                 8   > [         [        U ]  UUUS9  X l        g )N)r   r  )superr  r   r    )r   r   r    r   r  r   s        r   r    BucketNotFoundException.__init__   s(    	
!41&9?7; 2 = #r   )r    r   )rP   rQ   rR   rS   rT   r   rW   __classcell__)r   s   @r   r  r    s    C# #r   r  c                       \ rS rSrSrSrg)NotEmptyExceptioni'  z=Exception raised when trying to delete a bucket is not empty.rO   Nr   rO   r   r   r   r   '  s    Er   r   c                       \ rS rSrSrSrg)BadRequestExceptioni+  zException raised for malformed requests.

Where it is possible to detect invalid arguments prior to sending them
to the server, an ArgumentException should be raised instead.
rO   Nr   rO   r   r   r"  r"  +      r   r"  c                       \ rS rSrSrSrg)AccessDeniedExceptioni3  zException raised  when authenticated user has insufficient access rights.

This is raised when the authentication process succeeded but the
authenticated user does not have access rights to the requested resource.
rO   Nr   rO   r   r   r%  r%  3  r#  r   r%  c                       \ rS rSrSrSrg) PublishPermissionDeniedExceptioni;  zException raised when bucket does not have publish permission to a topic.

This is raised when a custom attempts to set up a notification config to a
Cloud Pub/Sub topic, but their GCS bucket does not have permission to
publish to the specified topic.
rO   Nr   rO   r   r   r'  r'  ;  s    r   r'  N)rT   
__future__r   r   r   rM   r   r   r   r   r   r   r   r	  r  r  r  r  r  r  r  r  r   r"  r%  r'  rO   r   r   <module>r)     s   ? &  'aBv aBH)F ) I) I=	 =$Q* Qy 22 0 2G!: GQ8 QP(A PM$4 MG. G4, 4=( =#/ #F( F* , '7 r   