Ë
    "V.jC=  ã            !       ó  — d dl Z d dlZd dlZd dl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
mZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZmZ d dlZd	d
lmZ d	dlmZmZmZm Z  erd dlm!Z! dZ" ejF                  d«      Z$dddd e«       d ddddd	dddœdee%z  de%e
def   z  de&edf   de'e%ef   dz  ddde
e(e   gdf   dz  de
ee%ge)f   dz  d e*d!e+d"e+d#e)dz  d$e+d%e+d&e)d'e)d(e+f d)„Z,dddd e«       d dddddd*œdee%z  de%e
def   z  de&edf   de'e%ef   dz  ddde
e(e   gef   dz  de
ee%ge)f   dz  d e*d!e+d"e+d#e)dz  d&e)d'e)d(e+fd+„Z- ed,«      Z.d-e%d(e/e%   fd.„Z0	 dAde%e
def   z  dd/de&edf   de'e%ef   dz  d0e(e   dz  d(d1fd2„Z1de%e
def   z  d(d/fd3„Z2 G d4„ d1«      Z3d5e%d6e%dz  de&edf   de'e%ef   d(df
d7„Z4d8e%d(efd9„Z5d(e%dz  fd:„Z6e jn                  d6e%dz  d(ed;   fd<„«       Z8d=e+d>ed(dfd?„Z9dBd@„Z:y)Cé    N)ÚCallableÚ	Generator)Úimport_module)Úget_context)ÚSpawnProcess)ÚPath)Úsleep)ÚTYPE_CHECKINGÚAnyé   )ÚDefaultFilter)ÚChangeÚ
FileChangeÚawatchÚwatch)ÚLiteral)Úrun_processÚarun_processÚdetect_target_typeÚimport_stringzwatchfiles.main© Úautoi@  é2   é   TF)ÚargsÚkwargsÚtarget_typeÚcallbackÚwatch_filterÚgrace_periodÚdebounceÚstepÚdebugÚsigint_timeoutÚsigkill_timeoutÚ	recursiveÚignore_permission_deniedÚpathsÚtarget.r   r   r   z&Literal['function', 'command', 'auto']r   r   r    r!   r"   r#   r$   r%   r&   r'   Úreturnc                 ó®  — |dk(  rt        | «      }t        j                  d| |«       t        «        t	        | |||«      }d}|r!t        j                  d|«       t        |«       	 t        |||||	d||dœŽD ]5  }|xr  ||«       |j                  |
|¬«       t	        | ||||«      }|dz  }Œ7 	 |j                  «        |S # |j                  «        w xY w)	u†  
    Run a process and restart it upon file changes.

    `run_process` can work in two ways:

    * Using `multiprocessing.Process` â€  to run a python function
    * Or, using `subprocess.Popen` to run a command

    !!! note

        **â€ ** technically `multiprocessing.get_context('spawn').Process` to avoid forking and improve
        code reload/import.

    Internally, `run_process` uses [`watch`][watchfiles.watch] with `raise_interrupt=False` so the function
    exits cleanly upon `Ctrl+C`.

    Args:
        *paths: matches the same argument of [`watch`][watchfiles.watch]
        target: function or command to run
        args: arguments to pass to `target`, only used if `target` is a function
        kwargs: keyword arguments to pass to `target`, only used if `target` is a function
        target_type: type of target. Can be `'function'`, `'command'`, or `'auto'` in which case
            [`detect_target_type`][watchfiles.run.detect_target_type] is used to determine the type.
        callback: function to call on each reload, the function should accept a set of changes as the sole argument
        watch_filter: matches the same argument of [`watch`][watchfiles.watch]
        grace_period: number of seconds after the process is started before watching for changes
        debounce: matches the same argument of [`watch`][watchfiles.watch]
        step: matches the same argument of [`watch`][watchfiles.watch]
        debug: matches the same argument of [`watch`][watchfiles.watch]
        sigint_timeout: the number of seconds to wait after sending sigint before sending sigkill
        sigkill_timeout: the number of seconds to wait after sending sigkill before raising an exception
        recursive: matches the same argument of [`watch`][watchfiles.watch]

    Returns:
        number of times the function was reloaded.

    ```py title="Example of run_process running a function"
    from watchfiles import run_process

    def callback(changes):
        print('changes detected:', changes)

    def foobar(a, b):
        print('foobar called with:', a, b)

    if __name__ == '__main__':
        run_process('./path/to/dir', target=foobar, args=(1, 2), callback=callback)
    ```

    As well as using a `callback` function, changes can be accessed from within the target function,
    using the `WATCHFILES_CHANGES` environment variable.

    ```py title="Example of run_process accessing changes"
    from watchfiles import run_process

    def foobar(a, b, c):
        # changes will be an empty list "[]" the first time the function is called
        changes = os.getenv('WATCHFILES_CHANGES')
        changes = json.loads(changes)
        print('foobar called due to changes:', changes)

    if __name__ == '__main__':
        run_process('./path/to/dir', target=foobar, args=(1, 2, 3))
    ```

    Again with the target as `command`, `WATCHFILES_CHANGES` can be used
    to access changes.

    ```bash title="example.sh"
    echo "changers: ${WATCHFILES_CHANGES}"
    ```

    ```py title="Example of run_process running a command"
    from watchfiles import run_process

    if __name__ == '__main__':
        run_process('.', target='./example.sh')
    ```
    r   úrunning "%s" as %sr   ú3sleeping for %s seconds before watching for changesF)r   r!   r"   r#   Úraise_interruptr&   r'   )r$   r%   r   )r   Úloggerr#   Úcatch_sigtermÚstart_processr	   r   Ústop)r)   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   ÚprocessÚreloadsÚchangess                     úPC:\xampp\htdocs\tradingbinance\backend\.venv\Lib\site-packages\watchfiles/run.pyr   r      sà   € ð@ �fÒÜ(¨Ó0ˆä
