
    $gTd                    	   d Z ddl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Zddl	m
Z
mZ ddlmZ ddlmZ ddlmZmZ ddlmZmZmZ dd	lmZ er 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!  ej"        ej#                   dZ$dZ% G d de          Z&dZ' e
e'e&          Z(e()                    dde           e(*                    d          Z+i Z,e-e.e/         ef         Z0dd!Z1e+dd"dd*Z2ej3        d+dd/Z4dd0dd5Z5dd8Z6d9d+dd=Z7ddDZ8ddGZ9 e2 e1dHdIdJK           e1dLdMdNej3        dOP           e1dQdRdSdTe:dUV           e1dWdXdYdZ[           e1d\dXd]^           e1d_dXd`^           e1dadXdb^           e1dcdXdd^           e1dedXdf^          g	dgg          ddi            Z; e2 e1djdIdkK           e1dLdMdNej3        dOP           e1dlddmP           e1dndodpdXdqr          gdsgg          ddt            Z< e2 e1dudIdMdvw           e1dxdydzd{dId|}           e1d~ddddd}           e1ddddXdr           e1ddWdBdXdr           e1dQdRdSdTe:dV           e1ddXd^           e1d\dXd]^           e1d_dXd`^           e1dadXdb^           e1dcdXdd^           e1dedXdf^          g          dd            Z= e2 e1dudIdMdw           e1ddddd}           e1dxdydzd{dId|}           e1d~ddddd}           e1dddddXd           e1ddWdBdXdr           e1dQdRdSdTe:dV           e1ddddXdr           e1ddddXdr           e1d\dXd]^          g
          dd            Z> e2 e1dd           e1dddId           e1ddduddd           e1dxdydzd{dId|}           e1d~ddddd}           e1dddddXd           e1ddWdBdXdr           e1dQdRdSdTe:dV           e1dddd}           e1d\dXd]^           e1ddde:dV           e1ddde:dV           e1dddYdd          g          dd            Z? G d de@          ZAddZBddZCeDdk    r ejE         eC                       dS dS )u   :module: watchdog.watchmedo
:author: yesudeep@google.com (Yesudeep Mangalapilly)
:author: contact@tiger-222.fr (Mickaël Schoentgen)
:synopsis: ``watchmedo`` shell script utility.
    )annotationsN)ArgumentParserRawDescriptionHelpFormatter)StringIO)dedent)TYPE_CHECKINGAny)WatchdogShutdownError
load_classplatform)VERSION_STRING)	Namespace_SubParsersAction)Callable)FileSystemEventHandler)ObserverType)BaseObserver)leveltrickszpython-pathc                  2     e Zd ZdZddd fdZddZ xZS )HelpFormattera#  A nicer help formatter.

    Help for arguments can be indented and contain new lines.
    It will be de-dented and arguments in the help
    will be separated by a blank line for better readability.

    Source: https://github.com/httpie/httpie/blob/2423f89/httpie/cli/argparser.py#L31
       )max_help_positionargsr	   r   intkwargsreturnNonec               D    ||d<    t                      j        |i | d S )Nr   )super__init__)selfr   r   r   	__class__s       R/var/www/html/netbox-4.1.3/venv/lib/python3.11/site-packages/watchdog/watchmedo.pyr!   zHelpFormatter.__init__0   s0    &7"#$)&)))))    textstrwidth	list[str]c                r    t          |                                          dz   }|                                S )Nz

)r   strip
splitlines)r"   r&   r(   s      r$   _split_lineszHelpFormatter._split_lines5   s.    d||!!##f,   r%   )r   r	   r   r   r   r	   r   r   )r&   r'   r(   r   r   r)   )__name__
__module____qualname____doc__r!   r-   __classcell__)r#   s   @r$   r   r   &   sj          => * * * * * * * *
! ! ! ! ! ! ! !r%   r   u,  Copyright 2018-2024 Mickaël Schoentgen & contributors
Copyright 2014-2018 Thomas Amland & contributors
Copyright 2012-2014 Google, Inc.
Copyright 2011-2012 Yesudeep Mangalapilly

