
    5i.                        d Z ddlmZmZmZmZ ddlZddlZddlZddl	Z	ddl
Z
ddlmZ ddlZddlZddlZ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      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       Z# G d* d+e      Z$ G d, d-e      Z% G d. d/e      Z& G d0 d1e      Z' G d2 d3e'      Z( G d4 d5e      Z) G d6 d7e)      Z* G d8 d9e      Z+ G d: d;e      Z, G d< d=e      Z- G d> d?e.      Z/ G d@ dAe      Z0 G dB dCe1      Z2dD Z3dIdFZ4ejj                  jl                  ejj                  jn                  ejj                  jp                  ejj                  jr                  ejj                  jt                  ejv                  jx                  ejj                  jz                  ejz                  ee
j|                  e?fZ@	 ej                  j                  fZCe@eCz   ee+eDfz   ZEdEdeEddGdfdHZFy#  e.fZCY xY w)Jz)
Exceptions for the :mod:`dxpy` package.
    )print_functionunicode_literalsdivisionabsolute_importN)	HTTPError   c                       e Zd ZdZy)DXErrorz*Base class for exceptions in this package.N__name__
__module____qualname____doc__     q/home/marpiech/ifpan-abm-pgxpred/analysis/marpiech-gwas-test/venv/lib/python3.12/site-packages/dxpy/exceptions.pyr
   r
   $       4r   r
   c                   $    e Zd ZdZddZd Zd Zy)
DXAPIErrora  
    Exception for when the API server responds with a code that is not 200 (OK). See
    https://documentation.dnanexus.com/developer/api/protocols#errors for complete documentation of API errors,
    including those reflected by subclasses of this class.
    c                     |d   d   | _         |d   d   | _        d|d   v r|d   d   | _        nd | _        || _        || _        || _        y )Nerrortypemessagedetails)namemsgr   code	timestampreq_id)selfcontentr   r   r   s        r   __init__zDXAPIError.__init__-   s^    G$V,	7#I.(("7+I6DLDL	"r   c                    | j                   dz   t        | j                        z   }|dj                  | j                  | j
                        z  }| j                  | j                  j                  k7  r| j                  dz   |z   }|S )z,Returns a one-line description of the error.z, code z . Request Time={}, Request ID={}: )	r   strr   formatr   r   r   	__class__r   r    outputs     r   error_messagezDXAPIError.error_message8   sk    I%DII64;;DNNDKKXX99///YY%.Fr   c                     | j                         }| j                  r'|dt        j                  | j                  d      z   z  }|S )Nz

Details:    )indent)r*   r   jsondumpsr(   s     r   __str__zDXAPIError.__str__@   s:    ##%<<mdjja&HHHFr   N) r1   r   r   r   r   r"   r*   r0   r   r   r   r   r   '   s    
	r   r   c                       e Zd ZdZy)MalformedJSONz4 Raised when the input could not be parsed as JSON. Nr   r   r   r   r4   r4   F   s    >r   r4   c                       e Zd ZdZy)InvalidAuthenticationz3 Raised when the provided OAuth2 token is invalid. Nr   r   r   r   r6   r6   I       =r   r6   c                       e Zd ZdZy)PermissionDeniedz\ Raised when the supplied credentials have insufficient permissions to perform this action. Nr   r   r   r   r9   r9   L   s    fr   r9   c                       e Zd ZdZy)SpendingLimitExceededzg Raised when the spending limit has been reached for the account that would be billed for this action. Nr   r   r   r   r;   r;   O   s    qr   r;   c                       e Zd ZdZy)