‡L�LÐ% v¨{Ô;Ü„OÜ˜F K°°vÓ>€GØ€GáÜ�‰ÐJÈLÔYÜˆlÔðÜØØ%ØØØØ!ØØ%=õ	
ˆGð Ò*™ 'Ó*øØ�L‰L¨ÈˆLÔXÜ# F¨K¸¸vÀwÓOˆGØ�q‰L‰Gñ	
ð 	�‰ŒØ€Nøð 	�‰�ús   Á&A	C ÃC)r   r   r   r   r   r    r!   r"   r#   r&   r'   c           
   ‡   ó  K  — ddl }|dk(  rt        | «      }t        j                  d| |«       t	        «        t
        j                  j                  t        | |||«      ƒ d{  –—† }d}|r3t        j                  d|«       t        j                  |«      ƒ d{  –—†  t        |||||	|
|dœŽ2 3 d{  –—† }|�# ||«      }|j                  |«      r
|ƒ d{  –—†  t
        j                  j                  |j                  «      ƒ d{  –—†  t
        j                  j                  t        | ||||«      ƒ d{  –—† }|dz  }Œ•7 Œà7 Œ«7 Œ”7 Œq7 ŒB7 Œ6 t
        j                  j                  |j                  «      ƒ d{  –—†7   |S ­w)a  
    Async equivalent of [`run_process`][watchfiles.run_process], all arguments match those of `run_process` except
    `callback` which can be a coroutine.

    Starting and stopping the process and watching for changes is done in a separate thread.

    As with `run_process`, internally `arun_process` uses [`awatch`][watchfiles.awatch], however `KeyboardInterrupt`
    cannot be caught and suppressed in `awatch` so these errors need to be caught separately, see below.

    ```py title="Example of arun_process usage"
    import asyncio
    from watchfiles import arun_process

    async def callback(changes):
        await asyncio.sleep(0.1)
        print('changes detected:', changes)

    def foobar(a, b):
        print('foobar called with:', a, b)

    async def main():
        await arun_process('.', target=foobar, args=(1, 2), callback=callback)

    if __name__ == '__main__':
        try:
            asyncio.run(main())
        except KeyboardInterrupt:
            print('stopped via KeyboardInterrupt')
    ```
    r   Nr   r,   r-   )r   r!   r"   r#   r&   r'   r   )Úinspectr   r/   r#   r0   ÚanyioÚ	to_threadÚrun_syncr1   r	   r   Úisawaitabler2   )r)   r   r   r   r   r   r    r!   r"   r#   r&   r'   r(   r8   r3   r4   r5   Úrs                     r6   r   r   ž   s[  è ø€ óZ à�fÒÜ(¨Ó0ˆä
‡L�LÐ% v¨{Ô;Ü„OÜ—O‘O×,Ñ,¬]¸FÀKÐQUÐW]Ó^×^€GØ€GáÜ�‰ÐJÈLÔYÜ�k‰k˜,Ó'×'Ð'äØ	Ø!ØØØØØ!9ó÷ ˆgð ÐÙ˜Ó!ˆAØ×"Ñ" 1Ô%Ø—�ä�o‰o×&Ñ& w§|¡|Ó4×4Ð4ÜŸ™×0Ñ0´ÀÈÐUYÐ[aÐcjÓk×kˆØ�1‰‰ð/ _øð
 	(øðøð øà4øØkøðô" �/‰/×
"Ñ
" 7§<¡<Ó
0×0Ñ0Ø€NùsŠ   ‚A FÁ"EÁ#6FÂEÂFÂ.EÂ2EÂ3EÂ6!FÃE	Ã0FÄEÄ	/FÄ8EÄ9FÅFÅEÅ	FÅFÅFÅ-FÅ<E?Å=FÚspawnÚcmdc                 óŽ   — dd l }|j                  «       j                  j                  «       dk7  }t	        j
                  | |¬«      S )Nr   Úwindows)Úposix)ÚplatformÚunameÚsystemÚlowerÚshlexÚsplit)r?   rC   rB   s      r6   Ú	split_cmdrI   ó   s6   € Ûà�N‰NÓ×#Ñ#×)Ñ)Ó+¨yÑ8€EÜ�;‰;�s %Ô(Ð(ó    zLiteral['function', 'command']r5   ÚCombinedProcessc                 ó2  — |€d}n8t        j                  |D ��cg c]  \  }}|j                  «       |g‘Œ c}}«      }|t        j                  d<   |dk(  rb|xs i }t        | t        «      r| t        «       ||f}t        }i }n| }t        j                  |||¬«      }	|	j                  «        t#        |	«      S |s|rt        j                  d«       t        | t        «      sJ d«       ‚t        | «      }
