o
    Th/                     @   s  d Z ddlmZ ddlmZ ddlmZmZmZm	Z	m
Z
mZ er2ddlmZ ddlmZ ddlmZ G d	d
 d
eZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd  d eZd!ed"eeef fd#d$Z G d%d& d&eZ!G d'd( d(eZ"G d)d* d*e"Z#G d+d, d,eZ$d-S ).a   
Custom exception classes.

These vary in use case from "we needed a specific data structure layout in
exceptions used for message-passing" to simply "we needed to express an error
condition in a way easily told apart from other, truly unexpected errors".
    )pformat)format_exception)TYPE_CHECKINGAnyDictListOptionalTuple   )ParserContext)Result)ExceptionWrapperc                   @   s"   e Zd ZdededdfddZdS )CollectionNotFoundnamestartreturnNc                 C      || _ || _d S N)r   r   )selfr   r    r   D/var/www/html/venv/lib/python3.10/site-packages/invoke/exceptions.py__init__      
zCollectionNotFound.__init__)__name__
__module____qualname__strr   r   r   r   r   r      s    r   c                   @   sd   e Zd ZdZ	dddded ddfdd	Zdeeef fd
dZdefddZ	de
defddZdS )Failurea#  
    Exception subclass representing failure of a command execution.

    "Failure" may mean the command executed and the shell indicated an unusual
    result (usually, a non-zero exit code), or it may mean something else, like
    a ``sudo`` command which was aborted when the supplied password failed
    authentication.

    Two attributes allow introspection to determine the nature of the problem:

    * ``result``: a `.Result` instance with info about the command being
      executed and, if it ran to completion, how it exited.
    * ``reason``: a wrapped exception instance if applicable (e.g. a
      `.StreamWatcher` raised `WatcherError`) or ``None`` otherwise, in which
      case, it's probably a `Failure` subclass indicating its own specific
      nature, such as `UnexpectedExit` or `CommandTimedOut`.

    This class is only rarely raised by itself; most of the time `.Runner.run`
    (or a wrapper of same, such as `.Context.sudo`) will raise a specific
    subclass like `UnexpectedExit` or `AuthFailure`.

    .. versionadded:: 1.0
    Nresultr   reasonWatcherErrorr   c                 C   r   r   )r   r   )r   r   r   r   r   r   r   2      
zFailure.__init__c                 C   sb   d}d| j jvr|}n| j d}| j jrd}||fS d| j jvr'|}||fS | j d}||fS )a  
        Return stdout/err streams as necessary for error display.

        Subject to the following rules:

        - If a given stream was *not* hidden during execution, a placeholder is
          used instead, to avoid printing it twice.
        - Only the last 10 lines of stream text is included.
        - PTY-driven execution will lack stderr, and a specific message to this
          effect is returned instead of a stderr dump.

        :returns: Two-tuple of stdout, stderr strings.

        .. versionadded:: 1.3
        z already printedstdoutz n/a (PTYs have no stderr)stderr)r   hidetailpty)r   already_printedr"   r#   r   r   r   streams_for_display8   s   zFailure.streams_for_displayc                 C   s   |   S r   )_reprr   r   r   r   __repr__V   s   zFailure.__repr__kwargsc                 K   s>   d}d}|rdd dd | D  }|| jj| jj|S )zP
        Return ``__repr__``-like value from inner result + any kwargs.
        z<{}: cmd={!r}{}>  c                 s   s     | ]\}}d  ||V  qdS )z{}={}N)format).0keyvaluer   r   r   	<genexpr>b   s    
z Failure._repr.<locals>.<genexpr>)joinitemsr/   	__class__r   r   command)r   r,   templaterestr   r   r   r)   Y   s   
zFailure._reprr   )r   r   r   __doc__r   r   r	   r   r(   r+   r   r)   r   r   r   r   r      s    
r   c                       s8   e Zd ZdZdefddZdedef fddZ  ZS )UnexpectedExita  
    A shell command ran to completion but exited with an unexpected exit code.

    Its string representation displays the following:

    - Command executed;
    - Exit code;
    - The last 10 lines of stdout, if it was hidden;
    - The last 10 lines of stderr, if it was hidden and non-empty (e.g.
      pty=False; when pty=True, stderr never happens.)

    .. versionadded:: 1.0
    r   c                 C   s0   |   \}}| jj}| jj}d}|||||S )NzZEncountered a bad command exit code!

