
    d{i                     b    d dl Z d dlmZmZmZ  G d de      Z G d de      Z G d de      Zy)	    N)OptionalListDictc                       e Zd Zy)TwilioExceptionN)__name__
__module____qualname__     T/home/sas/my/fyp/ringai/.venv/lib/python3.12/site-packages/twilio/base/exceptions.pyr   r      s    r   r   c                   R    e Zd ZdZ	 	 	 	 ddedededee   dedee   fd	Zd
efdZ	y)TwilioRestExceptiona  A generic 400 or 500 level exception from the Twilio API

    :param int status: the HTTP status that was returned for the exception
    :param str uri: The URI that caused the exception
    :param str msg: A human-readable message for the error
    :param int|None code: A Twilio-specific error code for the error. This is
         not available for all errors.
    :param method: The HTTP method used to make the request
    :param details: Additional error details returned for the exception
    Nstatusurimsgcodemethoddetailsc                 X    || _         || _        || _        || _        || _        || _        y N)r   r   r   r   r   r   )selfr   r   r   r   r   r   s          r   __init__zTwilioRestException.__init__   s.     	r   returnc                    dt         dt         fd}dt         dt         fd}dt         dt         fd}dt         dt         fd}dt        dt         fd}t        t        j                  d	      rt        j                  j                         rd
j                   |d       |d       || j                  d| j                         |d       |t        | j                                    }| j                  r@dj                  |dj                   |d       | || j                                    g      }|S dj                  | j                  | j                        S )z>Try to pretty-print the exception, if this is going on screen.wordsr   c                     d| z  S Nz[31m[49m%s[0mr   r   s    r   redz(TwilioRestException.__str__.<locals>.red)       .66r   c                     d| z  S Nz[37m[49m%s[0mr   r   s    r   whitez*TwilioRestException.__str__.<locals>.white,   r!   r   c                     d| z  S Nz[34m[49m%s[0mr   r   s    r   bluez)TwilioRestException.__str__.<locals>.blue/   r!   r   c                     d| z  S Nz[36m[49m%s[0mr   r   s    r   tealz)TwilioRestException.__str__.<locals>.teal2   r!   r   r   c                 $    dj                  |       S )Nz&https://www.twilio.com/docs/errors/{0})format)r   s    r   get_uriz,TwilioRestException.__str__.<locals>.get_uri5   s    ;BB4HHr   isattyzF
{red_error} {request_was}

{http_line}

{twilio_returned}

{message}

HTTP ErrorYour request was: *Twilio returned the following information:)	red_errorrequest_was	http_linetwilio_returnedmessage 
{more_info}

{uri}

'More information may be available here:	more_infor   HTTP {0} error: {1})strinthasattrsysstderrr.   r,   r   r   r   r   joinr   )r   r    r$   r'   r*   r-   r   s          r   __str__zTwilioRestException.__str__&   sI   	7s 	7s 	7	7 	7 	7	7 	7 	7	7 	7 	7	I# 	I# 	I 3::x(SZZ->->-@77=v!,/ %&9 :"dkk488#DE$)*V$W TXX/ 8> 8  yygg4;;&+,U&V $WTYY%7 8 <  J(//TXXFFr   )r8   NGETN)
r   r	   r
   __doc__r?   r>   r   objectr   rD   r   r   r   r   r   
   sk    	 "$(  	
 sm  &! ,G ,Gr   r   c                   v    e Zd ZdZ	 	 	 	 	 ddededededee   dee   d	eeeeef         d
edefdZ	defdZ
y)TwilioServiceExceptionaJ  An RFC-9457 compliant exception from a Twilio service

    This exception follows the Problem Details for HTTP APIs specification
    (RFC-9457). See https://www.rfc-editor.org/rfc/rfc9457.html

    :param str type: A URI reference that identifies the problem type
    :param str title: A short, human-readable summary of the problem type
    :param int status: The HTTP status code for this occurrence of the problem
    :param int code: Twilio-specific error code
    :param str|None detail: A human-readable explanation specific to this occurrence
    :param str|None instance: A URI reference identifying the specific occurrence
    :param list|None errors: Array of validation errors with detail and pointer fields
    :param str method: The HTTP method used to make the request
    :param str uri: The URI that caused the exception
    Ntype_urititler   r   detailinstanceerrorsr   r   c
                     || _         || _        || _        || _        || _        || _        |xs g | _        || _        |	| _        y r   )	typerK   r   r   rL   rM   rN   r   r   )
r   rJ   rK   r   r   rL   rM   rN   r   r   s
             r   r   zTwilioServiceException.__init__f   sG     	
	 lr   r   c                 V   dt         dt         fd}dt         dt         fd}dt         dt         fd}dt         dt         fd}dt         dt         fd}t        t        j                  d      r-t        j                  j	                         rd	j                   |d
       |d      | j                  r! || j                  d| j                        n |d       |d            g}|j                  dj                   |d       || j                                     | j                  r8|j                  dj                   |d       || j                                     |j                  dj                   |d       |t        | j                               |d       |t        | j                                           | j                  r|j                  dj                   |d                   | j                  D ]J  }|j                  dj                   ||j                  dd            |j                  d d!      "             L |j                  d#j                   |d$       || j                        %             d&j!                  |      S d'j                  | j                  | j                        }| j                  r|d(j                  | j                        z  }| j                  r4|d)j                  d*j!                  d+ | j                  D                    z  }|S ),z/Pretty-print the exception for terminal output.r   r   c                     d| z  S r   r   r   s    r   r    z+TwilioServiceException.__str__.<locals>.red   r!   r   c                     d| z  S r#   r   r   s    r   r$   z-TwilioServiceException.__str__.<locals>.white   r!   r   c                     d| z  S r&   r   r   s    r   r'   z,TwilioServiceException.__str__.<locals>.blue   r!   r   c                     d| z  S r)   r   r   s    r   r*   z,TwilioServiceException.__str__.<locals>.teal   r!   r   c                     d| z  S )Nz[33m[49m%s[0mr   r   s    r   yellowz.TwilioServiceException.__str__.<locals>.yellow   r!   r   r.   z;
{red_error} {request_was}

