o
    iZ                     @  sh  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eZerId dlmZ edZedZed	Zed
ZedddZ g dZ!dddQddZ"eG dd deZ#G dd deeef Z$dRd&d'Z%G d(d dZ&G d)d* d*e'Z(G d+d, d,e(Z)G d-d. d.e(Z*G d/d0 d0e)Z+G d1d2 d2e*Z,G d3d4 d4e(Z-G d5d6 d6e-Z.G d7d8 d8e.Z/G d9d: d:e-Z0G d;d< d<e-Z1G d=d> d>e-Z2G d?d@ d@e-Z3G dAdB dBe-Z4G dCdD dDe-eeef Z5G dEdF dFe-Z6G dGdH dHe(Z7G dIdJ dJe(Z8G dKdL dLe(Z9G dMdN dNe:Z;G dOdP dPe:Z<dS )S    )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 )message	exceptionr   argsr   r,   strkwargsreturnr   c          	      O  sh   t  \}}}|du rtdd||j|}| |g|R i |}z|| ty3   ||_|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.
    Nz7raise_with_traceback can only be used in except clauses
{}, {}: {})sysexc_info
ValueErrorformat__name__with_tracebackAttributeError__traceback__)	r-   r,   r.   r0   exc_type	exc_valueexc_tracebackexc_msgerror r@   L/home/app/Keep/.python/lib/python3.10/site-packages/azure/core/exceptions.pyraise_with_tracebackS   s   

rB   c                   @  sD   e Zd ZdZedddZedddZdd
dZedddZdS )_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).
    r1   Optional[str]c                 C     d S Nr@   selfr@   r@   rA   reasonr      z_HttpResponseCommonAPI.reasonOptional[int]c                 C  rE   rF   r@   rG   r@   r@   rA   status_codeu   rJ   z"_HttpResponseCommonAPI.status_coder/   c                 C  rE   rF   r@   rG   r@   r@   rA   textx   s    z_HttpResponseCommonAPI.textobjectc                 C  rE   rF   r@   rG   r@   r@   rA   requestz   s   z_HttpResponseCommonAPI.requestN)r1   rD   )r1   rK   r1   r/   )r1   rN   )	r7   
__module____qualname____doc__propertyrI   rL   rM   rO   r@   r@   r@   rA   rC   j   s    
rC   c                   @  s.   e Zd ZdZ	ddddddZdddZdS )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_errorcustom_error_map%Optional[Mapping[KeyType, ValueType]]rV   Optional[ValueType]r0   r   r1   Nonec                K  s   |pi | _ || _d S rF   )_custom_error_map_default_error)rH   rW   rV   r0   r@   r@   rA   __init__   s   

zErrorMap.__init__keyr   c                 C  s   | j |}|r
|S | jS rF   )r[   getr\   )rH   r^   retr@   r@   rA   r_      s   zErrorMap.getrF   )rW   rX   rV   rY   r0   r   r1   rZ   )r^   r   r1   rY   )r7   rQ   rR   rS   r]   r_   r@   r@   r@   rA   rU      s    	
rU   rL   intresponse	error_map%Mapping[int, Type[HttpResponseError]]rZ   c                 C  s(   |sd S | | }|sd S ||d}|)N)rb   )r_   )rL   rb   rc   Z
error_typer?   r@   r@   rA   	map_error   s   

re   c                   @  sP   e Zd ZdZdZdZdZdZdZdddZ	e
dddZdddZdddZdS )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
innererrorjson_objectMapping[str, Any]r1   rZ   c              	   C  s   d|v r|d }| j }||j| _||j| _| js(| js(tdt| ||j	| _
g | _||jp9g D ]}z| j|  | W q: tyP   Y q:w ||ji | _d S )Nr?   z7Impossible to extract code/message from received JSON:
)	__class__r_   
CODE_LABELrf   MESSAGE_LABELr,   r5   jsondumpsTARGET_LABELrg   rh   DETAILS_LABELappend	ExceptionINNERERROR_LABELri   )rH   rj   clsZdetail_noder@   r@   rA   r]      s    zODataV4Format.__init__rH   r   c                 C  s   dd l }|dt | S )Nr   zMerror.error from azure exceptions is deprecated, just simply use 'error' once)warningswarnDeprecationWarning)rH   rw   r@   r@   rA   r?      s   zODataV4Format.errorr/   c                 C  s   d | j| j|  S )Nz
({}) {}
{})r6   rf   r,   message_detailsrG   r@   r@   rA   __str__   s   zODataV4Format.__str__c                 C  s   d | j}|d | j7 }| jr|d | j7 }| jr6|d7 }| jD ]}|ddd t| D 7 }q#| jrF|d t	j
| jd	d
7 }|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                 s  s    | ]}d | V  qdS )	Nr@   ).0sr@   r@   rA   	<genexpr>  s    z0ODataV4Format.message_details.<locals>.<genexpr>z
Inner error: {}   )indent)r6   rf   r,   rg   rh   joinr/   
splitlinesri   ro   rp   )rH   Z	error_strZ	error_objr@   r@   rA   rz      s   
"zODataV4Format.message_detailsN)rj   rk   r1   rZ   )rH   r   r1   r   rP   )r7   rQ   rR   rS   rm   rn   rq   rr   ru   r]   rT   r?   r{   rz   r@   r@   r@   rA   r      s    *

	c                      s0   e Zd ZdZd fd	d
