
    ]hG                         d dl Z d dlmZmZmZmZ d dlmZ d dlm	Z	 ddl
mZmZ ddlmZ erd dlmZmZ d d	lmZ  G d
 d      Zy)    N)AnyOptionalUnionTYPE_CHECKING)HttpResponseError)distributed_trace   )process_storage_errorreturn_response_headers)get_modify_conditions
BlobClientContainerClient)datetimec                   
   e Zd ZU dZeed<   	 ee   ed<   	 ed   ed<   	 	 dded   d	ee   d
dfdZd Z	d Z
eddeded
dfd       Zeded
dfd       Zeded
dfd       Zededed
dfd       Zeddee   ded
efd       Zy)BlobLeaseClienta  Creates a new BlobLeaseClient.

    This client provides lease operations on a BlobClient or ContainerClient.
    :param client: The client of the blob or container to lease.
    :type client: Union[BlobClient, ContainerClient]
    :param lease_id: A string representing the lease ID of an existing lease. This value does not need to be
    specified in order to acquire a new lease, or break one.
    :type lease_id: Optional[str]
    idetagr   last_modifiedNclientr   lease_idreturnc                     |xs t        t        j                               | _        d | _        d | _        t        |d      r|j                  j                  | _        y t        |d      r|j                  j                  | _        y t        d      )N	blob_namecontainer_namez4Lease must use either BlobClient or ContainerClient.)struuiduuid4r   r   r   hasattr_clientblob	container	TypeError)selfr   r   s      _/var/www/core.comfia.cic-ware.com/crm/lib/python3.12/site-packages/azure/storage/blob/_lease.py__init__zBlobLeaseClient.__init__,   sm     /c$**,/!	6;'!>>..DLV-.!>>33DLRSS    c                     | S N )r$   s    r%   	__enter__zBlobLeaseClient.__enter__:   s    r'   c                 $    | j                          y r)   )release)r$   argss     r%   __exit__zBlobLeaseClient.__exit__=   s    r'   lease_durationkwargsc           	      b   t        |      }	  | j                  j                  d|j                  dd      || j                  |t
        d|}j                  d      | _        |j                  d      | _	        |j                  d      | _
        y# t        $ r}t        |       Y d}~\d}~ww xY w)a	  Requests a new lease.

        If the container does not have an active lease, the Blob service creates a
        lease on the container and returns a new lease ID.

        :param int lease_duration:
            Specifies the duration of the lease, in seconds, or negative one
            (-1) for a lease that never expires. A non-infinite lease can be
            between 15 and 60 seconds. A lease duration cannot be changed
            using renew or change. Default is -1 (infinite lease).
        :keyword ~datetime.datetime if_modified_since:
            A DateTime value. Azure expects the date value passed in to be UTC.
            If timezone is included, any non-UTC datetimes will be converted to UTC.
            If a date is passed in without timezone info, it is assumed to be UTC.
            Specify this header to perform the operation only
            if the resource has been modified since the specified time.
        :keyword ~datetime.datetime if_unmodified_since:
            A DateTime value. Azure expects the date value passed in to be UTC.
            If timezone is included, any non-UTC datetimes will be converted to UTC.
            If a date is passed in without timezone info, it is assumed to be UTC.
            Specify this header to perform the operation only if
            the resource has not been modified since the specified date/time.
        :keyword str etag:
            An ETag value, or the wildcard character (*). Used to check if the resource has changed,
            and act according to the condition specified by the `match_condition` parameter.
        :keyword ~azure.core.MatchConditions match_condition:
            The match condition to use upon the etag.
        :keyword str if_tags_match_condition:
            Specify a SQL where clause on blob tags to operate only on blob with a matching value.
            eg. ``"\"tagname\"='my tag'"``

            .. versionadded:: 12.4.0

        :keyword int timeout:
            Sets the server-side timeout for the operation in seconds. For more details see
            https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-blob-service-operations.
            This value is not tracked or validated on the client. To configure client-side network timesouts
            see `here <https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/storage/azure-storage-blob
            #other-client--per-operation-configuration>`__.
        :rtype: None
        timeoutN)r3   durationproposed_lease_idmodified_access_conditionsclsr   r   r   r*   )r   r    acquire_leasepopr   r   r   r
   getr   r   )r$   r0   r1   mod_conditionsresponseerrors         r%   acquirezBlobLeaseClient.acquire@   s    V /v6		)6DLL66 

