
    ]hZ                    J   d dl mZ d dlZd dlZd dlZd dlmZ d dlmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZ d dlmZmZ  ej.                  e      Zerd dlmZ  ed      Z ed      Z ed	      Z ed
      Z edd      Z g dZ!ddd@dZ"e G d de             Z# G d deeef         Z$	 	 	 	 	 	 	 	 dAdZ% G d d      Z& G d de'      Z( G d de(      Z) G d de(      Z* G d de)      Z+ G d  d!e*      Z, G d" d#e(      Z- G d$ d%e-      Z. G d& d'e.      Z/ G d( d)e-      Z0 G d* d+e-      Z1 G d, d-e-      Z2 G d. d/e-      Z3 G d0 d1e-      Z4 G d2 d3e-eeef         Z5 G d4 d5e-      Z6 G d6 d7e(      Z7 G d8 d9e(      Z8 G d: d;e(      Z9 G d< d=e:      Z; G d> d?e:      Z<y)B    )annotationsN)TracebackType)CallableAnyOptionalUnionTypeListMappingTypeVarGenericDictNoReturnTYPE_CHECKING)Protocolruntime_checkable)RequestHistoryHTTPResponseTypeHTTPRequestTypeKeyType	ValueTypeSelfODataV4FormatODataV4Format)bound)
AzureErrorServiceRequestErrorServiceResponseErrorHttpResponseErrorDecodeErrorResourceExistsErrorResourceNotFoundErrorClientAuthenticationErrorResourceModifiedErrorResourceNotModifiedErrorTooManyRedirectsErrorr   ODataV4ErrorStreamConsumedErrorStreamClosedErrorResponseNotReadErrorSerializationErrorDeserializationError )messagec                   t        j                         \  }}}|t        d      dj                  ||j                  |      } | |g|i |}	 |j                  |      # t        $ r
 ||_        |w xY w)a  Raise exception with a specified traceback.
    This MUST be called inside a "except" clause.

    .. note:: This method is deprecated since we don't support Python 2 anymore. Use raise/from instead.

    :param Exception exception: Error type to be raised.
    :param any args: Any additional args to be included with exception.
    :keyword str message: Message to be associated with the exception. If omitted, defaults to an empty string.
    z7raise_with_traceback can only be used in except clauses
{}, {}: {})sysexc_info
ValueErrorformat__name__with_tracebackAttributeError__traceback__)		exceptionr-   argskwargsexc_type	exc_valueexc_tracebackexc_msgerrors	            [/var/www/core.comfia.cic-ware.com/crm/lib/python3.12/site-packages/azure/core/exceptions.pyraise_with_tracebackrA   S   s     *-&HiRSS!!'8+<+<iHGg///E""=11 +s   A! !A4c                  N    e Zd ZdZedd       Zedd       Zd	dZed
d       Zy)_HttpResponseCommonAPIzProtocol used by exceptions for HTTP response.

    As HttpResponseError uses very few properties of HttpResponse, a protocol
    is faster and simpler than import all the possible types (at least 6).
    c                     y N selfs    r@   reasonz_HttpResponseCommonAPI.reasonr   s    '*    c                     y rE   rF   rG   s    r@   status_codez"_HttpResponseCommonAPI.status_codeu   s    ,/rJ   c                     y rE   rF   rG   s    r@   textz_HttpResponseCommonAPI.textx   s    rJ   c                     y rE   rF   rG   s    r@   requestz_HttpResponseCommonAPI.requestz   s    rJ   N)returnzOptional[str])rQ   zOptional[int]rQ   str)rQ   object)	r4   
