
    leJi                         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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.    )	Transport)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 )z
        Supported URL formats:

        azureblockblob://CONNECTION_STRING
        azureblockblob://DefaultAzureCredential@STORAGE_ACCOUNT_URL
        azureblockblob://ManagedIdentityCredential@STORAGE_ACCOUNT_URL
        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         d/var/www/html/movieo_spanner_bot/venv/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_url<   s3    F-  	6&}555  r,   c                    d| j         v s	d| j         v r:t          j        | j                   \  }}t          ||| j        | j                  }n&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.

        DefaultAzureCredentialManagedIdentityCredential)account_url
credentialconnection_timeoutread_timeout)r7   r8   )namezContainer created with name .zContainer with name z* already.exists. This will not be created.)r   AzureStorageQueuesTransport	parse_urir   r#   r$   from_connection_stringcreate_containerr    r
   LOGGERinfo)r%   credential_r&   clientmsgs        r+   _blob_service_clientz*AzureBlockBlobBackend._blob_service_clientD   s    %(???'4+BBB  ;D'   K '&#'#;!/	  FF '='#'#;!/  F	4##)=#>>>H1EHHHCC" 	4 	4 	44)= 4 4 4CCC	4 	Cs   4&B B32B3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   r?   debugr    rD   get_blob_clientr"   download_blobreadalldecoder   r%   keyblob_clients      r+   r!   zAzureBlockBlobBackend.getk   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 /rF   T)	overwriteN)r   r?   rI   r    rD   rJ   r"   upload_blob)r%   rO   valuerP   s       r+   setzAzureBlockBlobBackend.set~   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!   ).0rO   r%   s     r+   
<listcomp>z.AzureBlockBlobBackend.mget.<locals>.<listcomp>   s#    ...#...r,   rY   )r%   keyss   ` r+   mgetzAzureBlockBlobBackend.mget   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 rR   rF   N)r   r?   rI   r    rD   rJ   r"   delete_blobrN   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)rZ   partaccount_key_prefixs     r+   r[   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_partsrf   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   classmethodrg   r   r   rD   r!   rV   r]   r`   rm   __classcell__)r*   s   @r+   r   r      s        66  $J J J J J JB $F ! ! ! [! $ $ _$L  &7 7 7$/ / /" " ""
 
 
 
 
 
 
 
r,   r   )rq   "kombu.transport.azurestoragequeuesr   r;   kombu.utilsr   kombu.utils.encodingr   celery.exceptionsr   celery.utils.logr   baser	   azure.storage.blobstoragerH   r   azure.core.exceptionsr
   r   r   ImportError__all__rn   r?   rg   r   rY   r,   r+   <module>r      sC   6 6 W W W W W W ' ' ' ' ' ' - - - - - - 2 2 2 2 2 2 ' ' ' ' ' ' & & & & & &---------PPPPPPPP4444444   LLL %	H		%8 "d
 d
 d
 d
 d
0 d
 d
 d
 d
 d
s   A   A
	A