9d3'"&''+9+ H ,,z*%\\/:LL(		 ! 	)!%((	)   A B 	B.B))B.c                 `   t        |      }	  | j                  j                  d| j                  |j	                  dd      |t
        d|}j                  d      | _	        |j                  d      | _        |j                  d      | _
        y# t        $ r}t        |       Y d}~\d}~ww xY w)aP	  Renews the lease.

        The lease can be renewed if the lease ID specified in the
        lease client matches that associated with the container or blob. Note that
        the lease may be renewed even if it has expired as long as the container
        or blob has not been leased again since the expiration of that lease. When you
        renew a lease, the lease duration clock resets.

        :keyword ~datetime.datetime if_modified_since:
            A DateTime value. Azure expects the date value passed in to be UTC.
            If timezone is included, any non-UTC datetimes will be converted to UTC.
            If a date is passed in without timezone info, it is assumed to be UTC.
            Specify this header to perform the operation only
            if the resource has been modified since the specified time.
        :keyword ~datetime.datetime if_unmodified_since:
            A DateTime value. Azure expects the date value passed in to be UTC.
            If timezone is included, any non-UTC datetimes will be converted to UTC.
            If a date is passed in without timezone info, it is assumed to be UTC.
            Specify this header to perform the operation only if
            the resource has not been modified since the specified date/time.
        :keyword str etag:
            An ETag value, or the wildcard character (*). Used to check if the resource has changed,
            and act according to the condition specified by the `match_condition` parameter.
        :keyword ~azure.core.MatchConditions match_condition:
            The match condition to use upon the etag.
        :keyword str if_tags_match_condition:
            Specify a SQL where clause on blob tags to operate only on blob with a matching value.
            eg. ``"\"tagname\"='my tag'"``

            .. versionadded:: 12.4.0

        :keyword int timeout:
            Sets the server-side timeout for the operation in seconds. For more details see
            https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-blob-service-operations.
            This value is not tracked or validated on the client. To configure client-side network timesouts
            see `here <https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/storage/azure-storage-blob
            #other-client--per-operation-configuration>`__.
        :return: None
        r3   Nr   r3   r6   r7   r   r   r   r*   )r   r    renew_leaser   r9   r   r   r
   r:   r   r   r$   r1   r;   r<   r=   s        r%   renewzBlobLeaseClient.renewz   s    R /v6	)4DLL44 

9d3+9+	
 H LL(	,,z*%\\/:	 ! 	)!%((	)   ?B 	B-B((B-c                 `   t        |      }	  | j                  j                  d| j                  |j	                  dd      |t
        d|}j                  d      | _	        |j                  d      | _        |j                  d      | _
        y# t        $ r}t        |       Y d}~\d}~ww xY w)a  Release the lease.

        The lease may be released if the client lease id specified matches
        that associated with the container or blob. Releasing the lease allows another client
        to immediately acquire the lease for the container or blob as soon as the release is complete.

        :keyword ~datetime.datetime if_modified_since:
            A DateTime value. Azure expects the date value passed in to be UTC.
            If timezone is included, any non-UTC datetimes will be converted to UTC.
            If a date is passed in without timezone info, it is assumed to be UTC.
            Specify this header to perform the operation only
            if the resource has been modified since the specified time.
        :keyword ~datetime.datetime if_unmodified_since:
            A DateTime value. Azure expects the date value passed in to be UTC.
            If timezone is included, any non-UTC datetimes will be converted to UTC.
            If a date is passed in without timezone info, it is assumed to be UTC.
            Specify this header to perform the operation only if
            the resource has not been modified since the specified date/time.
        :keyword str etag:
            An ETag value, or the wildcard character (*). Used to check if the resource has changed,
            and act according to the condition specified by the `match_condition` parameter.
        :keyword ~azure.core.MatchConditions match_condition:
            The match condition to use upon the etag.
        :keyword str if_tags_match_condition:
            Specify a SQL where clause on blob tags to operate only on blob with a matching value.
            eg. ``"\"tagname\"='my tag'"``

            .. versionadded:: 12.4.0

        :keyword int timeout:
            Sets the server-side timeout for the operation in seconds. For more details see
            https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-blob-service-operations.
            This value is not tracked or validated on the client. To configure client-side network timesouts
            see `here <https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/storage/azure-storage-blob
            #other-client--per-operation-configuration>`__.
        :return: None
        r3   NrA   r   r   r   r*   )r   r    release_leaser   r9   r   r   r
   r:   r   r   rC   s        r%   r-   zBlobLeaseClient.release   s    N /v6	)6DLL66 

9d3+9+	
 H LL(	,,z*%\\/:	 ! 	)!%((	)rE   r5   c           	      b   t        |      }	  | j                  j                  d| j                  ||j	                  dd      |t
        d|}j                  d      | _	        |j                  d      | _        |j                  d      | _
        y# t        $ r}t        |       Y d}~\d}~ww xY w)a  Change the lease ID of an active lease.

        :param str proposed_lease_id:
            Proposed lease ID, in a GUID string format. The Blob service returns 400
            (Invalid request) if the proposed lease ID is not in the correct format.
        :keyword ~datetime.datetime if_modified_since:
            A DateTime value. Azure expects the date value passed in to be UTC.
            If timezone is included, any non-UTC datetimes will be converted to UTC.
            If a date is passed in without timezone info, it is assumed to be UTC.
            Specify this header to perform the operation only
            if the resource has been modified since the specified time.
        :keyword ~datetime.datetime if_unmodified_since:
            A DateTime value. Azure expects the date value passed in to be UTC.
            If timezone is included, any non-UTC datetimes will be converted to UTC.
            If a date is passed in without timezone info, it is assumed to be UTC.
            Specify this header to perform the operation only if
            the resource has not been modified since the specified date/time.
        :keyword str etag:
            An ETag value, or the wildcard character (*). Used to check if the resource has changed,
            and act according to the condition specified by the `match_condition` parameter.
        :keyword ~azure.core.MatchConditions match_condition:
            The match condition to use upon the etag.
        :keyword str if_tags_match_condition:
            Specify a SQL where clause on blob tags to operate only on blob with a matching value.
            eg. ``"\"tagname\"='my tag'"``

            .. versionadded:: 12.4.0

        :keyword int timeout:
            Sets the server-side timeout for the operation in seconds. For more details see
            https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-blob-service-operations.
            This value is not tracked or validated on the client. To configure client-side network timesouts
            see `here <https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/storage/azure-storage-blob
            #other-client--per-operation-configuration>`__.
        :return: None
        r3   N)r   r5   r3   r6   r7   r   r   r   r*   )r   r    change_leaser   r9   r   r   r
   r:   r   r   )r$   r5   r1   r;   r<   r=   s         r%   changezBlobLeaseClient.change   s    L /v6		)5DLL55 "3