t        j                   |
«      }	t#        |	«      S c c}}w )Nz[]ÚWATCHFILES_CHANGESÚfunction)r)   r   r   z-ignoring args and kwargs for "command" targetz+target must be a string to run as a command)ÚjsonÚdumpsÚraw_strÚosÚenvironÚ
isinstanceÚstrÚget_tty_pathÚrun_functionÚspawn_contextÚProcessÚstartr/   ÚwarningrI   Ú
subprocessÚPopenrK   )r)   r   r   r   r5   Úchanges_env_varÚcÚpÚtarget_r3   Ú
popen_argss              r6   r1   r1   ú   s  € ð €Ø‰äŸ*™*Á7Ô%KÁ7¹4¸1¸a q§y¡y£{°AÒ&6À7Ò%KÓLˆà'6„B‡J�JÐ#Ñ$ð �jÒ Ø’˜2ˆÜ�fœcÔ"Øœ<›>¨4°Ð7ˆDÜ"ˆGØ‰FàˆGä×'Ñ'¨w¸TÈ&Ð'ÓQˆØ�‰Œô ˜7Ó#Ð#ñ ‘6Ü�N‰NÐJÔKä˜&¤#Ô&ÐUÐ(UÓUÐ&Ü˜vÓ&ˆ
Ü×"Ñ" :Ó.ˆÜ˜7Ó#Ð#ùó/ &Ls   šD
c                 óx   — t        | t        «      sy| j                  d«      ryt        j                  d| «      ryy)a^  
    Used by [`run_process`][watchfiles.run_process], [`arun_process`][watchfiles.arun_process]
    and indirectly the CLI to determine the target type with `target_type` is `auto`.

    Detects the target type - either `function` or `command`. This method is only called with `target_type='auto'`.

    The following logic is employed:

    * If `target` is not a string, it is assumed to be a function
    * If `target` ends with `.py` or `.sh`, it is assumed to be a command
    * Otherwise, the target is assumed to be a function if it matches the regex `[a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)+`

    If this logic does not work for you, specify the target type explicitly using the `target_type` function argument
    or `--target-type` command line argument.

    Args:
        target: The target value

    Returns:
        either `'function'` or `'command'`
    rN   )z.pyz.shÚcommandz[a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)+)rT   rU   ÚendswithÚreÚ	fullmatch)r)   s    r6   r   r     s5   € ô, �fœcÔ"ØØ	�‰˜Ô	(ØÜ	�‰Ð8¸&Ô	AØàrJ   c                   óx   — e Zd Zdd„Zddededdfd„Zdefd„Zedefd„«       Z	d	eddfd