__module____qualname____doc__propertyrI   rL   rN   rP   rF   rJ   r@   rC   rC   j   s:     * */ / rJ   rC   c                  8    e Zd ZdZ	 ddd	 	 	 	 	 	 	 ddZddZy)	ErrorMapa  Error Map class. To be used in map_error method, behaves like a dictionary.
    It returns the error type if it is found in custom_error_map. Or return default_error

    :param dict custom_error_map: User-defined error map, it is used to map status codes to error types.
    :keyword error default_error: Default error type. It is returned if the status code is not found in custom_error_map
    N)default_errorc               (    |xs i | _         || _        y rE   )_custom_error_map_default_error)rH   custom_error_mapr[   r:   s       r@   __init__zErrorMap.__init__   s     "2!7R+rJ   c                X    | j                   j                  |      }|r|S | j                  S rE   )r]   getr^   )rH   keyrets      r@   rb   zErrorMap.get   s,    $$((-J"""rJ   rE   )r_   z%Optional[Mapping[KeyType, ValueType]]r[   Optional[ValueType]r:   r   rQ   None)rc   r   rQ   re   )r4   rU   rV   rW   r`   rb   rF   rJ   r@   rZ   rZ      sH     CG, .2	,?, +	,
 , 
,#rJ   rZ   c                F    |sy |j                  |       }|sy  ||      }|)N)response)rb   )rL   rh   	error_map
error_typer?   s        r@   	map_errorrk      s-    
 {+J)E
KrJ   c                  N    e Zd ZdZdZdZdZdZdZddZ	e
dd       Zdd	Zdd
Zy)r   a  Class to describe OData V4 error format.

    http://docs.oasis-open.org/odata/odata-json-format/v4.0/os/odata-json-format-v4.0-os.html#_Toc372793091

    Example of JSON:

    .. code-block:: json

        {
            "error": {
                "code": "ValidationError",
                "message": "One or more fields contain incorrect values: ",
                "details": [
                    {
                        "code": "ValidationError",
                        "target": "representation",
                        "message": "Parsing error(s): String '' does not match regex pattern '^[^{}/ :]+(?: :\\d+)?$'.
                        Path 'host', line 1, position 297."
                    },
                    {
                        "code": "ValidationError",
                        "target": "representation",
                        "message": "Parsing error(s): The input OpenAPI file is not valid for the OpenAPI specificate
                        https: //github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md
                        (schema https://github.com/OAI/OpenAPI-Specification/blob/master/schemas/v2.0/schema.json)."
                    }
                ]
            }
        }

    :param dict json_object: A Python dict representing a ODataV4 JSON
    :ivar str ~.code: Its value is a service-defined error code.
     This code serves as a sub-status for the HTTP error code specified in the response.
    :ivar str message: Human-readable, language-dependent representation of the error.
    :ivar str target: The target of the particular error (for example, the name of the property in error).
     This field is optional and may be None.
    :ivar list[ODataV4Format] details: Array of ODataV4Format instances that MUST contain name/value pairs
     for code and message, and MAY contain a name/value pair for target, as described above.
    :ivar dict innererror: An object. The contents of this object are service-defined.
     Usually this object contains information that will help debug the service.
    coder-   targetdetails
innererrorc                l   d|v r|d   }| j                   }|j                  |j                        | _        |j                  |j                        | _        | j                  s-| j
                  s!t        dt        j                  |      z         |j                  |j                        | _
        g | _        |j                  |j                        xs g D ]-  }	 | j                  j                  | j                  |             / |j                  |j                  i       | _        y # t        $ r Y ]w xY w)Nr?   z7Impossible to extract code/message from received JSON:
)	__class__rb   
CODE_LABELrm   MESSAGE_LABELr-   r2   jsondumpsTARGET_LABELrn   ro   DETAILS_LABELappend	ExceptionINNERERROR_LABELrp   )rH   json_objectclsdetail_nodes       r@   r`   zODataV4Format.__init__   s   k!%g.K#'>> $/??3>>#B	&1ooc6G6G&H		T\\WZ^ZdZdepZqqrr &1__S5E5E%F -/&??3+<+<=C 	K##DNN;$?@	 .9__S=Q=QSU-V  s   *D''	D32D3c                :    dd l }|j                  dt               | S )Nr   zMerror.error from azure exceptions is deprecated, just simply use 'error' once)warningswarnDeprecationWarning)rH   r   s     r@   r?   zODataV4Format.error   s    [	
 rJ   c                l    dj                  | j                  | j                  | j                               S )Nz