Command: {!r}

Exit code: {}

Stdout:{}

Stderr:{}

)r(   r   r7   exitedr/   )r   r"   r#   r7   r<   r8   r   r   r   __str__y   s
   zUnexpectedExit.__str__r,   c                    s"   | d| jj t jdi |S )Nr<   r   )
setdefaultr   r<   superr)   )r   r,   r6   r   r   r)      s   zUnexpectedExit._repr)	r   r   r   r:   r   r=   r   r)   __classcell__r   r   r@   r   r;   j   s    r;   c                       sJ   e Zd ZdZdddeddf fddZdefd	d
ZdefddZ  Z	S )CommandTimedOutzK
    Raised when a subprocess did not exit within a desired timeframe.
    r   r   timeoutr   Nc                       t  | || _d S r   )r?   r   rC   )r   r   rC   r@   r   r   r      s   
zCommandTimedOut.__init__c                 C   s   | j | jdS )N)rC   )r)   rC   r*   r   r   r   r+         zCommandTimedOut.__repr__c                 C   s*   |   \}}| jj}d}|| j|||S )NzRCommand did not complete within {} seconds!

Command: {!r}

Stdout:{}

Stderr:{}

)r(   r   r7   r/   rC   )r   r"   r#   r7   r8   r   r   r   r=      s   	zCommandTimedOut.__str__)
r   r   r   r:   intr   r   r+   r=   rA   r   r   r@   r   rB      s
    rB   c                   @   s4   e Zd ZdZdddeddfddZdefd	d
ZdS )AuthFailurea6  
    An authentication failure, e.g. due to an incorrect ``sudo`` password.

    .. note::
        `.Result` objects attached to these exceptions typically lack exit code
        information, since the command was never fully executed - the exception
        was raised instead.

    .. versionadded:: 1.0
    r   r   promptr   Nc                 C   r   r   )r   rH   )r   r   rH   r   r   r   r      r   zAuthFailure.__init__c                 C   s   d}| | jS )Nz3The password submitted to prompt {!r} was rejected.)r/   rH   )r   errr   r   r   r=      s   zAuthFailure.__str__)r   r   r   r:   r   r   r=   r   r   r   r   rG      s    rG   c                       s6   e Zd ZdZ	d	deded ddf fddZ  ZS )

ParseErrorz
    An error arising from the parsing of command-line flags/arguments.

    Ambiguous input, invalid task names, invalid flags, etc.

    .. versionadded:: 1.0
    Nmsgcontextr   r   c                    rD   r   )r?   r   rL   )r   rK   rL   r@   r   r   r      s   
zParseError.__init__r   )r   r   r   r:   r   r   r   rA   r   r   r@   r   rJ      s    	rJ   c                   @   sD   e Zd ZdZ	d
dee dee ddfddZedefdd	Z	dS )Exita  
    Simple custom stand-in for SystemExit.

    Replaces scattered sys.exit calls, improves testability, allows one to
    catch an exit request without intercepting real SystemExits (typically an
    unfriendly thing to do, as most users calling `sys.exit` rather expect it
    to truly exit.)

    Defaults to a non-printing, exit-0 friendly termination behavior if the
    exception is uncaught.

    If ``code`` (an int) given, that code is used to exit.

    If ``message`` (a string) given, it is printed to standard error, and the
    program exits with code ``1`` by default (unless overridden by also giving
    ``code`` explicitly.)

    .. versionadded:: 1.0
    Nmessagecoder   c                 C   r   r   )rN   _code)r   rN   rO   r   r   r   r      r!   zExit.__init__c                 C   s   | j d ur| j S | jrdS dS )Nr
   r   )rP   rN   r*   r   r   r   rO      s   
