
    g                    ~    d dl mZ d dlmZmZ d dlmZmZ ddlm	Z	 ddl
mZmZ ddlmZ dd	lmZ d
gZ G d d
      Zy)    )annotations)AnyOptional)HTTPStatusErrorResponse   )StorageApiError)CreateOrUpdateBucketOptionsRequestMethod)AsyncClient   )AsyncBucketAsyncStorageBucketAPIc                      e Zd ZdZddZ	 d	 	 	 	 	 	 	 ddZddZddZ	 	 d	 	 	 	 	 	 	 ddZ	 	 	 	 	 	 ddZ	dd	Z
dd
Zy)r   zfThis class abstracts access to the endpoint to the Get, List, Empty, and Delete operations on a bucketc                    || _         y N)_client)selfsessions     K/var/www/openai/venv/lib/python3.12/site-packages/storage3/_async/bucket.py__init__zAsyncStorageBucketAPI.__init__   s	        Nc                  K   	 | j                   j                  |||       d {   }|j                          |S 7 # t        $ r5}|j                  j                         }t        |d   |d   |d         d }~ww xY ww)Njsonmessageerror
statusCode)r   requestraise_for_statusr   responser   r	   )r   methodurlr   r!   excresps          r   _requestzAsyncStorageBucketAPI._request   s     	V!\\11&#D1IIH%%'
  J 	V<<$$&D!$y/4=$|BTUU	Vs1   A?!> <> A?> 	A<0A77A<<A?c                   K   | j                  dd       d{   }|j                         D cg c]  }t        di | c}S 7 +c c}w w)zHRetrieves the details of all storage buckets within an existing product.GET/bucketN r&   r   r   )r   resbuckets      r   list_bucketsz"AsyncStorageBucketAPI.list_buckets$   sF      MM%3347HHJ?J&%f%J?? 4?s    AAAAAAc                ~   K   | j                  dd|        d{   }|j                         }t        di |S 7 w)zRetrieves the details of an existing storage bucket.

        Parameters
        ----------
        id
            The unique identifier of the bucket you would like to retrieve.
        r(   /bucket/Nr*   r+   )r   idr,   r   s       r   
get_bucketz AsyncStorageBucketAPI.get_bucket*   s?      MM%8B499xxz"T"" :s   =; =c                   K   ||xs |d}|r |j                   di | | j                  dd|       d{   }|j                         S 7 w)a  Creates a new storage bucket.

        Parameters
        ----------
        id
            A unique identifier for the bucket you are creating.
        name
            A name for the bucket you are creating. If not passed, the id is used as the name as well.
        options
            Extra options to send while creating the bucket. Valid options are `public`, `file_size_limit` and
            `allowed_mime_types`.
        r1   namePOSTr)   r   Nr*   )updater&   r   )r   r1   r5   optionsr   r,   s         r   create_bucketz#AsyncStorageBucketAPI.create_bucket6   s^     $ ')$*"=DKK"'"MM " 
 

 xxz
s   5AAAc                z   K   ||d|}| j                  dd| |       d{   }|j                         S 7 w)a0  Update a storage bucket.

        Parameters
        ----------
        id
            The unique identifier of the bucket you would like to update.
        options
            The properties you want to update. Valid options are `public`, `file_size_limit` and
            `allowed_mime_types`.
        r4   PUTr0   r   Nr&   r   )r   r1   r8   r   r,   s        r   update_bucketz#AsyncStorageBucketAPI.update_bucketR   sF      "00MM%8B4tMDDxxz Es   ";9;c                n   K   | j                  dd| di        d{   }|j                         S 7 w)zRemoves all objects inside a single bucket.

        Parameters
        ----------
        id
            The unique identifier of the bucket you would like to empty.
        r6   r0   z/emptyr   Nr<   r   r1   r,   s      r   empty_bucketz"AsyncStorageBucketAPI.empty_bucketc   s:      MM&HRD*?bMIIxxz Js   535c                l   K   | j                  dd| i        d{   }|j                         S 7 w)a  Deletes an existing bucket. Note that you cannot delete buckets with existing objects inside. You must first
        `empty()` the bucket.

        Parameters
        ----------
        id
            The unique identifier of the bucket you would like to delete.
        DELETEr0   r   Nr<   r?   s      r   delete_bucketz#AsyncStorageBucketAPI.delete_bucketn   s7      MM(hrdO"MEExxz Fs   424)r   r   returnNoner   )r"   r   r#   strr   zOptional[dict[Any, Any]]rD   r   )rD   zlist[AsyncBucket])r1   rF   rD   r   )NN)r1   rF   r5   zOptional[str]r8   z%Optional[CreateOrUpdateBucketOptions]rD   dict[str, str])r1   rF   r8   r
   rD   rG   )r1   rF   rD   rG   )__name__
__module____qualname____doc__r   r&   r.   r2   r9   r=   r@   rC   r*   r   r   r   r      s    p *.	  '	
 
@
# #9=	  7	
 
8 ;	"	
r   N)
__future__r   typingr   r   httpxr   r   
exceptionsr	   typesr
   r   utilsr   file_apir   __all__r   r*   r   r   <module>rT      s.    "   + ( >  !"
#i ir   