({}) {}
{})r3   rm   r-   message_detailsrG   s    r@   __str__zODataV4Format.__str__   s(    ##DIIt||T=Q=Q=STTrJ   c                   dj                  | j                        }|dj                  | j                        z  }| j                  r|dj                  | j                        z  }| j                  rH|dz  }| j                  D ]4  }|dj                  d t        |      j                         D              z  }6 | j                  r3|dj                  t        j                  | j                  d	            z  }|S )
z}Return a detailed string of the error.

        :return: A string with the details of the error.
        :rtype: str
        zCode: {}z
Message: {}z
Target: {}z
Exception Details:
c              3  &   K   | ]	  }d |z     yw)	NrF   ).0ss     r@   	<genexpr>z0ODataV4Format.message_details.<locals>.<genexpr>  s     &UAtax&Us   z
Inner error: {}   )indent)r3   rm   r-   rn   ro   joinrS   
splitlinesrp   ru   rv   )rH   	error_str	error_objs      r@   r   zODataV4Format.message_details   s     %%dii0	_++DLL99	;;..t{{;;I<<//I!\\ V	TYY&UY9R9R9T&UUU	V ??,33DJJtWX4YZZIrJ   N)r|   zMapping[str, Any]rQ   rf   )rH   r   rQ   r   rR   )r4   rU   rV   rW   rs   rt   rw   rx   r{   r`   rX   r?   r   r   rF   rJ   r@   r   r      sI    (T JMLM#W2  UrJ   c                  0     e Zd ZdZd fdZd fdZ xZS )r   a@  Base exception for all errors.

    :param object message: The message object stringified as 'message' attribute
    :keyword error: The original exception if any
    :paramtype error: Exception

    :ivar inner_exception: The exception passed with the 'error' kwarg
    :vartype inner_exception: Exception
    :ivar exc_type: The exc_type from sys.exc_info()
    :ivar exc_value: The exc_value from sys.exc_info()
    :ivar exc_traceback: The exc_traceback from sys.exc_info()
    :ivar exc_msg: A string formatting of message parameter, exc_type and exc_value
    :ivar str message: A stringified version of the message parameter
    :ivar str continuation_token: A token reference to continue an incomplete operation. This value is optional
     and will be `None` where continuation is either unavailable or not applicable.
    c                   |j                  d      | _        t        j                         }|d   | _        |d   | _        |d   | _        | j                  r| j                  nt        | j                        | _        dj                  || j                  j                  | j
                        | _
        t        |      | _        |j                  d      | _        t        t        | B  | j                  g|  y )Nr?   r         r/   continuation_token)rb   inner_exceptionr0   r1   r;   r<   r=   typer3   r4   r>   rS   r-   r   superr   r`   )rH   r-   r9   r:   r1   rr   s        r@   r`   zAzureError.__init__%  s    8>

78K<<>-5a[2:1+6>qk)-DAUAU<V(//9O9OQUQ_Q_`L17<P1Qj$(==rJ   c                    	 t         t        |   | j                        # t        $ r | j                  | _        | w xY w)zRaise the exception with the existing traceback.

        .. deprecated:: 1.22.0
           This method is deprecated as we don't support Python 2 anymore. Use raise/from instead.
        )r   r   r5   r=   r6   r7   rH   rr   s    r@   rA   zAzureError.raise_with_traceback3  sB    	
