
    `f                         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 n# e$ r dZY nw xY wdZ ee          ZdZ G d de
          ZdS )z0The Azure Storage Block Blob backend for Celery.    )cached_property)bytes_to_str)ImproperlyConfigured)
get_logger   )KeyValueStoreBackendN)ResourceExistsErrorResourceNotFoundError)BlobServiceClient)AzureBlockBlobBackendzazureblockblob://c                   x     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.Nc                     t                      j        |i | t          t          j        dk     rt	          d          | j        j        }|                     |          | _        |p|d         | _	        |
                    dd          | _        |
                    dd          | _        |
                    dd	          | _        d S )
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         P/var/www/html/env/lib/python3.11/site-packages/celery/backends/azureblockblob.pyr   zAzureBlockBlobBackend.__init__   s    
 	$)&)))<#;d#B#B&12 2 2 x}"&//#"6"6  201 	 "<bAA#'88/$
 $
  "XX&CSII    c                 V    |t          |          d          }|st          d          |S )NzInvalid URL)lenr   )clsr%   prefixconnection_strings       r*   r   z AzureBlockBlobBackend._parse_url4   s3    F-  	6&}555  r+   c                    t          j        | j        | j        | j                  }	 |                    | j                   d| j         d}n# t          $ r d| j         d}Y nw xY wt          	                    |           |S )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##7+
 
 
	4##)=#>>>H1EHHHCC" 	4 	4 	44)= 4 4 4CCC	4 	Cs   &A A'&A'c                 J   t          |          }t                              d| j        |           | j                            | j        | j         |           }	 |                                                                	                                S # t          $ r Y dS 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5t7KSQQQ/??*N)C)) @ 
 

	,,..6688??AAA$ 	 	 	44	s   7B 
B"!B"c                     t          |          }t                              d| j         d|            | j                            | j        | j         |           }|                    |d           dS )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   s     3Kt/CKKcKKLLL/??*N)C)) @ 
 

 	66666r+   c                        fd|D             S )zqRead all the values for the provided keys.

        Args:
              keys: The list of keys to read.

        c                 :    g | ]}                     |          S  )r    ).0rG   r$   s     r*   
<listcomp>z.AzureBlockBlobBackend.mget.<locals>.<listcomp>   s#    ...#...r+   rQ   )r$   keyss   ` r*   mgetzAzureBlockBlobBackend.mgety   s     /.......r+   c                     t          |          }t                              d| j         d|            | j                            | j        | j         |           }|                                 dS )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   s     3Kt/CKKcKKLLL/??*N)C)) @ 
 

 	!!!!!r+   Fc                     |rt            | j         S | j                            d          }dfd|D             }t            d                    |           S )N;zAccountKey=c                 H    g | ]}|                               r d n|S )z**)
startswith)rR   partaccount_key_prefixs     r*   rS   z0AzureBlockBlobBackend.as_uri.<locals>.<listcomp>   sO     ,
 ,
 ,
  *.9K)L)L !%%%%,
 ,
 ,
r+   )"AZURE_BLOCK_BLOB_CONNECTION_PREFIXr   splitjoin)r$   include_passwordconnection_string_parts redacted_connection_string_partsr^   s       @r*   as_urizAzureBlockBlobBackend.as_uri   s     	5 -*- -
 #'"9"?"?"D"D*,
 ,
 ,
 ,
 0,
 ,
 ,
( 2 <xx899< <	
r+   )NN)F)__name__
__module____qualname____doc__r   classmethodr_   r   r   r<   r    rN   rU   rX   re   __classcell__)r)   s   @r*   r   r      s        66  $J J J J J J4 $F ! ! ! [!   _.  &7 7 7$/ / /" " ""
 
 
 
 
 
 
 
r+   r   )ri   kombu.utilsr   kombu.utils.encodingr   celery.exceptionsr   celery.utils.logr   baser   azure.storage.blobstorager@   r   azure.core.exceptionsr	   r
   r   ImportError__all__rf   r8   r_   r   rQ   r+   r*   <module>rv      s1   6 6 ' ' ' ' ' ' - - - - - - 2 2 2 2 2 2 ' ' ' ' ' ' & & & & & &---------PPPPPPPP4444444   LLL %	H		%8 "N
 N
 N
 N
 N
0 N
 N
 N
 N
 N
s   : AA