
    ޣ                        d Z ddlmZ ddlmZ ddlmZ  G d de      Z G d de      Z G d	 d
e      Z	 G d de      Z
 G d de
      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d d e      Z G d! d"e      Z G d# d$e      Z G d% d&e      Z G d' d(e      Z G d) d*e      Zy+),z8Gsutil API for interacting with cloud storage providers.    )absolute_import)division)unicode_literalsc                   ,   e Zd ZdZ	 	 	 	 	 	 d.dZd Zd/dZd/dZd0dZd	 Z	d1d
Z
	 	 	 	 	 d2dZd0dZ	 	 	 	 d3dZd/dZ G d de      Z G d de      Z	 	 	 	 	 d2dZ	 	 	 d1dZ	 	 d/dZ	 	 	 d1dZ	 	 	 	 	 d2dZ G d de      Zddddej0                  ddddddfdZ	 	 	 	 	 	 	 	 d4dZ	 	 	 	 	 	 	 d5dZ	 	 	 	 	 	 	 	 	 	 d6dZ	 	 	 	 	 	 	 	 	 d7dZ	 	 	 	 d3d Z	 	 	 d1d!Z	 	 	 d1d"Z d0d#Z!d0d$Z"d0d%Z#	 	 	 	 d3d&Z$d0d'Z%d0d(Z&d) Z'd* Z(d+ Z)	 d8d,Z*d- Z+y)9CloudApiay  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
                     || _         || _        || _        || _        || _        || _        || _        || _        |	| _        y)aF  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__zCloudApi.__init__   sI    4 %=D!DK$DDMDJ$D"D,D$D    c                     t        d      )z%Returns the service account email id.z'GetServiceAccountId must be overridden.NotImplementedErrorr   s    r   GetServiceAccountIdzCloudApi.GetServiceAccountIdC   s    
G
HHr   c                     t        d      )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   	GetBucketzCloudApi.GetBucketG   s    " <
==r   c                     t        d      )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   GetBucketIamPolicyzCloudApi.GetBucketIamPolicyZ         E
FFr   c                     t        d      )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   SetBucketIamPolicyzCloudApi.SetBucketIamPolicyl   r"   r   c	                     t        d      )aW  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   SignUrlzCloudApi.SignUrl~   s    4 :
;;r   c                     t        d      )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   ListBucketszCloudApi.ListBuckets   s    0 >
??r   c                     t        d      )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   PatchBucketzCloudApi.PatchBucket   s    6 >
??r   c                     t        d      )a  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   LockRetentionPolicyzCloudApi.LockRetentionPolicy   s     F
GGr   c                     t        d      )a  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   r0   r3   r   r   s         r   CreateBucketzCloudApi.CreateBucket   s    . ?
@@r   c                     t        d      )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   r6   r   s       r   DeleteBucketzCloudApi.DeleteBucket   s      ?
@@r   c                       e Zd ZdZdZdZy)CloudApi.CsObjectOrPrefixTypez1Enum class for describing CsObjectOrPrefix types.objectprefixN)__name__
__module____qualname____doc__OBJECTPREFIX r   r   CsObjectOrPrefixTyper@     s    ;FFr   rJ   c                       e Zd ZdZd Zy)CloudApi.CsObjectOrPrefixz(Container class for ListObjects results.c                      || _         || _        y)zStores a ListObjects result.

      Args:
        data: Root object, either an apitools Object or a string Prefix.
        datatype: CsObjectOrPrefixType of data.
      N)datadatatype)r   rN   rO   s      r   r   z"CloudApi.CsObjectOrPrefix.__init__  s     didmr   NrC   rD   rE   rF   r   rI   r   r   CsObjectOrPrefixrL     s
    2r   rQ   c                     t        d      )a  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   rB   	delimiterall_versionsr   r   s          r   ListObjectszCloudApi.ListObjects  s    B >