Licensed under the terms of the Apache license, version 2.0. Please see
LICENSE in the source code for more information.)epilogformatter_classz	--versionversion)actionr5   top_command)destname_or_flagsr'   r   r	   r   Argumentc                 $    t          |           |fS )z\Convenience function to properly format arguments to pass to the
    command decorator.
    )list)r9   r   s     r$   argumentr=   K   s     &&r%   )parentcmd_aliasesr   list[Argument]r>   !_SubParsersAction[ArgumentParser]r?   list[str] | Noner   c                    d fd}|S )a
  Decorator to define a new command in a sanity-preserving way.
    The function will be stored in the ``func`` variable when the parser
    parses arguments so that it can be called directly like so::

      >>> args = cli.parse_args()
      >>> args.func(args)

    funcr   r   c                   | j                             dd          }t          | j        pd          }	                    |pg |t
                    }|t          |<   |                                }|                    ddddd	
           |                    ddddd
           D ](\  }} |j        |i | |	                    |            )| S )N_- )aliasesdescriptionr4   z-qz--quiet	verbosityappend_const)r8   r6   constz-vz	--verbose   )rD   )
r.   replacer   r1   
add_parserr   command_parsersadd_mutually_exclusive_groupadd_argumentset_defaults)
rD   namedescparserverbosity_groupr9   r   r   r?   r>   s
          r$   	decoratorzcommand.<locals>.decoratora   s    }$$S#..dl(b))""41BPTfs"tt & ==??$$T9;~eg$hhh$$T;[Q_gh$iii%) 	+ 	+!M6F9&999T****r%   )rD   r   r   r    )r   r>   r?   rZ   s   ``` r$   commandr\   R   s5            r%   )	separatorpathname_specr]   r)   c               ,    |                      |          S )zSplits a pathname specification separated by an OS-dependent separator.

    :param pathname_spec:
        The pathname specification.
    :param separator:
        (OS Dependent) `:` on Unix and `;` on Windows or user-specified.
    split)r^   r]   s     r$   