D89K9KLL 	:>:L:LDJ	s     =)r-   Optional[object]r9   r   r:   r   rQ   rf   )rQ   rf   )r4   rU   rV   rW   r`   rA   __classcell__rr   s   @r@   r   r     s    ">
 
rJ   r   c                      e Zd ZdZy)r   z_An error occurred while attempt to make a request to the service.
    No request was sent.
    Nr4   rU   rV   rW   rF   rJ   r@   r   r   @  s    rJ   r   c                      e Zd ZdZy)r   zThe request was sent, but the client failed to understand the response.
    The connection may have timed out. These errors can be retried for idempotent or
    safe operationsNr   rF   rJ   r@   r   r   F  s    rJ   r   c                      e Zd ZdZy)ServiceRequestTimeoutError!Error raised when timeout happensNr   rF   rJ   r@   r   r   L      +rJ   r   c                      e Zd ZdZy)ServiceResponseTimeoutErrorr   Nr   rF   rJ   r@   r   r   P  r   rJ   r   c                  b     e Zd ZdZ	 	 d	 	 	 	 	 	 	 d fdZe	 	 	 	 	 	 dd       Zd fdZ xZS )	r   aS  A request was made, and a non-success status code was received from the service.

    :param object message: The message object stringified as 'message' attribute
    :param response: The response that triggered the exception.
    :type response: ~azure.core.pipeline.transport.HttpResponse or ~azure.core.pipeline.transport.AsyncHttpResponse

    :ivar reason: The HTTP response reason
    :vartype reason: str
    :ivar status_code: HttpResponse's status code
    :vartype status_code: int
    :ivar response: The response that triggered the exception.
    :vartype response: ~azure.core.pipeline.transport.HttpResponse or ~azure.core.pipeline.transport.AsyncHttpResponse
    :ivar model: The request body/response body model
    :vartype model: ~msrest.serialization.Model
    :ivar error: The formatted error
    :vartype error: ODataV4Format
    c                   |j                  dt              }d | _        d | _        || _        |r"|j                  | _        |j                  | _        |j                  dd       }|  ||| _        nt        | dd       | _        | j                  ||      | _	        | j                  rt        | j                        }n|xs dj                  | j                        }t        t        | :  dd|i| y )Nerror_formatmodelr?   z)Operation returned an invalid status '{}'r-   rF   )rb   r   rI   rL   rh   popr   getattr_parse_odata_bodyr?   rS   r3   r   r   r`   )rH   r-   rh   r:   r   r   rr   s         r@   r`   zHttpResponseError.__init__g  s     zz.-@%)*.:B"//DK'33D  &zz'48DJ w5DJ.2.D.D\S[.\
 ::$**oG`!L!S!STXT_T_!`G/JJ6JrJ   c                x    	 t        j                  |j                               } | |      S # t        $ r Y y w xY wrE   )ru   loadsrN   rz   )r   rh   
odata_jsons      r@   r   z#HttpResponseError._parse_odata_body  s;    	HMMO4J
++ 		s   *- 	99c                    t         t        |          }	 | j                  j	                         }|r!| j
                  sdj                  ||      d d S |S # t        $ r Y |S w xY w)Nz{}
Content: {}i   )r   r   r   rh   rN   r?   r3   rz   )rH   retvalbodyrr   s      r@   r   zHttpResponseError.__str__  sm    ($79	==%%'DDJJ(//=etDD   		s   <A 	A! A!)NN)r-   r   rh    Optional[_HttpResponseCommonAPI]r:   r   rQ   rf   )r   zType[ODataV4Format]rh   r   rQ   zOptional[ODataV4Format]rR   )	r4   rU   rV   rW   r`   staticmethodr   r   r   r   s   @r@   r   r   T  sw    ( %)59#K!#K 3#K 	#K
 