9d3+9+ H LL(	,,z*%\\/:	 ! 	)!%((	)r?   lease_break_periodc                     t        |      }	  | j                  j                  d|j                  dd      ||t        d|}j                  d      S # t
        $ r}t        |       Y d}~*d}~ww xY w)a  Break the lease, if the container or blob has an active lease.

        Once a lease is broken, it cannot be renewed. Any authorized request can break the lease;
        the request is not required to specify a matching lease ID. When a lease
        is broken, the lease break period is allowed to elapse, during which time
        no lease operation except break and release can be performed on the container or blob.
        When a lease is successfully broken, the response indicates the interval
        in seconds until a new lease can be acquired.

        :param int lease_break_period:
            This is the proposed duration of seconds that the lease
            should continue before it is broken, between 0 and 60 seconds. This
            break period is only used if it is shorter than the time remaining
            on the lease. If longer, the time remaining on the lease is used.
            A new lease will not be available before the break period has
            expired, but the lease may be held for longer than the break
            period. If this header does not appear with a break
            operation, a fixed-duration lease breaks after the remaining lease
            period elapses, and an infinite lease breaks immediately.
        :keyword ~datetime.datetime if_modified_since:
            A DateTime value. Azure expects the date value passed in to be UTC.
            If timezone is included, any non-UTC datetimes will be converted to UTC.
            If a date is passed in without timezone info, it is assumed to be UTC.
            Specify this header to perform the operation only
            if the resource has been modified since the specified time.
        :keyword ~datetime.datetime if_unmodified_since:
            A DateTime value. Azure expects the date value passed in to be UTC.
            If timezone is included, any non-UTC datetimes will be converted to UTC.
            If a date is passed in without timezone info, it is assumed to be UTC.
            Specify this header to perform the operation only if
            the resource has not been modified since the specified date/time.
        :keyword str if_tags_match_condition:
            Specify a SQL where clause on blob tags to operate only on blob with a matching value.
            eg. ``"\"tagname\"='my tag'"``

            .. versionadded:: 12.4.0

        :keyword int timeout:
            Sets the server-side timeout for the operation in seconds. For more details see
            https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-blob-service-operations.
            This value is not tracked or validated on the client. To configure client-side network timesouts
            see `here <https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/storage/azure-storage-blob
            #other-client--per-operation-configuration>`__.
        :return: Approximate time remaining in the lease period, in seconds.
        :rtype: int
        r3   N)r3   break_periodr6   r7   
lease_timer*   )r   r    break_leaser9   r   r   r
   r:   )r$   rK   r1   r;   r<   r=   s         r%   rO   zBlobLeaseClient.break_lease  s~    ` /v6	)/t||// 

9d3/+9+	
 H ||L)) ! 	)!%((	)s   5A 	A1A,,A1r)   ))__name__
__module____qualname____doc__r   __annotations__r   r   r&   r+   r/   r   intr   r>   rD   r-   rJ   rO   r*   r'   r%   r   r      s7    	G$
3-0J''J
 #'T;<T3-T 
T 7)c 7)# 7)$ 7) 7)r 4;c 4;d 4; 4;l 2; 2; 2; 2;h 2; 2;s 2;t 2; 2;h 9*hsm 9*c 9*VY 9* 9*r'   r   )r   typingr   r   r   r   azure.core.exceptionsr   azure.core.tracing.decoratorr   _shared.response_handlersr
   r   
_serializer   azure.storage.blobr   r   r   r   r*   r'   r%   <module>r]      s1     6 6 3 : U ->!~* ~*r'   