Zd fddZ  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.
    r,   Optional[object]r.   r   r0   r1   rZ   c                   s   | d| _t }|d | _|d | _|d | _| jr| jnt| j| _d|| jj	| j| _
t|| _| d| _tt| j| jg|R   d S )Nr?   r         r2   continuation_token)r_   Zinner_exceptionr3   r4   r;   r<   r=   typer6   r7   r>   r/   r,   r   superr   r]   )rH   r,   r.   r0   r4   rl   r@   rA   r]   %  s   



zAzureError.__init__c                   s.   z	t t| | j ty   | j| _| 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   r8   r=   r9   r:   rG   r   r@   rA   rB   3  s   zAzureError.raise_with_traceback)r,   r   r.   r   r0   r   r1   rZ   )r1   rZ   )r7   rQ   rR   rS   r]   rB   __classcell__r@   r@   r   rA   r     s    r   c                   @     e Zd ZdZdS )r   z_An error occurred while attempt to make a request to the service.
    No request was sent.
    Nr7   rQ   rR   rS   r@   r@   r@   rA   r   @      r   c                   @  r   )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   r@   r@   r@   rA   r   F  r   r   c                   @  r   )ServiceRequestTimeoutError!Error raised when timeout happensNr   r@   r@   r@   rA   r   L  r   r   c                   @  r   )ServiceResponseTimeoutErrorr   Nr   r@   r@   r@   rA   r   P  r   r   c                      sD   e Zd ZdZ		dd fddZedddZd fddZ  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
    Nr,   r   rb    Optional[_HttpResponseCommonAPI]r0   r   r1   rZ   c                   s   | dt}d | _d | _|| _|r|j| _|j| _|dd }|  |d ur)|| _nt| dd | _| ||| _	| j	r@t
| j	}n|pGd| j}tt| jdd|i| d S )Nerror_formatmodelr?   z)Operation returned an invalid status '{}'r,   r@   )r_   r   rI   rL   rb   popr   getattr_parse_odata_bodyr?   r/   r6   r   r   r]   )rH   r,   rb   r0   r   r   r   r@   rA   r]   g  s"   zHttpResponseError.__init__r   Type[ODataV4Format]Optional[ODataV4Format]c                 C  s.   zt | }| |W S  ty   Y d S w rF   )ro   loadsrM   rt   )r   rb   
odata_jsonr@   r@   rA   r     s   
z#HttpResponseError._parse_odata_bodyr/   c                   sZ   t t|  }z| j }|r| js d||d d W S W |S W |S  ty,   Y |S w )Nz{}
Content: {}i   )r   r   r{   rb   rM   r?   r6   rt   )rH   retvalbodyr   r@   rA   r{     s   

zHttpResponseError.__str__)NN)r,   r   rb   r   r0   r   r1   rZ   )r   r   rb   r   r1   r   rP   )	r7   rQ   rR   rS   r]   staticmethodr   r{   r   r@   r@   r   rA   r   T  s    %r   c                   @  r   )r   z-Error raised during response deserialization.Nr   r@   r@   r@   rA   r     r   r   c                   @  r   )IncompleteReadErrorz]Error raised if peer closes the connection before we have received the complete message body.Nr   r@   r@   r@   rA   r     r   r   c                   @  r   )r   hAn error response with status code 4xx.
    This will not be raised directly by the Azure core pipeline.Nr   r@   r@   r@   rA   r     r   r   c                   @  r   )r    z[An error response, typically triggered by a 412 response (for update) or 404 (for get/post)Nr   r@   r@   r@   rA   r      r   r    c                   @  r   )r!   r   Nr   r@   r@   r@   rA   r!     r   r!   c                   @  r   )r"   zAn error response with status code 4xx, typically 412 Conflict.
    This will not be raised directly by the Azure core pipeline.Nr   r@   r@   r@   rA   r"     r   r"   c                   @  r   )r#   zhAn error response with status code 304.
    This will not be raised directly by the Azure core pipeline.Nr   r@   r@   r@   rA   r#     r   r#   c                      s"   e Zd ZdZd fd	d