#KJ 
)
5U
	 
 
	 	rJ   r   c                      e Zd ZdZy)r   z-Error raised during response deserialization.Nr   rF   rJ   r@   r   r     s    7rJ   r   c                      e Zd ZdZy)IncompleteReadErrorz]Error raised if peer closes the connection before we have received the complete message body.Nr   rF   rJ   r@   r   r     s    grJ   r   c                      e Zd ZdZy)r    hAn error response with status code 4xx.
    This will not be raised directly by the Azure core pipeline.Nr   rF   rJ   r@   r    r          DrJ   r    c                      e Zd ZdZy)r!   z[An error response, typically triggered by a 412 response (for update) or 404 (for get/post)Nr   rF   rJ   r@   r!   r!     s    erJ   r!   c                      e Zd ZdZy)r"   r   Nr   rF   rJ   r@   r"   r"     r   rJ   r"   c                      e Zd ZdZy)r#   zAn error response with status code 4xx, typically 412 Conflict.
    This will not be raised directly by the Azure core pipeline.Nr   rF   rJ   r@   r#   r#     r   rJ   r#   c                      e Zd ZdZy)r$   zhAn error response with status code 304.
    This will not be raised directly by the Azure core pipeline.Nr   rF   rJ   r@   r$   r$     r   rJ   r$   c                  4     e Zd ZdZ	 	 	 	 	 	 	 	 d fdZ xZS )r%   zReached the maximum number of redirect attempts.

    :param history: The history of requests made while trying to fulfill the request.
    :type history: list[~azure.core.pipeline.policies.RequestHistory]
    c                F    || _         d}t        t        |   |g|i | y )Nz"Reached maximum redirect attempts.)historyr   r%   r`   )rH   r   r9   r:   r-   rr   s        r@   r`   zTooManyRedirectsError.__init__  s+     6#T3GMdMfMrJ   )r   z9'List[RequestHistory[HTTPRequestType, HTTPResponseType]]'r9   r   r:   r   rQ   rf   r4   rU   rV   rW   r`   r   r   s   @r@   r%   r%     s>    NJN N 	N
 
N NrJ   r%   c                  4     e Zd ZdZeZd fdZd fdZ xZS )r&   aK  An HTTP response error where the JSON is decoded as OData V4 error format.

    http://docs.oasis-open.org/odata/odata-json-format/v4.0/os/odata-json-format-v4.0-os.html#_Toc372793091

    :param ~azure.core.rest.HttpResponse response: The response object.
    :ivar dict odata_json: The parsed JSON body as attribute for convenience.
    :ivar str ~.code: Its value is a service-defined error code.
     This code serves as a sub-status for the HTTP error code specified in the response.
    :ivar str message: Human-readable, language-dependent representation of the error.
    :ivar str target: The target of the particular error (for example, the name of the property in error).
     This field is optional and may be None.
    :ivar list[ODataV4Format] details: Array of ODataV4Format instances that MUST contain name/value pairs
     for code and message, and MAY contain a name/value pair for target, as described above.
    :ivar dict innererror: An object. The contents of this object are service-defined.
     Usually this object contains information that will help debug the service.
    c                $   d | _         	 t        j                  |j                               | _         | j                   j	                  di       j                  d      }d | _        |j                  d|      }d | _        g | _	        i | _
        |r	d|vr||d<   t        t        | 6  dd|i| d | _        | j                   r{	 | j                   d   }| j                  |      | _        | j                   j#                  | j                  j                   j%                         D ci c]  \  }}|	|| c}}       y y # t        $ r d }Y w xY wc c}}w # t        $ r5 t&        j)                  d       dt+        | j                        z   | _        Y y w xY w)Nr?   r-   rh   z4Received error message was not valid OdataV4 format.zJSON was invalid for format rF   )r   ru   r   rN   