OrgExpiredzP Raised when the organization that would be billed for this action has expired. Nr   r   r   r   r=   r=   R   s    Zr   r=   c                       e Zd ZdZy)ResourceNotFoundz@ Raised when a specified entity or resource could not be found. Nr   r   r   r   r?   r?   U       Jr   r?   c                       e Zd ZdZy)InvalidInputz Raised when the input is syntactically correct (JSON), but semantically incorrect (for example, a JSON array
    is provided where a hash was required; or a required parameter was missing, etc.). Nr   r   r   r   rB   rB   X   s    [r   rB   c                       e Zd ZdZy)InvalidStatez@ Raised when the operation is not allowed at this object state. Nr   r   r   r   rD   rD   \   r@   r   rD   c                       e Zd ZdZy)InvalidTypezD Raised when an object specified in the request is of invalid type. Nr   r   r   r   rF   rF   _   s    Nr   rF   c                       e Zd ZdZy)RateLimitConditionalz7 Raised when the rate of invalid requests is too high. Nr   r   r   r   rH   rH   b       Ar   rH   c                       e Zd ZdZy)InternalErrorz7 Raised when the server encountered an internal error. Nr   r   r   r   rK   rK   e   rI   r   rK   c                       e Zd ZdZy)ServiceUnavailablez9 Raised when an API service was temporarily unavailable. Nr   r   r   r   rM   rM   h   s    Cr   rM   c                       e Zd ZdZy)DXFileErrorz3Exception for :class:`dxpy.bindings.dxfile.DXFile`.Nr   r   r   r   rO   rO   k   r7   r   rO   c                       e Zd ZdZy)DXIncompleteReadsErrorzdException for :class:`dxpy.bindings.dxfile.DXFile` when returned read data is shorter than requestedNr   r   r   r   rQ   rQ   n   s    nr   rQ   c                       e Zd ZdZy)DXPartLengthMismatchErrorzQException raised by :class:`dxpy.bindings.dxfile.DXFile` on part length mismatch.Nr   r   r   r   rS   rS   q   s    [r   rS   c                       e Zd ZdZy)DXChecksumMismatchErrorzNException raised by :class:`dxpy.bindings.dxfile.DXFile` on checksum mismatch.Nr   r   r   r   rU   rU   t   s    Xr   rU   c                       e Zd ZdZy)DXSearchErrorz2Exception for :mod:`dxpy.bindings.search` methods.Nr   r   r   r   rW   rW   w   s    <r   rW   c                       e Zd ZdZy)DXAppletErrorz7Exception for :class:`dxpy.bindings.dxapplet.DXApplet`.Nr   r   r   r   rY   rY   z   rI   r   rY   c                       e Zd ZdZy)DXJobFailureErrorzJException produced by :class:`dxpy.bindings.dxjob.DXJob` when a job fails.Nr   r   r   r   r[   r[   }   s    Tr   r[   c                       e Zd ZdZy)ProgramErrorz*Deprecated. Use :class:`AppError` instead.Nr   r   r   r   r]   r]      r   r   r]   c                       e Zd ZdZy)AppErrora  
    Base class for fatal exceptions to be raised while using :mod:`dxpy` inside
    DNAnexus execution containers.

    This exception is thrown for user errors, and the error message is
    presented to the user. Throwing this exception will cause the Python
    execution template to write exception information into the file
    *job_error.json* in the current working directory, allowing reporting of
    the error state through the DNAnexus API.
    Nr   r   r   r   r_   r_          	r   r_   c                       e Zd ZdZy)AppInternalErrora  
    Base class for fatal exceptions to be raised while using :mod:`dxpy` inside
    DNAnexus execution containers.

    This exception is intended for internal App errors, whose message goes to
    the App developer. Throwing this exception will cause the Python execution
    template to write exception information into the file ``job_error.json`` in
    the current working directory, allowing reporting of the error state
    through the DNAnexus API.
    Nr   r   r   r   rb   rb      r`   r   rb   c                       e Zd ZdZy)AppInsufficientResourceErrora  
    Exception to be raised while using :mod:`dxpy` inside DNAnexus execution
    containers when a job fails due to insufficient resources (e.g., out of
    memory, storage).

    This exception is a subclass of :class:`AppInternalError` and is intended
    to provide a specific error type for resource-related failures, allowing
    job viewers to immediately understand the failure cause. Like its parent
    class, this exception will cause the Python execution template to write
    exception information into the file ``job_error.json`` in the current
    working directory, allowing reporting of the error state through the
    DNAnexus API.
    Nr   r   r   r   rd   rd      s    r   rd   c                       e Zd ZdZy)
DXCLIErrorzG
    Exception class for generic errors in the command-line client
    Nr   r   r   r   rf   rf          r   rf   c                       e Zd ZdZy)ContentLengthErrorzs
    Raised when actual content length received from the server does not
    match the "Content-Length" header
    Nr   r   r   r   ri   ri          r   ri   c                   "     e Zd ZdZ fdZ xZS )HTTPErrorWithContentz
    Specific variant of HTTPError with response content.

    This class was created to avoid appending content directly to error message
    which makes difficult to format log strings.
    c                 :    t         t        |   |       || _        y N)superr   r"   r!   )r    valuer!   r'   s      r   r"   zHTTPErrorWithContent.__init__   s    i'.r   )r   r   r   r   r"   __classcell__)r'   s   @r   rl   rl      s     r   rl   c                       e Zd ZdZy)BadJSONInReplyz
    Raised when the server returned invalid JSON in the response body. Possible reasons
    for this are the network connection breaking, or overload on the server.
    Nr   r   r   r   rs   rs      rj   r   rs   c                   "    e Zd ZdZd Zd Zd Zy)InvalidTLSProtocolz
    Raised when the connection to the server was reset due to an ssl protocol not supported.
    Only connections with TLS v1.2 will be accepted.
    c                      y rn   r   r    s    r   r"   zInvalidTLSProtocol.__init__   s    r   c                 
    d}|S )NztPlease refer to our blog post at https://blog.dnanexus.com/2017-09-23-upgrading-tls/ regarding upgrading to TLS 1.2.r   r(   s     r   r*   z InvalidTLSProtocol.error_message   s     Hr   c                 "    | j                         S rn   )r*   rw   s    r   r0   zInvalidTLSProtocol.__str__   s    !!##r   Nr2   r   r   r   ru   ru      s    $r   ru   c                       e Zd ZdZy)UrllibInternalErrorz9
    Exception class for AttributeError from urllib3
    Nr   r   r   r   r{   r{      rg   r   r{   c                 ~    ddl m dj                  fdt        j                  t        |       |       D              S )zEReturns a string containing the type and text of the exception.

       )fill
c              3   .   K   | ]  } |        y wrn   r   ).0liner~   s     r   	<genexpr>z#format_exception.<locals>.<genexpr>   s     XDT$ZXs   )utils.printingr~   join	tracebackformat_exception_onlyr   )er~   s    @r   format_exceptionr      s0     %99XI,K,KDQRGUV,WXXXr   r1   c                 0   ||j                   |fnt        j                         dd \  }}||rt        j                          njt        |t              r t        j                  j                  d       n:t        j                  ||      D ]!  }t        j                  j                  |       # t        j                  j                  |       |dk7  r0|j                  d      st        j                  j                  d       t        j                  |        y)a  Exits the program, printing information about the last exception (if
    any) and an optional error message.  Uses *exception* instead if provided.

    :param code: Exit code.
    :type code: integer (valid exit code, 0-255)
    :param message: Message to be printed after the exception information.
    :type message: string
    :param print_tb: If set to True, prints the exception traceback; otherwise, suppresses it.
    :type print_tb: boolean
    :type exception: an exception to use in place of the last exception raised
    N   z^C
r1   r   )r'   sysexc_infor   	print_exc
isinstanceKeyboardInterruptstderrwriter   endswithexit)r   r   print_tb	exceptionexc_type	exc_valuer   s          r   exit_with_exc_infor      s     '2 %..	:8;r8J Hi !	#45JJV$!77)L '

  &' JJW"}W--d3

HHTNr   Tc                    ||j                   dz   | z   } ||nt        j                         d   }t        |t              r|t        ||      r%t        t        | t        j                  dkD  |       y|rrt        |t              rbt        |dd      t        j                  k(  rDt        j                  dkD  rt        dt        j                         t        j                  d	       y|d}t        || d
|       y)a  Exits the program, printing information about the last exception (if
    any) and an optional error message.  Uses *exception* instead if provided.

    Uses **expected_exceptions** to set the error code decide whether to
    suppress the error traceback.

    :param message: Message to be printed after the exception information.
    :type message: string
    :param code: Exit code.
    :type code: integer (valid exit code, 0-255)
    :param expected_exceptions: Exceptions for which to exit with error code 3 (expected error condition) and suppress the stack trace (unless the _DX_DEBUG environment variable is set).
    :type expected_exceptions: iterable
    :param arg_parser: argparse.ArgumentParser object used in the program (optional)
    :param ignore_sigpipe: Whether to exit silently with code 3 when IOError with code EPIPE is raised. Default true.
    :type ignore_sigpipe: boolean
    :param exception: an exception to use in place of the last exception raised
    Nr$   r}   r   )r   r   errnozBroken pipe)filer   T)progr   r   r   
SystemExitr   EXPECTED_ERR_EXIT_STATUSdxpy_DEBUGIOErrorgetattrr   EPIPEprintr   r   )r   r   expected_exceptions
arg_parserignore_sigpiper   excs          r   err_exitr     s    & //D(72 ,)#,,.2CC#z"		C,	-3Wt{{UVbkl	JsG4gt9TX]XcXc9c;;?-cjj1<D449Mr   )r}   r1   FN)Gr   
__future__r   r   r   r   r   r.   r   r   socketurllib3.exceptionsr   r   urllib3sslr   	Exceptionr
   r   r4   r6   r9   r;   r=   r?   rB   rD   rF   rH   rK   rM   rO   rQ   rS   rU   rW   rY   r[   r]   r_   rb   rd   rf   ri   rl   
ValueErrorrs   ru   AttributeErrorr{   r   r   
exceptionsProtocolErrorNewConnectionErrorDecodeErrorConnectTimeoutErrorReadTimeoutErrorconnectionpoolHTTPExceptionSSLErrorr   ConnectionResetErrornetwork_exceptionsdecoderJSONDecodeErrorjson_exceptionsr   default_expected_exceptionsr   r   r   r   <module>r      s  " S R 
     (   
 5i 5 >?J ?>J >gz grJ r[ [Kz K[: [K: KO* OB: BBJ BD D>' >oW o\ \Yk Y=G =BG BU U57 5
| 

w 
#3  
 
9 
Z $ $. Y: ((66((;;((44((<<((99,,::((11llll*
- $||335O 1?Bj4>4EFG G  d8S`d D"N$!mOs   I. .I5