
    Dh8                    0   d Z ddlmZ ddlZddlZddlZddlmZ ej                  rddl	m
Z
 ddl	mZ ddlmZ  ed	      Zd
Z G d dej                         Zej$                  	 d	 	 	 	 	 	 	 dd       Zej$                  ddd       Z	 	 	 d	 	 	 	 	 	 	 ddZy)z/Threaded implementation.

Asyncio is supported
    )annotationsN   )class_decorator)	Awaitable)Callable)	ParamSpecSpec)Threadedthreadedc                       e Zd ZdZdZ	 	 	 d
	 	 	 	 	 	 	 d fdZedd       Zedd       Zedd       Z	ddZ
	 	 	 	 ddZ	 	 	 	 	 	 d fd	Z xZS )r
   z Run function in separate thread.)__name__daemon	__startedc           
         || _         || _        t        |      r*|}dt        |dt	        t        |                  z   | _        n
d|c}| _        t        | !  |       y)a  Run function in separate thread.

        :param name: New thread name.
                     If callable: use as wrapped function.
                     If none: use wrapped function name.
        :type name: typing.Optional[typing.Union[str, Callable[..., typing.Union[Awaitable, typing.Any]]]]
        :param daemon: Daemonize thread.
        :type daemon: bool
        :param started: Return started thread
        :type started: bool
        
Threaded: __name__N)func)	_Threaded__daemon_Threaded__startedcallablegetattrstrhash_Threaded__namesuper__init__)selfnamedaemonstartedr   	__class__s        t/var/www/fastuser/data/www/generator.snapmosaic.io/flask_app/venv/lib/python3.12/site-packages/threaded/_threaded.pyr   zThreaded.__init__.   s]    " %&D>MQD&2WT:sSWX\S]5_&_DK $dD$+d#    c                    | j                   S )z;Thread name.

        :rtype: typing.Optional[str]
        )r   r   s    r"   r   zThreaded.nameH   s     {{r#   c                    | j                   S )z6Start thread as daemon.

        :rtype: bool
        )r   r%   s    r"   r   zThreaded.daemonP   s     }}r#   c                    | j                   S )z5Return started thread.

        :rtype: bool
        )r   r%   s    r"   r    zThreaded.startedX   s     ~~r#   c                    | j                   j                   d| j                  d| j                  d| j                  dS )zLFor debug purposes.

        :return: repr data
        :rtype: str
        z(name=z	, daemon=z
, started=z, ))r!   r   r   r   r    r%   s    r"   __repr__zThreaded.__repr__`   s@     ..))*&Yt{{oU_`d`l`l_oorssr#   c           
           j                  |       j                  "dt        |dt        t	        |                  z   t        j                        d fd       }|S )a   Here should be constructed and returned real decorator.

        :param func: Wrapped function
        :type func: Callable[..., typing.Union[Awaitable, typing.Any]]
        :return: wrapped function
        :rtype: Callable[..., threading.Thread]
        r   r   c                     t        j                  | |j                        }j                  r|j	                          |S )zdThread getter.

            :return: Thread object
            :rtype: threading.Thread
            )targetr   argskwargsr   )	threadingThreadr   r    start)r-   r.   threadr   preparedr   s      r"   wrapperz/Threaded._get_function_wrapper.<locals>.wrapperx   s:     %%XDtTZcgcncnoF||Mr#   )r-   z	Spec.argsr.   zSpec.kwargsreturnzthreading.Thread)_await_if_requiredr   r   r   r   	functoolswraps)r   r   r4   r   r3   s   `  @@r"   _get_function_wrapperzThreaded._get_function_wrapperh   sb     04/F/Ft/L99<'$
CT
O"LLD 
	"		 
#		 r#   c                "    t        |   |i |S )zExecutable instance.

        :return: Thread object or Thread getter
        :rtype: Union[threading.Thread, Callable[..., threading.Thread]]
        )r   __call__)r   r-   r.   r!   s      r"   r;   zThreaded.__call__   s     w000r#   NFF)r   z@None | (str | Callable[..., Awaitable[typing.Any] | typing.Any])r   boolr    r=   r5   None)r5   
str | None)r5   r=   )r5   r   )r   z2Callable[Spec, Awaitable[typing.Any] | typing.Any]r5   Callable[..., threading.Thread])r-   z>Callable[..., Awaitable[typing.Any] | typing.Any] | typing.Anyr.   z
typing.Anyr5   z2threading.Thread | Callable[..., threading.Thread])r   
__module____qualname____doc__	__slots__r   propertyr   r   r    r)   r9   r;   __classcell__)r!   s   @r"   r
   r
   )   s    *3I RV	$N$ $ 	$
 
$4      tF	(<
1M
1 
1 
<	
1 
1r#   r
   c                     y)z+Overload: Call decorator without arguments.N r   r   r    s      r"   r   r          r#   c                     y)zOverload: Name is not callable.NrH   rI   s      r"   r   r      rJ   r#   c                    t        |       r8| dt        | dt        t        |                   z   } } t	        | ||      |      S t	        | ||      S )a  Run function in separate thread.

    :param name: New thread name.
                 If callable: use as wrapped function.
                 If none: use wrapped function name.
    :type name: typing.Union[None, str, Callable]
    :param daemon: Daemonize thread.
    :type daemon: bool
    :param started: Return started thread
    :type started: bool
    :return: Threaded instance, if called as function or argumented decorator, else callable wrapper
    :rtype: typing.Union[Threaded, Callable[..., threading.Thread]]
    r   r   rI   )r   r   r   r   r
   )r   r   r    r   s       r"   r   r      s_    $ ~L74Sd_+UUd
x

 
 	
 fg>>r#   )FF)r   zCallable[..., typing.Any]r   r=   r    r=   r5   r@   r<   )r   r?   r   r=   r    r=   r5   r
   )r   z&str | Callable[..., typing.Any] | Noner   r=   r    r=   r5   z*Threaded | Callable[..., threading.Thread])rC   
__future__r   r7   r/   typing r   TYPE_CHECKINGcollections.abcr   r   typing_extensionsr   r	   __all__BaseDecoratorr
   overloadr   rH   r#   r"   <module>rV      s   
 #    	)(+VD
"g1,, g1T KP6
#6-16DH6$6 6 * *
 48?
0?? ? 0	?r#   