path_splitrb   q   s     y)))r%   )index	pathnamesrc   r   r   c               b    | ddd         D ]"}t           j                            ||           #dS )zAdds specified paths at specified index into the sys.path list.

    :param paths:
        A list of paths to add to the sys.path
    :param index:
        (Default 0) The index in the sys.path list where the paths will be
        added.
    NrM   )syspathinsert)rd   rc   pathnames      r$   add_to_sys_pathrj   |   s@     dddO ) )x(((() )r%   tricks_file_pathnamedictc                    ddl }t          | d          5 }|                    |                                          cddd           S # 1 swxY w Y   dS )zLoads the YAML configuration from the specified file.

    :param tricks_file_path:
        The path to the tricks configuration file.
    :returns:
        A dictionary of configuration information.
    r   Nrb)yamlopen	safe_loadread)rk   ro   fs      r$   load_configrt      s     KKK	"D	)	) (Q~~affhh''( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( (s   'A		AA;patterns_specignore_patterns_spectuple[list[str], list[str]]c               p    |                      |          }|                     |          }|dgk    rg }||fS )z^Parses pattern argument specs and returns a two-tuple of
    (patterns, ignore_patterns).
    rH   r`   )rv   rw   r]   patternsignore_patternss        r$   parse_patternsr|      sG     ""9--H*00;;O2$_$$r%   observerr   event_handlerr   	recursiveboolc                   t          |          D ]}|                     |||           |                                  	 	 t          j        d           # t
          $ r |                                  Y nw xY w|                                  dS )ag  Single observer thread with a scheduled path and event handler.

    :param observer:
        The observer thread.
    :param event_handler:
        Event handler which will be called in response to file system events.
    :param pathnames:
        A list of pathnames to monitor.
    :param recursive:
        ``True`` if recursive; ``False`` otherwise.
    r   TrO   N)setschedulestarttimesleepr
   stopjoin)r}   r~   rd   r   ri   s        r$   observe_withr      s    $ 	NN H H-YGGGGNN	JqMMM	    MMOOOOOs    A A76A7
list[dict]ri   c                   |D ]^}|                                 D ]G\  }}t          |          } |di |}t          |dd          p|}	|                     ||	|           H_dS )aj  Schedules tricks with the specified observer and for the given watch
    path.

    :param observer:
        The observer thread into which to schedule the trick and watch.
    :param tricks:
        A list of tricks.
    :param pathname:
        A path name which should be watched.
    :param recursive:
        ``True`` if recursive; ``False`` otherwise.
    source_directoryNr   r[   )itemsr   getattrr   )
r}   r   ri   r   trickrV   value	trick_clshandlertrick_pathnames
             r$   schedule_tricksr      s      L L ;;== 	L 	LKD%"4((Ii((%((G$W.@$GGS8Ng~KKKK		LL Lr%   files*zperform tricks from given file)nargshelpz--python-path.zPaths separated by z to add to the Python path.)defaultr   z
--intervalz	--timeouttimeoutg      ?z?Use this as the polling interval/blocking timeout (in seconds).)r8   r   typer   z--recursive
store_trueTz-Recursively monitor paths (defaults to True).)r6   r   r   z--debug-force-pollingz[debug] Forces polling.)r6   r   z--debug-force-kqueuez[debug] Forces BSD kqueue(2).z--debug-force-winapiz[debug] Forces Windows API.z--debug-force-fseventsz[debug] Forces macOS FSEvents.z--debug-force-inotifyz [debug] Forces Linux inotify(7).)r?   r   c                    | j         r	ddlm} |}ni| j        r	ddlm} |}nYt          s| j        st          rt          j	                    r	ddl
m} |}n(| j        r	ddlm} |}n| j        r	ddlm} |}nddlm} |}t)          t+          | j                             g }| j        D ]k}	 || j                  }
t2          j                            |	          s7t9          t:          j        t3          j        t:          j                  |	          tA          |	          }	 |tB                   }n0# tD          $ r#}d	tB          d
|	d}tE          |          |d}~ww xY wtF          |v rt)          |tF                              t2          j        $                    |	          p/t2          j        %                    t3          j&                              }tO          |
||| j(                   |
)                                 |*                    |
           m	 	 tW          j,        d           # tZ          $ r0 |D ]*}|.                                 |/                                 +Y nw xY w|D ]}|0                                 dS )z;Command to execute tricks from a tricks configuration file.r   PollingObserverKqueueObserverWindowsApiObserverInotifyObserverFSEventsObserverObserverr   zNo z key specified in r   Nr   TrO   )1debug_force_pollingwatchdog.observers.pollingr   debug_force_kqueuewatchdog.observers.kqueuer   r   debug_force_winapir   
is_windows)watchdog.observers.read_directory_changesr   debug_force_inotifywatchdog.observers.inotifyr   debug_force_fseventswatchdog.observers.fseventsr   watchdog.observersr   rj   rb   python_pathr   r   osrg   existsOSErrorerrnoENOENTstrerrorrt   CONFIG_KEY_TRICKSKeyErrorCONFIG_KEY_PYTHON_PATHdirnamerelpathgetcwdr   r   r   appendr   r   r
   unschedule_allr   r   )r   r   observer_clsr   r   r   r   r   	observerstricks_filer}   configr   eerrordir_pathos                    r$   tricks_fromr      s   b   >>>>>>&		   <<<<<<%   7  ]  xObOdOd  PPPPPP)		!  >>>>>>&		" 	 @@@@@@' 	0/////Jt/00111Iz # #<555w~~k** 	P%,EL(A(A;OOO[))	)-.FF 	) 	) 	)Q+QQQQQE5//q(	) "V++F#9:;;;7??;//O27??29;;3O3O&(dnMMMM""""	JqMMM	     	 	AFFHHHH	 	   	 s*   D,,
E6EEH( (7I"!I"trick_pathsz5Dotted paths for all the tricks you want to generate.z--append-to-filez
                   Appends the generated tricks YAML to a file.
                   If not specified, prints to standard output.z-az--append-onlyappend_onlyz
                   If --append-to-file is not specified, produces output for
                   appending instead of a complete tricks YAML file.)r8   r6   r   zgenerate-tricks-yamlc                   ddl }t          | j                  }t          |           t	                      }| j        D ]8}t          |          }|                    |                                           9|	                                }|
                                 |                    t          |i          }|t           dz  }| j        -| j        s||z   }t           j                            |           dS t$          j                            | j                  s||z   }t+          | j        dd          5 }|                    |           ddd           dS # 1 swxY w Y   dS )zLCommand to generate Yaml configuration for tricks named on the command line.r   Nz:
azutf-8)encoding)ro   rb   r   rj   r   r   r   writegenerate_yamlgetvalueclosedumpr   r   append_to_filer   rf   stdoutr   rg   r   rp   )	r   ro   python_pathsoutput
trick_pathr   contentheaderfiles	            r$   tricks_generate_yamlr   E  s   B KKKd.//LL!!!ZZF& 0 0
z**	Y,,..////ooG
LLNNNYY.=>>F
"''''F" 	'w&G
!!!!!w~~d122 	'w&G$%sW=== 	 JJw	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	 s   ;EE"%E"directoriesz%Directories to watch. (default: '.').)r   r   r   z-pz	--patternz
--patternsrz   z9Matches event paths with these patterns (separated by ;).)r8   r   r   z-iz--ignore-patternz--ignore-patternsr{   rH   z9Ignores event paths with these patterns (separated by ;).z-Dz--ignore-directoriesignore_directorieszIgnores events for directories.z-Rz%Monitors the directories recursively.z2Use this as the polling interval/blocking timeout.z--tracez!Dumps complete dispatching trace.c                B   ddl m} ddlm} | j        r3t          j        |j                  |                    |fd           t          | j
        | j                  \  }} |||| j                  }| j        r	ddlm} |}ni| j        r	ddlm} |}nYt&          s| j        st&          rt+          j                    r	dd	lm}	 |	}n(| j        r	dd
lm}
 |
}n| j        r	ddlm} |}nddlm } |} || j!                  }tE          ||| j#        | j$                   dS )z1Command to log file system events to the console.r   )LoggerTrick)echoc                .                         |           S N)info)msgclass_module_loggers    r$   <lambda>zlog.<locals>.<lambda>  s    7J7O7OPS7T7T r%   )r   )rz   r{   r   r   r   r   r   r   r   r   r   N)%watchdog.tricksr   watchdog.utilsr   tracelogging	getLoggerr/   
echo_classr|   rz   r{   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )r   r   r   rz   r{   r   r   r   r   r   r   r   r   r}   r   s                 @r$   logr     s   P ,+++++######z V%/0FGG+T+T+T+TUUU .t}d>R S SHok'2  G   >>>>>>&		   <<<<<<%   7  ]  xObOdOd  PPPPPP)		!  >>>>>>&		" 	 @@@@@@' 	0/////|DL111H7D$4OOOOOOr%   zDirectories to watch.z-cz	--commandr\   am  
    Shell command executed in response to matching events.
    These interpolation variables are available to your command string:

        ${watch_src_path}   - event source path
        ${watch_dest_path}  - event destination path (for moved events)
        ${watch_event_type} - event type
        ${watch_object}     - 'file' or 'directory'

    Note:
        Please ensure you do not use double quotes (") to quote
        your command string. That will force your shell to
        interpolate before the command is processed by this
        command.

    Example:

        --command='echo "${watch_src_path}"'
    F)r8   r   r6   r   z-wz--waitwait_for_processzDWait for process to finish to avoid multiple simultaneous instances.z-Wz--dropdrop_during_processzhIgnore events that occur while command is still being executed to avoid multiple simultaneous instances.c                >   ddl m} | j        sd| _        | j        r	ddlm} |}nddlm} |}t          | j	        | j
                  \  }} || j        ||| j        | j        | j                  } || j                  }t          ||| j        | j                   dS )	zDCommand to execute shell commands in response to file system events.r   )ShellCommandTrickNr   r   )rz   r{   r   r   r   r   r   )r   r   r\   r   r   r   r   r   r|   rz   r{   r   r   r   r   r   r   r   )	r   r   r   r   r   rz   r{   r   r}   s	            r$   shell_commandr     s    n 211111<    >>>>>>&////// .t}d>R S SHo'2. 4  G |DL111H7D$4OOOOOOr%   z,Long-running command to run in a subprocess.)r   command_argsargz
    Command arguments.

    Note: Use -- before the command arguments, otherwise watchmedo will
    try to interpret them.
    )metavarr   r   z-dz--directory	DIRECTORYr   zLDirectory to watch. Use another -d or --directory option for each directory.)r8   r   r6   r   z--signalsignalSIGINTz6Stop the subprocess with this signal (default SIGINT).z--kill-after
kill_afterg      $@zYWhen stopping, kill the subprocess after the specified timeout in seconds (default 10.0).z--debounce-intervaldebounce_intervalg        zwAfter a file change, Wait until the specified interval (in seconds) passes with no file changes, and only then restart.z--no-restart-on-command-exitrestart_on_command_exitstore_falsez.Don't auto-restart the command after it exits.c           
     t   | j         r	ddlm} |}nddlm} |}ddlddlm} | j        sdg| _        | j        	                    d          rt          | j                  nt          | j                  }j        j        ht          d          r                    j                   dfd}D ]}                    ||           t#          | j        | j                  \  }}	| j        g}
|
                    | j                    ||
||	| j        || j        | j        | j                  }|                                  || j                  }	 t;          ||| j        | j                   n# t>          $ r Y nw xY w|                                  dS # |                                  w xY w)zLCommand to start a long-running subprocess and restart it on matched events.r   r   r   N)AutoRestartTrickr   SIGSIGHUP_signumsignal._SIGNUM_frameobjectr   r   c                R    D ]}                     |j                   t          r   )r   SIG_IGNr
   )r	  r  signumr   termination_signalss      r$   handler_termination_signalz0auto_restart.<locals>.handler_termination_signal  s1    ) 	2 	2FMM&&.1111##r%   )rz   r{   r   stop_signalr  debounce_interval_secondsr  r   r   )r	  r
  r  r  r   r   )!r   r   r   r   r   r   r   r  r   
startswithr   r   SIGTERMr   hasattraddr  r|   rz   r{   r\   extendr   r   r  r  r  r   r   r   r   r
   r   )r   r   r   r   r  r  r  r  rz   r{   r\   r   r}   r   r  s                @@r$   auto_restartr  j  s.   ~   >>>>>>&//////MMM000000 !5 37+2H2H2O2Oe'&$+...UXY]YdUeUeK ">6=9vx   /...$ $ $ $ $ $ $ & : :f89999 .t}d>R S SHo|nGNN4$%%%'2?"&"8 $ <	 	 	G MMOOO|DL111HXw(8DNSSSSS     	s*   E; :F! ;
FF! FF! !F7c                      e Zd ZdS )LogLevelErrorN)r.   r/   r0   r[   r%   r$   r  r    s        Dr%   r  c                    t          | j        pg           }|dk     rd}t          |          |dk    rd}t          |          g dd|z            S )NrM   z&-q/--quiet may be specified only once.   z,-v/--verbose may be specified up to 2 times.)ERRORWARNINGINFODEBUGrO   )sumrK   r  )r   rK   r   s      r$   _get_log_level_from_argsr#    sc    DN(b))I2~~8E"""1}}>E"""000Y??r%   c                    t                                           } | j        t                                            dS 	 t	          |           }ne# t
          $ rX}t          d|j        d          t          j	                   t          | j                                                  Y d}~dS d}~ww xY wt          j        d                              |           	 |                     |            n# t          $ r Y dS w xY wdS )zEntry-point function.NrO   zError: r   )r   watchdog   )cli
parse_argsr7   
print_helpr#  r  printr   rf   stderrrR   r   r   setLevelrD   KeyboardInterrupt)r   	log_levelexcs      r$   mainr0    s   >>Dq,T22		   %%%CJ7777()44666qqqqq j!!**9555		$   ss 1s*   A 
B/AB**B/C0 0
C>=C>__main__)r9   r'   r   r	   r   r:   )r   r@   r>   rA   r?   rB   r   r   )r^   r'   r]   r'   r   r)   )rd   r)   rc   r   r   r   )rk   r'   r   rl   )rv   r'   rw   r'   r]   r'   r   rx   )
r}   r   r~   r   rd   r)   r   r   r   r   )
r}   r   r   r   ri   r'   r   r   r   r   )r   r   r   r   )r   r   r   r'   )r   r   )Fr1   
__future__r   r   r   r   os.pathrf   r   argparser   r   ior   textwrapr   typingr   r	   r   r
   r   r   watchdog.versionr   r   r   r   watchdog.eventsr   r   r   watchdog.observers.apir   basicConfigr   r   r   r   r3   r'  rT   add_subparsers
subparsersrR   tupler<   r'   r:   r=   r\   pathseprb   rj   rt   r|   r   r   floatr   r   r   r   r  	Exceptionr  r#  r0  r.   exitr[   r%   r$   <module>rC     s    # " " " " "   				  



  @ @ @ @ @ @ @ @             % % % % % % % % F F F F F F F F F F + + + + + + 455555555666666//////333333  ', ' ' ' ' & ! ! ! ! !/ ! ! !(
4 nFMBBB   Y  G G G]33
cC ' ' ' ' 1;$(	     > 8:z * * * * * * ;< 
) 
) 
) 
) 
) 
)( ( ( ( HK
% 
% 
% 
% 
% 
%   :L L L L* 	*JKKKPrzPPP	
 	
 	

 	R	
 	
 	
 	@		
 	
 	
 	(D]^^^"0	
 	
 	

 	".	
 	
 	

 	$1	
 	
 	

 	#3	
 	
 	
K*V 
Y- - -\> > >]- -\>B 	H	
 	
 	

 	PrzPPP	
 	
 	

 	C	
 	
 	
 	H	
 	
 	
%8 ((;  >     ? > : 	8		
 	
 	
 	L	
 	
 	
 	"L	
 	
 	
 	"%2	
 	
 	
 	8	
 	
 	
 	E	
 	
 	
 	<6YZZZ(D]^^^"0	
 	
 	

 	".	
 	
 	

 	$1	
 	
 	

 	#3	
 	
 	
}CE EL-P -P -PME EL-P` 	c3=TUUU	
 	
 	
2 	L	
 	
 	
 	"L	
 	
 	
 	"%2	
 	
 	
 	8	
 	
 	
 	E	
 	
 	
 	#W	
 	
 	
 	&B	
 	
 	
 	(D]^^^cRT TjP P PkT TjP< 	!OPPP	
	
 
	
 
	
 	_	
 	
 	
 	L	
 	
 	
 	"L	
 	
 	
 	"%2	
 	
 	
 	8	
 	
 	
 	E	
 	
 	
 	I		
 	
 	
 	(D]^^^l	
 	
 	
 	!$K	
 	
 	
 	** A	
 	
 	
eY[ [x: : :y[ [x:z	 	 	 	 	I 	 	 	@ @ @ @   . zCHTTVV r%   