„Z
ededz  fd„«       Zy)rK   c                 ó8   — || _         | j                  €J d«       ‚y )Nzprocess not yet spawned©Ú_pÚpid)Úselfr`   s     r6   Ú__init__zCombinedProcess.__init__?  s   € ØˆŒØ�x‰xÐ#Ð>Ð%>Ó>Ñ#rJ   r$   r%   r*   Nc                 óš  — t         j                  j                  dd «       | j                  «       rÌt        j                  d«       t        j                  | j                  t        j                  «       	 | j                  |«       | j                  €Ut        j                  d«       t        j                  | j                  t        j                  «       | j                  |«       y t        j                  d«       y t        j                  d| j                  «       y # t        j                  $ r t        j                  d|«       Y ŒÃw xY w)NrM   zstopping process...z!SIGINT timed out after %r secondsz+process has not terminated, sending SIGKILLzprocess stoppedz#process already dead, exit code: %d)rR   rS   ÚpopÚis_aliver/   r#   Úkillrl   ÚsignalÚSIGINTÚjoinr\   ÚTimeoutExpiredr[   ÚexitcodeÚSIGKILL)rm   r$   r%   s      r6   r2   zCombinedProcess.stopC  sØ   € Ü
�
‰
�‰Ð+¨TÔ2Ø�=‰=Œ?Ü�L‰LÐ.Ô/ä�G‰G�D—H‘HœfŸm™mÔ,ðØ—	‘	˜.Ô)ð �}‰}Ð$Ü—‘ÐLÔMÜ—‘˜Ÿ™¤&§.¡.Ô1Ø—	‘	˜/Õ*ä—‘Ð.Õ/ä�N‰NÐ@À$Ç-Á-ÕPøô ×,Ñ,ò ô —‘ÐBÀNÔSÙð	ús   Á5D Ä)E
Å	E
c                 ó¢   — t        | j                  t        «      r| j                  j                  «       S | j                  j	                  «       d u S ©N)rT   rk   r   rq   Úpoll©rm   s    r6   rq   zCombinedProcess.is_alive[  s8   € Ü�d—g‘gœ|Ô,Ø—7‘7×#Ñ#Ó%Ð%à—7‘7—<‘<“> TÐ)Ð)rJ   c                 ó.   — | j                   j                  S rz   rj   r|   s    r6   rl   zCombinedProcess.pida  s   € ð �w‰w�{‰{ÐrJ   Útimeoutc                 ó¦   — t        | j                  t        «      r| j                  j                  |«       y | j                  j	                  |«       y rz   )rT   rk   r   ru   Úwait)rm   r~   s     r6   ru   zCombinedProcess.joinf  s0   € Ü�d—g‘gœ|Ô,Ø�G‰G�L‰L˜Õ!à�G‰G�L‰L˜Õ!rJ   c                 óŽ   — t        | j                  t        «      r| j                  j                  S | j                  j                  S rz   )rT   rk   r   rw   Ú
returncoder|   s    r6   rw   zCombinedProcess.exitcodel  s0   € ä�d—g‘gœ|Ô,Ø—7‘7×#Ñ#Ð#à—7‘7×%Ñ%Ð%rJ   )r`   z&SpawnProcess | subprocess.Popen[bytes])r   r   )Ú__name__Ú
__module__Ú__qualname__rn   Úintr2   Úboolrq   Úpropertyrl   ru   rw   r   rJ   r6   rK   rK   >  s~   „ ó?ñQ 3ð Q¸Sð QÈó Qð0*˜$ó *ð ð�Sò ó ðð"˜Cð " Dó "ð ð&˜# ™*ò &ó ñ&rJ   rN   Útty_pathc                 ój   — t        |«      5  t        | «      } ||i |¤Ž d d d «       y # 1 sw Y   y xY wrz   )Úset_ttyr   )rN   r‰   r   r   Úfuncs        r6   rW   rW   t  s-   € Ü	�Õ	Ü˜XÓ&ˆÙˆdÐ�fÒ÷ 
×	Ñ	ús   Œ)©2Údotted_pathc                 ó  — 	 | j                  d«      j                  dd«      \  }}t	        |«      }	 t        ||«      S # t        $ r}t        d| › d�«      |‚d}~ww xY w# t        $ r}t        d|› d|› d	�«      |‚d}~ww xY w)
zº
    Stolen approximately from django. Import a dotted module path and return the attribute/class designated by the
    last name in the path. Raise ImportError if the import fails.
    Ú Ú.r   Ú"z!" doesn't look like a module pathNzModule "z" does not define a "z" attribute)ÚstripÚrsplitÚ
