
    >i                         d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 	 ddlmc mZ dd	lmZmZ dd
lmZ dZ ee      ZdZ G d de
      Zy# e$ r dZY !w xY w)z0The Azure Storage Block Blob backend for Celery.    )cached_property)bytes_to_str)ImproperlyConfigured)
get_logger   )KeyValueStoreBackendN)ResourceExistsErrorResourceNotFoundError)BlobServiceClient)AzureBlockBlobBackendzazureblockblob://c                   l     e Zd ZdZ	 	 d
 fd	Zeefd       Zed        Z	d Z
d Zd Zd Zdd	Z xZS )r   z,Azure Storage Block Blob backend for Celery.c                 j   t        |   |i | t        t        j                  dk  rt	        d      | j
                  j                  }| j                  |      | _        |xs |d   | _	        |j                  dd      | _        |j                  dd      | _        |j                  dd	      | _        y )
N12zWYou need to install the azure-storage-blob v12 library touse the AzureBlockBlob backendazureblockblob_container_nameazureblockblob_base_path !azureblockblob_connection_timeout   azureblockblob_read_timeoutx   )super__init__azurestorage__version__r   appconf
_parse_url_connection_string_container_nameget	base_path_connection_timeout_read_timeout)selfurlcontainer_nameargskwargsr   	__class__s         z/var/www/html/wine-match-dev/backend/winematch-backend/venv/lib/python3.12/site-packages/celery/backends/azureblockblob.pyr   zAzureBlockBlobBackend.__init__   s    
 	$)&)<#;#;d#B&12 2 xx}}"&//#"6  201 	 "<bA#'88/$
  "XX&CSI    c                 <    |t        |      d  }|st        d      |S )NzInvalid URL)lenr   )clsr%   prefixconnection_strings       r*   r   z AzureBlockBlobBackend._parse_url4   s'    F- &}55  r+   c                 4   t        j                  | j                  | j                  | j                        }	 |j                  | j                         d| j                   d}t        j                  |       |S # t        $ r d| j                   d}Y 2w xY w)zReturn the Azure Storage Blob service client.

        If this is the first call to the property, the client is created and
        the container is created if it doesn't yet exist.

        )connection_timeoutread_timeout)namezContainer created with name .zContainer with name z* already.exists. This will not be created.)
r   from_connection_stringr   r"   r#   create_containerr   r	   LOGGERinfo)r$   clientmsgs      r*   _blob_service_clientz*AzureBlockBlobBackend._blob_service_client<   s     #99###77++
	4##)=)=#>01E1E0FaHC 	C # 	4()=)=(> ?4 4C	4s   ,A; ;BBc                 <   t        |      }t        j                  d| j                  |       | j                  j                  | j                  | j                   |       }	 |j                         j                         j                         S # t        $ r Y yw xY w)zwRead the value stored at the given key.

        Args:
              key: The key for which to read the value.
        zGetting Azure Block Blob %s/%s	containerblobN)r   r8   debugr   r<   get_blob_clientr!   download_blobreadalldecoder
   r$   keyblob_clients      r*   r    zAzureBlockBlobBackend.getT   s     35t7K7KSQ//??**NN#C5) @ 

	,,.668??AA$ 		s   #+B 	BBc                     t        |      }t        j                  d| j                   d|        | j                  j                  | j                  | j                   |       }|j                  |d       y)zStore a value for a given key.

        Args:
              key: The key at which to store the value.
              value: The value to store.

        zCreating azure blob at /r>   T)	overwriteN)r   r8   rA   r   r<   rB   r!   upload_blob)r$   rG   valuerH   s       r*   setzAzureBlockBlobBackend.setg   sz     3.t/C/C.DAcUKL//??**NN#C5) @ 

 	6r+   c                 J    |D cg c]  }| j                  |       c}S c c}w )zqRead all the values for the provided keys.

        Args:
              keys: The list of keys to read.

        )r    )r$   keysrG   s      r*   mgetzAzureBlockBlobBackend.mgety   s      *..#...s    c                     t        |      }t        j                  d| j                   d|        | j                  j                  | j                  | j                   |       }|j                          y)zlDelete the value at a given key.

        Args:
              key: The key of the value to delete.

        zDeleting azure blob at rJ   r>   N)r   r8   rA   r   r<   rB   r!   delete_blobrF   s      r*   deletezAzureBlockBlobBackend.delete   ss     3.t/C/C.DAcUKL//??**NN#C5) @ 

 	!r+   c                     |rt          | j                   S | j                  j                  d      }d}|D cg c]  }|j                  |      r| dn| }}t          dj	                  |       S c c}w )N;zAccountKey=z**)"AZURE_BLOCK_BLOB_CONNECTION_PREFIXr   split
startswithjoin)r$   include_passwordconnection_string_partsaccount_key_prefixpart redacted_connection_string_partss         r*   as_urizAzureBlockBlobBackend.as_uri   s    56**+-
 #'"9"9"?"?"D* 0,
  *.9K)L!""%,
( ,
 22xx89:<	
,
s   A2)NN)F)__name__
__module____qualname____doc__r   classmethodrW   r   r   r<   r    rN   rQ   rT   r`   __classcell__)r)   s   @r*   r   r      sX    6  $J4 $F ! !  .&7$/""
r+   r   )rd   kombu.utilsr   kombu.utils.encodingr   celery.exceptionsr   celery.utils.logr   baser   azure.storage.blobstorager@   r   azure.core.exceptionsr	   r
   r   ImportError__all__ra   r8   rW   r    r+   r*   <module>rr      sd    6 ' - 2 ' &--P4 %	H	%8 "N
0 N
  Ls   A AA