??r   c                     t        d      )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_namer*   r   r   s         r   GetObjectIamPolicyzCloudApi.GetObjectIamPolicyB      . E
FFr   c                     t        d      )aS  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   rX   r$   r*   r   s         r   SetObjectIamPolicyzCloudApi.SetObjectIamPolicy[  rZ   r   c                     t        d      )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   rW   s         r   GetObjectMetadatazCloudApi.GetObjectMetadatat  s    8 D
EEr   c	                     t        d      )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   rX   r3   r4   r*   r6   r   r   s	            r   PatchObjectMetadatazCloudApi.PatchObjectMetadata  s    : F
GGr   c                       e Zd ZdZdZdZy)CloudApi.DownloadStrategyz,Enum class for specifying download strategy.oneshot	resumableN)rC   rD   rE   rF   ONE_SHOT	RESUMABLErI   r   r   DownloadStrategyrb     s    6HIr   rg   Fc                     t        d      )a   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   rX   download_streamr   r*   object_sizecompressed_encodingdownload_strategy
start_byteend_byteprogress_callbackserialization_data	digestersdecryption_tuples                  r   GetObjectMediazCloudApi.GetObjectMedia  s    j A
BBr   c                     t        d      )a  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_metadatar4   sizer6   ro   encryption_tupler   r   gzip_encodeds              r   UploadObjectzCloudApi.UploadObject  s    L ?
@@r   c
                     t        d      )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   ru   rv   r4   r6   ro   rx   r   r   ry   s
             r   UploadObjectStreamingzCloudApi.UploadObjectStreaming  s    J H
IIr   c                     t        d      )a  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   ru   rv   r4   rw   r6   rp   tracker_callbackro   rx   r   r   ry   s                r   UploadObjectResumablezCloudApi.UploadObjectResumable>  s    ` H
IIr   c                     t        d      )a  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_generationr4   r6   ro   max_bytes_per_callrx   rr   r   r   s               r   
CopyObjectzCloudApi.CopyObjectr  s    Z =
>>r   c                     t        d      )a  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   r6   rx   r   r   s          r   ComposeObjectzCloudApi.ComposeObject  s    : @
AAr   c                     t        d      )aR  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   rX   r6   r*   r   s         r   DeleteObjectzCloudApi.DeleteObject  s    0 ?
@@r   c                     t        d      )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   WatchBucketzCloudApi.WatchBucket  s    2 >
??r   c                     t        d      )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   StopChannelzCloudApi.StopChannel  s      >
??r   c                     t        d      )a  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   ListChannelszCloudApi.ListChannels  s     ?
@@r   c                     t        d      )a  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   GetProjectServiceAccountz!CloudApi.GetProjectServiceAccount  s     K
LLr   c                     t        d      )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   CreateNotificationConfigz!CloudApi.CreateNotificationConfig(  s    6 K
LLr   c                     t        d      )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   DeleteNotificationConfigz!CloudApi.DeleteNotificationConfigE  s      K
LLr   c                     t        d      )a  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   ListNotificationConfigsz CloudApi.ListNotificationConfigsW  s     I
JJr   c                     t        d      )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   r0   service_account_emails      r   CreateHmacKeyzCloudApi.CreateHmacKeyh  s     @
AAr   c                     t        d      )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   r0   	access_ids      r   DeleteHmacKeyzCloudApi.DeleteHmacKeyy  s     @
AAr   c                     t        d      )aQ  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   
GetHmacKeyzCloudApi.GetHmacKey  s     =
>>r   c                     t        d      )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   r0   r   show_deleted_keyss       r   ListHmacKeyszCloudApi.ListHmacKeys  s    " ?
@@r   c                     t        d      )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   r0   r   stateetags        r   UpdateHmacKeyzCloudApi.UpdateHmacKey  s      @
AAr   )Nr   NNNNNNN)NNN)NNNNN)NNNN)NNNNNNNF)NNNNNNF)
NNNNNNNNNF)	NNNNNNNNN)F),rC   rD   rE   rF   r   r   r   r!   r%   r.   r1   r7   r:   r<   r>   rA   rJ   rQ   rU   rY   r\   r^   r`   rg   re   rs   rz   r|   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rI   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                       e Zd ZdZddZy)PreconditionszGPreconditions class for specifying preconditions to cloud API requests.Nc                      || _         || _        y)aH  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   zPreconditions.__init__  s     DN(Dr   r   rP   rI   r   r   r   r     s
    O
)r   r   c                       e Zd ZdZy)EncryptionExceptionz@Exception raised when an encrypted resource cannot be decrypted.NrC   rD   rE   rF   rI   r   r   r   r     s    Hr   r   c                   "    e Zd ZdZd Zd Zd Zy)ArgumentExceptionzException 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                 <    t         j                  |        || _        y r   )	Exceptionr   reason)r   r   s     r   r   zArgumentException.__init__  s    tDKr   c                     t        |       S r   strr   s    r   __repr__zArgumentException.__repr__      t9r   c                 L    | j                   j                  d| j                  S )Nz: )	__class__rC   r   r   s    r   __str__zArgumentException.__str__  s    ~~..<<r   NrC   rD   rE   rF   r   r   r   rI   r   r   r   r     s    =r   r   c                       e Zd ZdZy)ProjectIdExceptionzHException raised when a Project ID argument is required but not present.Nr   rI   r   r   r   r         Pr   r   c                   $    e Zd ZdZddZd Zd Zy)ServiceExceptionzException raised when a cloud storage provider request fails.

    This exception is raised only as a result of a failed remote call.
  Nc                 X    t         j                  |        || _        || _        || _        y r   )r   r   r   statusbody)r   r   r   r   s       r   r   zServiceException.__init__  s%    tDKDKDIr   c                     t        |       S r   r   r   s    r   r   zServiceException.__repr__  r   r   c                     d| j                   j                  z  }| j                  r|d| j                  z  z  }|d| j                  z  z  }| j                  r|d| j                  z  z  }|S )Nz%s:z %sz