setdefaultrb   rz   rm   rn   ro   rp   r   r&   r`   _error_format_ERROR_FORMAT__dict__updateitems_LOGGERinforS   )	rH   rh   r:   odata_messager-   
error_nodekvrr   s	           r@   r`   zODataV4Error.__init__  sk   48	!"jj9DO OO66wCGG	RM
 $(	!'I}!E%),.79y. 'F9lD*GHGGBF??^!__W5
%)%7%7
%C"$$t7I7I7R7R7X7X7Z%ltq!^_^kad%lm	 !  	! M	!( &m ^ST%Cc$J\J\F]%]"^s=   AD: ?A!E  
E
+E
0E :EEE ;FFc                j    | j                   rt        | j                         S t        t        |          S rE   )r   rS   r   r&   r   r   s    r@   r   zODataV4Error.__str__
  s-    t))**\4022rJ   )rh   rC   r:   r   rQ   rf   rR   )	r4   rU   rV   rW   r   r   r`   r   r   r   s   @r@   r&   r&     s    " "M^>3 3rJ   r&   c                  $     e Zd ZdZd fdZ xZS )r'   a  Error thrown if you try to access the stream of a response once consumed.

    It is thrown if you try to read / stream an ~azure.core.rest.HttpResponse or
    ~azure.core.rest.AsyncHttpResponse once the response's stream has been consumed.

    :param response: The response that triggered the exception.
    :type response: ~azure.core.rest.HttpResponse or ~azure.core.rest.AsyncHttpResponse
    c                b    dj                  |j                        }t        t        |   |       y )NzYou are attempting to read or stream the content from request {}. You have likely already consumed this stream, so it can not be accessed anymore.)r3   rP   r   r'   r`   rH   rh   r-   rr   s      r@   r`   zStreamConsumedError.__init__  s2    __e_efnfvfv_w 	 	!41':rJ   rh   rC   rQ   rf   r   r   s   @r@   r'   r'     s    ; ;rJ   r'   c                  $     e Zd ZdZd fdZ xZS )r(   a  Error thrown if you try to access the stream of a response once closed.

    It is thrown if you try to read / stream an ~azure.core.rest.HttpResponse or
    ~azure.core.rest.AsyncHttpResponse once the response's stream has been closed.

    :param response: The response that triggered the exception.
    :type response: ~azure.core.rest.HttpResponse or ~azure.core.rest.AsyncHttpResponse
    c                b    dj                  |j                        }t        t        |   |       y )NzwThe content for response from request {} can no longer be read or streamed, since the response has already been closed.)r3   rP   r   r(   r`   r   s      r@   r`   zStreamClosedError.__init__,  s/    006x7G7G0H 	 	/8rJ   r   r   r   s   @r@   r(   r(   "  s    9 9rJ   r(   c                  $     e Zd ZdZd fdZ xZS )r)   a  Error thrown if you try to access a response's content without reading first.

    It is thrown if you try to access an ~azure.core.rest.HttpResponse or
    ~azure.core.rest.AsyncHttpResponse's content without first reading the response's bytes in first.

    :param response: The response that triggered the exception.
    :type response: ~azure.core.rest.HttpResponse or ~azure.core.rest.AsyncHttpResponse
    c                b    dj                  |j                        }t        t        |   |       y )NzdYou have not read in the bytes for the response from request {}. Call .read() on the response first.)r3   rP   r   r)   r`   r   s      r@   r`   zResponseNotReadError.__init__>  s/    228&9I9I2J 	 	"D27;rJ   r   r   r   s   @r@   r)   r)   4  s    < <rJ   r)   c                      e Zd ZdZy)r*   z7Raised if an error is encountered during serialization.Nr   rF   rJ   r@   r*   r*   F  s    ArJ   r*   c                      e Zd ZdZy)r+   z9Raised if an error is encountered during deserialization.Nr   rF   rJ   r@   r+   r+   J  s    CrJ   r+   )
r8   r   r9   r   r-   rS   r:   r   rQ   r   )rL   intrh   rC   ri   z%Mapping[int, Type[HttpResponseError]]rQ   rf   )=
__future__r   ru   loggingr0   typesr   typingr   r   r   r   r	   r
   r   r   r   r   r   r   typing_extensionsr   r   	getLoggerr4   r   azure.core.pipeline.policiesr   r   r   r   r   r   __all__rA   rC   rZ   rk   r   rz   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r2   r*   r+   rF   rJ   r@   <module>r      s  4 #   
     :
'

H
%;-. +,
)
K 	/G , JL . X  (#ww	)* #2$ 5 
	j jZ* *Z* : ,!4 ,,"6 ,N
 Nb8# 8h+ hD+ D
f- fD 1 D
D- D
D0 D
N-wHX7X/Y N$63$ 63r;* ;$9
 9$<: <$B BD: DrJ   