ValueErrorÚImportErrorr   ÚgetattrÚAttributeError)r�   Úmodule_pathÚ
class_nameÚeÚmodules        r6   r   r   z  s§   € ð
VØ"-×"3Ñ"3°CÓ"8×"?Ñ"?ÀÀQÓ"GÑˆ�Zô ˜;Ó'€FðgÜ�v˜zÓ*Ð*øô ò VÜ˜A˜k˜]Ð*LÐMÓNÐTUÐUûðVûô ò gÜ˜H [ MÐ1FÀzÀlÐR]Ð^Ó_ÐefÐfûðgús,   ‚$> ²A ¾	AÁAÁAÁ	B Á(A;Á;B c                  ó˜   — 	 t        j                  t        j                  j	                  «       «      S # t
        $ r Y yt        $ r Y yw xY w)zr
    Return the path to the current TTY, if any.

    Virtually impossible to test in pytest, hence no cover.
    z/dev/ttyN)rR   ÚttynameÚsysÚstdinÚfilenoÚOSErrorr—   r   rJ   r6   rV   rV   ‹  s@   € ðÜ�z‰zœ#Ÿ)™)×*Ñ*Ó,Ó-Ð-øÜò áÜò áðús   ‚03 ³	A	¾A	ÁA	)NNNc              #   ó¢   K  — | r&	 t        | «      5 }|t        _        d –— d d d «       y y d –— y # 1 sw Y   ŒxY w# t        $ r d –— Y y w xY w­wrz   )Úopenrž   rŸ   r¡   )r‰   Úttys     r6   r‹   r‹   ›  sG   è ø€ áð	Ü�h” 3Ø””	Û÷  ‘ô 	÷  �ûô ò 	åð	üs5   ‚A†< ‘0¡< ©A°9µ< ¼AÁ	AÁAÁAÚsignumÚ_framec                 ó`   — t         j                  dt        j                  | «      «       t        ‚)Nz-received signal %s, raising KeyboardInterrupt)r/   r[   rs   ÚSignalsÚKeyboardInterrupt)r¥   r¦   s     r6   Úraise_keyboard_interruptrª   ª  s!   € Ü