%s)r   rC   r   r   r   )r   messages     r   r   zServiceException.__str__  sb    dnn---G{{$$gut{{""Gyy$))##gNr   r   r   rI   r   r   r   r     s    
r   r   c                       e Zd ZdZy)RetryableServiceExceptionz)Exception class for retryable exceptions.Nr   rI   r   r   r   r     s    1r   r   c                       e Zd ZdZy)ResumableDownloadExceptionz>Exception raised for res. downloads that can be retried later.Nr   rI   r   r   r   r         Fr   r   c                       e Zd ZdZy)ResumableUploadExceptionzHException raised for res. uploads that can be retried w/ same upload ID.Nr   rI   r   r   r   r     r   r   r   c                       e Zd ZdZy)!ResumableUploadStartOverExceptionzGException raised for res. uploads that can be retried w/ new upload ID.Nr   rI   r   r   r   r   	  s    Or   r   c                       e Zd ZdZy)ResumableUploadAbortExceptionzDException raised for resumable uploads that cannot be retried later.Nr   rI   r   r   r   r     s    Lr   r   c                       e Zd ZdZy)AuthenticationExceptionz>Exception raised for errors during the authentication process.Nr   rI   r   r   r   r     r   r   r   c                       e Zd ZdZy)PreconditionExceptionz+Exception raised for precondition failures.Nr   rI   r   r   r   r     s    3r   r   c                       e Zd ZdZy)NotFoundExceptionz4Exception raised when a resource is not found (404).Nr   rI   r   r   r   r     s    <r   r   c                   $     e Zd ZdZd fd	Z xZS )BucketNotFoundExceptionz;Exception raised when a bucket resource is not found (404).c                 @    t         t        |   |||       || _        y )N)r   r   )superr   r   r   )r   r   r   r   r   r   s        r   r   z BucketNotFoundException.__init__   s*    	
!41&9?7; 2 = #Dr   r   )rC   rD   rE   rF   r   __classcell__)r   s   @r   r   r     s    C# #r   r   c                       e Zd ZdZy)NotEmptyExceptionz=Exception raised when trying to delete a bucket is not empty.Nr   rI   r   r   r   r   '  s    Er   r   c                       e Zd ZdZy)BadRequestExceptionzException 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.
  Nr   rI   r   r   r   r   +      r   r   c                       e Zd ZdZy)AccessDeniedExceptionzException 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.
  Nr   rI   r   r   r   r   3  r   r   r   c                       e Zd ZdZy) PublishPermissionDeniedExceptiona
  Exception 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.
  Nr   rI   r   r   r   r   ;  s    r   r   N)rF   
__future__r   r   r   rA   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rI   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   