z	Exit.code)NN)
r   r   r   r:   r   r   rF   r   propertyrO   r   r   r   r   rM      s    
rM   c                   @      e Zd ZdZdS )PlatformErrora   
    Raised when an illegal operation occurs for the current platform.

    E.g. Windows users trying to use functionality requiring the ``pty``
    module.

    Typically used to present a clearer error message to the user.

    .. versionadded:: 1.0
    Nr   r   r   r:   r   r   r   r   rS          rS   c                   @   rR   )AmbiguousEnvVarze
    Raised when loading env var config keys has an ambiguous target.

    .. versionadded:: 1.0
    NrT   r   r   r   r   rV          rV   c                   @   rR   )UncastableEnvVara  
    Raised on attempted env var loads whose default values are too rich.

    E.g. trying to stuff ``MY_VAR="foo"`` into ``{'my_var': ['uh', 'oh']}``
    doesn't make any sense until/if we implement some sort of transform option.

    .. versionadded:: 1.0
    NrT   r   r   r   r   rX   
      	rX   c                   @   rR   )UnknownFileTypezi
    A config file of an unknown type was specified and cannot be loaded.

    .. versionadded:: 1.0
    NrT   r   r   r   r   rZ     rW   rZ   c                   @   rR   )UnpicklableConfigMemberaw  
    A config file contained module objects, which can't be pickled/copied.

    We raise this more easily catchable exception instead of letting the
    (unclearly phrased) TypeError bubble out of the pickle module. (However, to
    avoid our own fragile catching of that error, we head it off by explicitly
    testing for module members.)

    .. versionadded:: 1.0.2
    NrT   r   r   r   r   r[   !  rU   r[   r,   r   c                 C   sv   i }|   D ]2\}}|}|dkr4g }|D ]}|}t|dr.t|dkr.d}|dd |g }|| q|||< q|S )z
    Return print-friendly version of a thread-related ``kwargs`` dict.

    Extra care is taken with ``args`` members which are very long iterables -
    those need truncating to be useful.
    args__len__
   z2<... remainder truncated during error display ...>N)r5   hasattrlenappend)r,   	printabler1   r2   itemargnew_argrK   r   r   r   _printable_kwargs0  s   
rf   c                   @   sH   e Zd ZU dZe Zed ed< ded ddfddZ	de
fd	d
ZdS )ThreadExceptiona  
    One or more exceptions were raised within background threads.

    The real underlying exceptions are stored in the `exceptions` attribute;
    see its documentation for data structure details.

    .. note::
        Threads which did not encounter an exception, do not contribute to this
        exception object and thus are not present inside `exceptions`.

    .. versionadded:: 1.0
    )r   .
exceptionsr   r   Nc                 C   s   t || _d S r   )tuplerh   )r   rh   r   r   r   r   b  rE   zThreadException.__init__c                 C   sv   g }| j D ]}d}||tt|jdt|j|j	|j
 qt| j ddd | j D d|f}dj| S )NzThread args: {}

{}
z, c                 s   s    | ]}|j jV  qd S r   )typer   )r0   xr   r   r   r3   r  s    z*ThreadException.__str__.<locals>.<genexpr>z

z-
Saw {} exceptions within threads ({}):


{}
)rh   ra   r/   r   rf   r,   r4   r   rk   r2   	tracebackr`   )r   detailsrl   detailr\   r   r   r   r=   e  s"   
zThreadException.__str__)r   r   r   r:   ri   rh   r	   __annotations__r   r   r   r=   r   r   r   r   rg   F  s
   
 rg   c                   @   rR   )r    a  
    Generic parent exception class for `.StreamWatcher`-related errors.

    Typically, one of these exceptions indicates a `.StreamWatcher` noticed
    something anomalous in an output stream, such as an authentication response
    failure.

    `.Runner` catches these and attaches them to `.Failure` exceptions so they
    can be referenced by intermediate code and/or act as extra info for end
    users.

    .. versionadded:: 1.0
    NrT   r   r   r   r   r      s    r    c                   @   rR   )ResponseNotAcceptedz
    A responder/watcher class noticed a 'bad' response to its submission.

    Mostly used by `.FailingResponder` and subclasses, e.g. "oh dear I
    autosubmitted a sudo password and it was incorrect."

    .. versionadded:: 1.0
    NrT   r   r   r   r   rq     rY   rq   c                   @   rR   )SubprocessPipeErrora#  
    Some problem was encountered handling subprocess pipes (stdout/err/in).

    Typically only for corner cases; most of the time, errors in this area are
    raised by the interpreter or the operating system, and end up wrapped in a
    `.ThreadException`.

    .. versionadded:: 1.3
    NrT   r   r   r   r   rr     s    
rr   N)%r:   pprintr   rm   r   typingr   r   r   r   r   r	   parserr   runnersr   utilr   	Exceptionr   r   r;   rB   rG   rJ   rM   rS   rV   rX   rZ   r[   r   rf   rg   r    rq   rr   r   r   r   r   <module>   s2     Q%"

9