o
    Th"'                     @   s  d dl m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mZmZ d dlZd dlZd dlZd dlZd dlZzddlmZ ddlmZ W n ey[   d dlmZ d dlZY nw d	Zd"ddZejdrle  edZej Z de!d
ee	e! e!f fddZ"ede!d
ed fddZ#de
d
e$fddZ%de
d
ee$ef fddZ&de'd
ee! fddZ(G dd dej)Z*ed d!Z+dS )#    )
namedtuple)contextmanager)TracebackType)Any	GeneratorListIOOptionalTupleTypeUnionN   )Lexicon)yamlz-%(name)s.%(module)s.%(funcName)s: %(message)sreturnc                   C   s   t jt jtd d S )N)levelformat)loggingbasicConfigDEBUG
LOG_FORMAT r   r   >/var/www/html/venv/lib/python3.10/site-packages/invoke/util.pyenable_logging   s   r   INVOKE_DEBUGinvokenamec                 C   s   |  d}|dd |d fS )zk
    Return key tuple for use sorting dotted task names, via e.g. `sorted`.

    .. versionadded:: 1.0
    .N)split)r   partsr   r   r   task_name_sort_key-   s   

r!   where)NNNc              	   c   s8    t  }t |  zd V  W t | d S t | w )N)osgetcwdchdir)r"   cwdr   r   r   cd?   s   
r'   streamc              	   C   s,   zt |  tW S  ttjfy   Y dS w )aq  
    Cleanly determine whether ``stream`` has a useful ``.fileno()``.

    .. note::
        This function helps determine if a given file-like object can be used
        with various terminal-oriented modules and functions such as `select`,
        `termios`, and `tty`. For most of those, a fileno is all that is
        required; they'll function even if ``stream.isatty()`` is ``False``.

    :param stream: A file-like object.

    :returns:
        ``True`` if ``stream.fileno()`` returns an integer, ``False`` otherwise
        (this includes when ``stream`` lacks a ``fileno`` method).

    .. versionadded:: 1.0
    F)
isinstancefilenointAttributeErrorioUnsupportedOperationr(   r   r   r   
has_filenoI   s
   r0   c                 C   s6   t | drt| jr|  S t| rt|  S dS )a  
    Cleanly determine whether ``stream`` is a TTY.

    Specifically, first try calling ``stream.isatty()``, and if that fails
    (e.g. due to lacking the method entirely) fallback to `os.isatty`.

    .. note::
        Most of the time, we don't actually care about true TTY-ness, but
        merely whether the stream seems to have a fileno (per `has_fileno`).
        However, in some cases (notably the use of `pty.fork` to present a
        local pseudoterminal) we need to tell if a given stream has a valid
        fileno but *isn't* tied to an actual terminal. Thus, this function.

    :param stream: A file-like object.

    :returns:
        A boolean depending on the result of calling ``.isatty()`` and/or
        `os.isatty`.

    .. versionadded:: 1.0
    isattyF)hasattrcallabler1   r0   r#   r*   r/   r   r   r   r1   a   s
   r1   objc                 C   s4   | j }|r| r|t| j krdS |  d S )zo
    Yield an object's first docstring line, or None if there was no docstring.

    .. versionadded:: 1.0
    Nr   )__doc__striptypelstrip
splitlines)r4   	docstringr   r   r   helpline   s   r;   c                       sj   e Zd ZdZdeddf fddZd fddZded	 fd
dZe	de
fddZdefddZ  ZS )ExceptionHandlingThreadaJ  
    Thread handler making it easier for parent to handle thread exceptions.

    Based in part on Fabric 1's ThreadHandler. See also Fabric GH issue #204.

    When used directly, can be used in place of a regular ``threading.Thread``.
    If subclassed, the subclass must do one of:

    - supply ``target`` to ``__init__``
    - define ``_run()`` instead of ``run()``

    This is because this thread's entire point is to wrap behavior around the
    thread's execution; subclasses could not redefine ``run()`` without
    breaking that functionality.

    .. versionadded:: 1.0
    kwargsr   Nc                    s(   t  jdi | d| _|| _d| _dS )z
        Create a new exception-handling thread instance.

        Takes all regular `threading.Thread` keyword arguments, via
        ``**kwargs`` for easier display of thread identity when raising
        captured exceptions.
        TNr   )super__init__daemonr=   exc_info)selfr=   	__class__r   r   r?      s
   z ExceptionHandlingThread.__init__c                    s   zt | drt| jr|   W d S t   W d S  tyB   t | _d}d}d| jv r4| jd j	}t
|| jd | Y d S w )N_runz-Encountered exception {!r} in thread for {!r}targetr   )r2   r3   rE   r>   runBaseExceptionsysrA   r=   __name__debugr   )rB   msgr   rC   r   r   rG      s   

zExceptionHandlingThread.runExceptionWrapperc                 C   s"   | j du rdS t| jg| j R  S )aP  
        If an exception occurred, return an `.ExceptionWrapper` around it.

        :returns:
            An `.ExceptionWrapper` managing the result of `sys.exc_info`, if an
            exception was raised during thread execution. If no exception
            occurred, returns ``None`` instead.

        .. versionadded:: 1.0
        N)rA   rM   r=   rB   r   r   r   	exception   s   
z!ExceptionHandlingThread.exceptionc                 C   s   |    o	| jduS )z
        Returns ``True`` if not alive and has a stored exception.

        Used to detect threads that have excepted & shut down.

        .. versionadded:: 1.0
        N)is_aliverA   rN   r   r   r   is_dead   s   zExceptionHandlingThread.is_deadc                 C   s   t | jd jS )NrF   )strr=   rJ   rN   r   r   r   __repr__   s   z ExceptionHandlingThread.__repr__r   N)rJ   
__module____qualname__r5   r   r?   rG   r	   rO   propertyboolrQ   rR   rS   __classcell__r   r   rC   r   r<      s    &r<   rM   zkwargs type value tracebackrT   ),collectionsr   
contextlibr   typesr   typingr   r   r   r   r	   r
   r   r   r-   r   r#   	threadingrI   vendor.lexiconr   vendorr   ImportErrorlexiconr   r   environget	getLoggerlogrK   rR   r!   r'   rX   r0   r1   objectr;   Threadr<   rM   r   r   r   r   <module>   s@    (

	!x