‡N�NÐBÄFÇNÁNÐSYÓDZÔ[Ü
ÐrJ   c                  ó¤   — t         j                  dt        j                  «       «       t	        j                  t        j
                  t        «       y)a  
    Catch SIGTERM and raise KeyboardInterrupt instead. This means watchfiles will stop quickly
    on `docker compose stop` and other cases where SIGTERM is sent.

    Without this the watchfiles process will be killed while a running process will continue uninterrupted.
    z8registering handler for SIGTERM on watchfiles process %dN)r/   r#   rR   Úgetpidrs   ÚSIGTERMrª   r   rJ   r6   r0   r0   ¯  s,   € ô ‡L�LÐKÌRÏYÉYË[ÔYÜ
‡M�M”&—.‘.Ô":Õ;rJ   rz   )r*   N);Ú
contextlibrO   ÚloggingrR   rf   rG   rs   r\   rž   Úcollections.abcr   r   Ú	importlibr   Úmultiprocessingr   Úmultiprocessing.contextr   Úpathlibr   Útimer	   Útypingr
   r   r9   Úfiltersr   Úmainr   r   r   r   r   Ú__all__Ú	getLoggerr/   rU   ÚtupleÚdictÚsetr‡   Úfloatr†   r   r   rX   ÚlistrI   r1   r   rK   rW   r   rV   Úcontextmanagerr‹   rª   r0   r   rJ   r6   Ú<module>rÁ      s   ðÛ Û Û Û 	Û 	Û Û Û Û 
ß /Ý #Ý 'Ý 0Ý Ý ß %ã å "ß 3Ó 3áÝà
N€Ø	ˆ×	Ñ	Ð,Ó	-€ð Ø$(Ø<BØ9=Ù9F»ØØØØØØØØ%*ò}Ø�3‰Jð}à�(˜3 ˜8Ñ$Ñ$ð}ð ��S�‰/ð}ð ��c�‰N˜TÑ!ð	}ð
 :ð}ð ˜˜J™Ð(¨$Ð.Ñ/°$Ñ6ð}ð ˜F C˜=¨$Ð.Ñ/°$Ñ6ð}ð ð}ð ð}ð ð}ð �$‰;ð}ð ð}ð ð}ð ð}ð #ð}ð  	ó!}ðF Ø$(Ø<BØ8<Ù9F»ØØØØØØ%*òMØ�3‰JðMà�(˜3 ˜8Ñ$Ñ$ðMð ��S�‰/ðMð ��c�‰N˜TÑ!ð	Mð
 :ðMð ˜˜J™Ð(¨#Ð-Ñ.°Ñ5ðMð ˜F C˜=¨$Ð.Ñ/°$Ñ6ðMð ðMð ðMð ðMð �$‰;ðMð ðMð #ðMð 	óMñd ˜GÓ$€ð)�3ð )˜4 ™9ó )ð '+ñ!$Ø�(˜3 ˜8Ñ$Ñ$ð!$à1ð!$ð ��S�‰/ð!$ð ��c�‰N˜TÑ!ð	!$ð
 �‰_˜tÑ#ð!$ð ó!$ðH˜s X¨c°3¨hÑ%7Ñ7ð Ð<\ó ÷@3&ñ 3&ðl˜3ð ¨#°©*ð ¸EÀ#ÀsÀ(¹Oð ÐUYÐZ]Ð_bÐZbÑUcð Ðhló ðg˜sð g só gð"�c˜D‘jó ð  ×Ñð�c˜D‘jð  YÐ/?Ñ%@ò ó ðð Sð °#ð ¸$ó ô
<rJ   