Z  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]
    history9'List[RequestHistory[HTTPRequestType, HTTPResponseType]]'r.   r   r0   r1   rZ   c                   s,   || _ d}tt| j|g|R i | d S )Nz"Reached maximum redirect attempts.)r   r   r$   r]   )rH   r   r.   r0   r,   r   r@   rA   r]     s   "zTooManyRedirectsError.__init__)r   r   r.   r   r0   r   r1   rZ   r7   rQ   rR   rS   r]   r   r@   r@   r   rA   r$     s    r$   c                      s4   e Zd ZdZeZd fdd	Zd fddZ  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.
    rb   rC   r0   r   r1   rZ   c                   s  d | _ zt| | _ | j di d}W n ty"   d }Y nw d | _|d|}d | _g | _	i | _
|r?d|vr?||d< tt| jdd|i| d | _| j rz| j d }| || _| jdd | jj D  W d S  ty   td dt| j | _Y d S w d S )	Nr?   r,   rb   c                 S  s   i | ]\}}|d ur||qS rF   r@   )r~   kvr@   r@   rA   
<dictcomp>  s    z)ODataV4Error.__init__.<locals>.<dictcomp>z4Received error message was not valid OdataV4 format.zJSON was invalid for format r@   )r   ro   r   rM   
setdefaultr_   rt   rf   rg   rh   ri   r   r%   r]   _error_format_ERROR_FORMAT__dict__updateitems_LOGGERinfor/   )rH   rb   r0   Zodata_messager,   Z
error_noder   r@   rA   r]     s4   
$
zODataV4Error.__init__r/   c                   s   | j rt| j S tt|  S rF   )r   r/   r   r%   r{   rG   r   r@   rA   r{   
  s   
zODataV4Error.__str__)rb   rC   r0   r   r1   rZ   rP   )	r7   rQ   rR   rS   r   r   r]   r{   r   r@   r@   r   rA   r%     s
    r%   c                      "   e Zd ZdZd fddZ  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
    rb   rC   r1   rZ   c                       d |j}tt| | d S )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.)r6   rO   r   r&   r]   rH   rb   r,   r   r@   rA   r]        zStreamConsumedError.__init__rb   rC   r1   rZ   r   r@   r@   r   rA   r&         	r&   c                      r   )	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
    rb   rC   r1   rZ   c                   r   )NzwThe content for response from request {} can no longer be read or streamed, since the response has already been closed.)r6   rO   r   r'   r]   r   r   r@   rA   r]   ,  r   zStreamClosedError.__init__r   r   r@   r@   r   rA   r'   "  r   r'   c                      r   )	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
    rb   rC   r1   rZ   c                   r   )NzdYou have not read in the bytes for the response from request {}. Call .read() on the response first.)r6   rO   r   r(   r]   r   r   r@   rA   r]   >  r   zResponseNotReadError.__init__r   r   r@   r@   r   rA   r(   4  r   r(   c                   @  r   )r)   z7Raised if an error is encountered during serialization.Nr   r@   r@   r@   rA   r)   F  r   r)   c                   @  r   )r*   z9Raised if an error is encountered during deserialization.Nr   r@   r@   r@   rA   r*   J  r   r*   )
r-   r   r.   r   r,   r/   r0   r   r1   r   )rL   ra   rb   rC   rc   rd   r1   rZ   )=
__future__r   ro   loggingr3   typesr   typingr   r   r   r   r   r	   r
   r   r   r   r   r   Ztyping_extensionsr   r   	getLoggerr7   r   Zazure.core.pipeline.policiesr   r   r   r   r   r   __all__rB   rC   rU   re   r   rt   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r5   r)   r*   r@   r@   r@   rA   <module>   sT   8

m-Q9