{http_line}

{twilio_returned}
r/   r0   r1   z(no URI)r2   )r3   r4   r5   r6   z
{title_label}: {title}
Title)title_labelrK   z{detail_label}: {detail}
Detail)detail_labelrL   z0{code_label}: {code} | {status_label}: {status}
z
Error CodeStatus)
code_labelr   status_labelr   z
{validation_label}:
zValidation Errors)validation_labelz  {pointer}: {detail}
pointerz(unknown field)rL   z(no detail))r`   rL   r9   r:   r;   r8   r=   z - {0}z | Validation errors: {0}z, c              3      K   | ]6  }d j                  |j                  dd      |j                  dd             8 yw)z	{0} ({1})r`   ?rL   N)r,   get).0es     r   	<genexpr>z1TwilioServiceException.__str__.<locals>.<genexpr>   s<       $**155C+@!%%RUBVWs   <>)r>   r@   rA   rB   r.   r,   r   r   appendrK   rL   r   r   rN   rc   rP   rC   )	r   r    r$   r'   r*   rW   	msg_partserrorr   s	            r   rD   zTwilioServiceException.__str__|   s   	7s 	7s 	7	7 	7 	7	7 	7 	7	7 	7 	7	7# 	7# 	7 3::x(SZZ->->-@SZZ!,/ %&9 :  88 TXX>?!*-$)*V$W [ 	I ,33 %gtzz* 4  {{  077%*8_#DKK0 8  CJJ$\2c$))n-!&xDKK 01	 K  {{  -44)./B)C 5 
 "[[ E$$188$*599Y@Q+R$S#(99X}#E 9  ,33#$MNTYY 4  779%% (..t{{DJJGC{{xt{{33{{299II !%   Jr   )NNNrE   r8   )r   r	   r
   rF   r>   r?   r   r   r   r   rD   r   r   r   rI   rI   U   s    , !%"&15  	
   3- d38n-.  ,_ _r   rI   )	rA   typingr   r   r   	Exceptionr   r   rI   r   r   r   <module>rl      s9    
 ' '	i 	HG/ HGVF_ Fr   