
    !ni
i                    $   d dl mZ 	 d dlZd dlZd dlZ	 d dlmZ d dl	Z	g dZ
h dZ G d d      Zd Zd	 Zd
 Zd Zd Zi Zd Zd Zd Zd Zd ZddZd Zd Zd Zd Zd Zd Zd Zd Z d Z!g dfdZ"e#dk(  rnejH                  jK                  d         e         e&ejH                  d          5 Z' e(e'jS                         ejH                  d    d      Z* e+e*       ddd       yy# e$ r d dlZY w xY w# e$ r dZY w xY w# 1 sw Y   yxY w)     )annotationsN)register_at_fork)injectimport_patchedmonkey_patchis_monkey_patched>   __file____name____builtins__c                  $    e Zd ZdZddZd Zd Zy)SysModulesSaverzClass that captures some subset of the current state of
    sys.modules.  Pass in an iterator of module names to the
    constructor.c                X    i | _         t        j                           | j                  |  y N)_savedimpacquire_locksave)selfmodule_namess     P/home/homepc/tiktok-worker/venv/lib/python3.12/site-packages/eventlet/patcher.py__init__zSysModulesSaver.__init__   s#    		<     c                l    |D ]/  }t         j                  j                  |d      | j                  |<   1 y)z&Saves the named modules to the object.N)sysmodulesgetr   )r   r   modnames      r   r   zSysModulesSaver.save#   s0    # 	BG#&;;??7D#ADKK 	Br   c                   	 | j                   j                         D ]-  \  }}||t        j                  |<   	 t        j                  |= / 	 t        j                          y# t        $ r Y Qw xY w# t        j                          w xY w)zRRestores the modules that the saver knows about into
        sys.modules.
        N)r   itemsr   r   KeyErrorr   release_lock)r   r   mods      r   restorezSysModulesSaver.restore(   s|    
	 $ 1 1 3 ?+.CKK(KK0  $  s.   6A1 A"
A1 "	A.+A1 -A..A1 1BN) )r
   
__module____qualname____doc__r   r   r#   r$   r   r   r   r      s    !
B
r   r   c                v   d| z   }|t         j                  v rt         j                  |   S |s6t               t               z   t	               z   t               z   t               z   }t        |D cg c]  \  }}|	 c}}      }|j                  |        |D ]  \  }}|t         j                  |<    t         j                  j                  | d       t        t         j                  j                               D ]7  }|j                  | dz         st         j                  j                  |d       9 	 t        | i i | j                  d      dd       }	|(t        |	      D ]  }|t         vst#        |	|      ||<    |	t         j                  |<   |j%                          |	S c c}}w # |j%                          w xY w)a  Base method for "injecting" greened modules into an imported module.  It
    imports the module specified in *module_name*, arranging things so
    that the already-imported modules in *additional_modules* are used when
    *module_name* makes its imports.

    **Note:** This function does not create or change any sys.modules item, so
    if your greened module use code like 'sys.modules["your_module_name"]', you
    need to update sys.modules by yourself.

    *new_globals* is either None or a globals dictionary that gets populated
    with the contents of the *module_name* module.  This is useful when creating
    a "green" version of some other module.

    *additional_modules* should be a collection of two-element tuples, of the
    form (<name>, <module>).  If it's not specified, a default selection of
    name/module pairs is used, which should cover all use cases but may be
    slower because there are inevitably redundant or unnecessary imports.
    __patched_module_N.)r   r   _green_os_modules_green_select_modules_green_socket_modules_green_thread_modules_green_time_modulesr   r   poplistkeys
startswith
__import__splitdir	__excludegetattrr#   )
module_namenew_globalsadditional_modulespatched_namenamemsaverr"   imported_module_namemodules
             r   r   r   9   s   & '4Ls{{" {{<(( #%&#%& $%& "#	$ 	 1CDgdATDEE	JJ{ (  	cD 
 KKOOK& !%S[[%5%5%7 8 8**;+<=KKOO0$78KR1B1B31G1LM"F >y((/(=K%>
 %+L!M? E: 	s   -F 
18F& *$F& &F8c                P    t        | dg|t        |j                               z    S )zImports a module in a way that ensures that the module uses "green"
    versions of the standard library modules, so that everything works
    nonblockingly.

    The only required argument is the name of the module to be imported.
    N)r   tupler   )r:   r<   kw_additional_moduless      r   r   r      s2     T.7L7R7R7T1UU r   c                     s6t               t               z   t               z   t               z   t	               z    fd}|S )a   Decorator that returns a version of the function that patches
    some modules for the duration of the function call.  This is
    deeply gross and should only be used for functions that import
    network libraries within their function bodies that there is no
    way of getting around.c                     t               }D ])  \  }}|j                  |       |t        j                  |<   + 	  | i ||j	                          S # |j	                          w xY wr   )r   r   r   r   r#   )argskwr@   r>   r"   r<   funcs        r   patchedzpatch_function.<locals>.patched   s]    !+ 	$ID#JJt #CKK	$	$$MMOEMMOs   A A%)r,   r-   r.   r/   r0   )rJ   r<   rK   s   `` r   patch_functionrL      sQ      #%&#%& $%& "#	$ 	 Nr   c                      fd}|S )au  Kind of the contrapositive of patch_function: decorates a
    function such that when it's called, sys.modules is populated only
    with the unpatched versions of the specified modules.  Unlike
    patch_function, only the names of the modules need be supplied,
    and there are no defaults.  This is a gross hack; tell your kids not
    to import inside function bodies!c                     t              }D ]  }t        |      t        j                  |<     	  | i ||j	                          S # |j	                          w xY wr   )r   originalr   r   r#   )rH   rI   r@   r>   rJ   r   s       r   rK   z)_original_patch_function.<locals>.patched   sS    -  	/D (CKK	/	$$MMOEMMOs   A	 	Ar$   )rJ   r   rK   s   `` r   _original_patch_functionrP      s     Nr   c                   d| z   }|t         j                  v rt         j                  j                  |      S t        | f      }t         j                  j	                  | d       ddd}| |v r2||    }|j                  |       t        |      t         j                  |<   	 t        | i i | j                  d      dd       }| dv r;t        |d	      s/t        |j                  j                  d      |j                  _        |t         j                  |<   |j                          t         j                  |   S # |j                          w xY w)
zcThis returns an unpatched version of a module; this is useful for
    Eventlet itself (i.e. tpool).__original_module_N_thread	threadingrT   queuer*   r+   )QueuerV   
_threading)r   r   r   r   r1   r   rO   r5   r6   hasattrrP   rW   r   r#   )r   original_namer@   deps
dependencyreal_mods         r   rO   rO      s    )72M#{{}-- WJ'EKKOOGT" #[9D$']


:"*:"6Jgr2w}}S/A#2/FG((<1P '?'''HNN# &.M";;}%% 	s   A2D4 4Ec                   | }t        |      }|dk(  r+ddl}t        |j                  d      r|j                  |_        |dv rF	 ddl}|dk(  r||j                  j                  _        |dk(  r||j                  j                  _	        	 dD ]F  }	 t        j                  |      }t        ||d      t        j                   |   u s:t#        |||       H y# t        $ r Y Ww xY w# t        $ r Y dw xY w)	z
    When using asyncio hub, we want the asyncio modules to use the original,
    blocking APIs.  So un-monkeypatch references to the given module name, e.g.
    "select".
    rS   r   N	get_identrU   rT   rV   )zasyncio.base_eventszasyncio.base_futureszasyncio.base_subprocesszasyncio.base_taskszasyncio.constantszasyncio.coroutineszasyncio.eventszasyncio.exceptionszasyncio.format_helperszasyncio.futuresasynciozasyncio.lockszasyncio.logzasyncio.mixinszasyncio.protocolszasyncio.queueszasyncio.runnerszasyncio.selector_eventszasyncio.sslprotozasyncio.staggeredzasyncio.streamszasyncio.subprocesszasyncio.taskgroupszasyncio.taskszasyncio.threadszasyncio.timeoutszasyncio.transportszasyncio.trsockzasyncio.unix_events)rO   asyncio.base_futuresrY   base_futuresr_   concurrent.futures.threadfuturesthreadrT   rV   RuntimeError	importlibimport_moduleImportErrorr9   r   r   setattr)!unmonkeypatch_refs_to_this_module
to_unpatchoriginal_moduler`   
concurrentr:   rB   s          r   _unmonkey_patch_asyncioro      s    3Jz*O Y#7''5#2#<#<G  ++
	B, [(6E
""))3W$2A
""))/ &9>	,,[9F
 6:t,J0GGFJ8M&9  	 	X  	 	s$   C C#	C C #	C/.C/c            
         t        t               t               t               t	               t               t               t               gg       D ]  \  } }t        |         t        d      t        d      _
        y)z<
    Unmonkey-patch all referred-to modules in asyncio.
    select	selectorsN)sumr,   r-   r.   r/   r0   _green_builtins_green_subprocess_modulesro   rO   rq   )r:   _s     r   _unmonkey_patch_asyncio_allrw   5  sn     !# 
 	-Q 	 ,	- $,H#5H[ r   c            	        t         j                  j                          h d}d| v rd| v rJ 	 | j                  d      }|| d<   | j                  dd      }| j                         D ]  }||vst        d|z         |d| j                         v}|D ]B  }|dk(  r| j                  |d	       |dk(  r| j                  |d	       | j                  ||       D d
dl	}t        |j                               }g }dt        fdt        fdt        fdt        fdt         fdt"        fdt$        fdt&        ffD ]4  \  }	}
| |	   st(        j+                  |	      r"| |
       z  }dt(        |	<   6 | d   r5t(        j+                  d      s 	 d
dlm} |j1                          dt(        d<   t5        d      }t7        j8                          	 |D ]  \  }	}t:        j<                  j+                  |	      }|t?        |	      }|j@                  D ]  }tC        ||d      }|tE        |||       ! tC        |dg       }|D ]  }tG        ||      stI        ||        |	dk(  stJ        sd }|jL                  |jN                  _&        |jL                  tQ        di       jN                  _&         	 t7        jR                          d
dl*}t5        d      }||jV                  _,        d
dl	}|jZ                  |_        d
dl.}|j^                  |_0        |D ]  \  }	}|	dk(  stc        |        y# t        $ r Y w xY w# t2        $ r Y w xY w# t7        jR                          w xY w)a  Globally patches certain system modules to be greenthread-friendly.

    The keyword arguments afford some control over which modules are patched.
    If no keyword arguments are supplied, all possible modules are patched.
    If keywords are set to True, only the specified modules are patched.  E.g.,
    ``monkey_patch(socket=True, select=True)`` patches only the select and
    socket modules.  Most arguments patch the single module of the same name
    (os, time, select).  The exceptions are socket, which also patches the ssl
    module if present; and thread, which patches thread, threading, and Queue.

    It's safe to call monkey_patch multiple times.
    >	   ostimerq   socketre   MySQLdbpsycopgbuiltins
subprocess__builtin__r~   allNz4monkey_patch() got an unexpected keyword argument %rTr|   Fr   ry   rq   r{   re   rz   r   r}   )psycopg2_patcherrT   __deleted__c                      y r   r$   r$   r   r   noopzmonkey_patch.<locals>.noop  s    r   rS   )2eventlethubsget_hubr1   r    r3   	TypeErrorvalues
setdefaultrT   typeRLockr,   r-   r.   r/   r0   _green_MySQLdbrt   ru   already_patchedr   eventlet.supportr   make_psycopg_greenri   rO   r   r   r   r   r5   __patched__r9   rj   rY   delattrr   __code___after_forkr   r!   importlib._bootstrap
_bootstraprS   _PyRLockrV   _PySimpleQueueSimpleQueue_green_existing_locks)onaccepted_argsb
default_onkr   rT   original_rlock_typemodules_to_patchr>   modules_functionr   rX   r"   orig_mod	attr_namepatched_attrdeletedr   rg   re   rV   rv   s                          r   r   r   F  sv   * MM
M #
b(899FF=! :t$JWWY M!IAM 
 ,
  +iMM'5)j MM'5)
gz*+ y01	 !	()	()	()	$%	N#	_%	01	# ) d8O//5 0 22$(OD!) 
)}_00;	9//1)-OI& +&J) 	MID#{{t,H%d+ __ ?	&sIt<+Hi>? c="5G$ 1	8Y/Hi01 {"'704$$-?C}}{B'33<7	M: 	i F#)I  ((IO ,,E $ 7a;!"567_  ^  	 	P 	sI   L L. AL> -L> L> L> AL> 	L+*L+.	L;:L;>Mc                <    | t         v xs t        | dd      t         v S )a[  Returns True if the given module is monkeypatched currently, False if
    not.  *module* can be either the module itself or its name.

    Based entirely off the name of the module, so if you import a
    module some other way than with the import keyword (including
    import_patched), this might not be correct about that particular
    module.r
   N)r   r9   )rB   s    r   r   r     s(     	/! 	@6:t,?r   c                t   ddl }ddl}ddl}|j                  j                  j                         fd}t        t        j                  | |       d|j                  v ry|j                          d}|j                         D ]  }	 t        ||       r|dz  } |r[	 ddl}|j                         D ]B  }	 t        ||       s	 |j.                  t1        t$        |j3                  |            v r|dz  }~D 	 |r<ddl}|j!                  d      }
|
j#                  dj7                  |      dz   dz          yy# t        $ rn}ddl}ddl}	|j!                  d      }
|
j#                  dt%        |      j&                  z   dz   t)        |      z   d	z   |	j+                         z          Y d}~%d}~ww xY w# t        $ rn}ddl}ddl}	|j!                  d      }
|
j#                  d
t%        |      j&                  z   dz   t)        |      z   d	z   |	j+                         z          Y d}~qd}~ww xY w# t4        $ r Y ?w xY w)a  Make locks created before monkey-patching safe.

    RLocks rely on a Lock and on Python 2, if an unpatched Lock blocks, it
    blocks the native thread. We need to replace these with green Locks.

    This was originally noticed in the stdlib logging module.r   Nc                    t        |       S r   )_convert_py3_rlock)old_locktids    r   upgradez&_green_existing_locks.<locals>.upgrade  s    !(C00r   PYTEST_CURRENT_TEST   r   z/Not increase rlock count, an exception of type zoccurred with the message 'z'. Traceback details: z.No decrease rlock count, an exception of type z{} RLock(s) were not greened,z= to fix this error make sure you run eventlet.monkey_patch() z#before importing any other modules.)gcry   eventlet.green.threadgreenre   r_   _upgrade_instancesr   r   environcollectget_objects
isinstanceReferenceErrorlogging	tracebackLoggererrorr   r
   str
format_exc_frozen_importlib_ModuleLockmapget_referrersri   format)
rlock_typer   ry   r   r   remaining_rlocksoexcr   r   loggerr   r   s               @r   r   r     sP      ..


)
)
+C1 s{{J8
 

*
 JJL^^ 	!Z( A%  	$ ^^% %a4  5 %00Cb>N>Nq>Q4RR$)$), 
++223CDMN34	
	 O  
	^^J/FLLAs)$$%'DEc(56 &&() 
	. & "$$^^J7FLLHs),,-/LMc(#%=> $..01   		sD   D6H* 5F06	F-?A#F((F-0	H'9A#H""H'*	H76H7c                8   i i | t        |       <   fd}t        | t              r1t        | j	                               D ]  \  }} ||      }||| |<    t        | t              r#t        |       D ]  \  }	} ||      }||| |	<    	 t        |       }
	 t        |
j	                               D ]  \  }} ||      }|t        | ||        y#  ddl}|j                  d      }|j                  dd       Y yxY w# t        $ r Y yw xY w)a|  
    Starting with a Python object, find all instances of ``klass``, following
    references in ``dict`` values, ``list`` items, and attributes.

    Once an object is found, replace all instances with
    ``upgrade(found_object)``, again limited to the criteria above.

    In practice this is used only for ``threading.RLock``, so we can assume
    instances are hashable.
    Nc                    t        |       v ry t        |       r| v r|    S  |       }|| <   |S t        |        y r   )idr   r   )objnewklass
old_to_newr   visiteds     r   upgrade_or_traversez/_upgrade_instances.<locals>.upgrade_or_traverseW  sX    c7gc5!j !#&cl"%
3
sE7GZHr   r   r   zAn exception was thrown while monkey_patching for eventlet. to fix this error make sure you run eventlet.monkey_patch() before importing any other modules.T)exc_info)r   r   dictr2   r   	enumeratevarsrj   r   r   	exceptionr   )	containerr   r   r   r   r   r   vr   icontainer_varsr   r   s    ````        r   r   r   D  sE    
 'GByM )T"*+ 	#DAq%a(C"	!	# )T"i( 	#DAq%a(C"	!	#i	^1134 /1)!,?Iq#./		^^J/F6 	    s$   D $)C C *D
	DDc                x   ddl }ddlm} |j                         }t	        |d      rt	        |d      st        d       |       |_        d}| j                         r3| j                          |j                          d}| j                         r3| j                         r|j                          d}|r||_
        |S )	z
    Convert a normal RLock to one implemented in Python.

    This is necessary to make RLocks work with eventlet, but also introduces
    bugs, e.g. https://bugs.python.org/issue13697.  So more of a downgrade,
    really.
    r   N)allocate_lock_block_ownerzINTERNAL BUG. Perhaps you are using a major version of Python that is unsupported by eventlet? Please file a bug at https://github.com/eventlet/eventlet/issues/newFT)rT   r   r   r   rY   rf   r   	_is_ownedreleaseacquirer   )oldr   rT   r   r   acquireds         r   r   r     s     3



C3!h)? C
 	

 CJH
--/ --/ }}
Jr   c                     ddl m}  d| fgS )Nr   ry   ry   )eventlet.greenry   r   s    r   r,   r,     s    !2J<r   c                 N    ddl m}  d| fg}ddl m} |j                  d|f       |S )Nr   )rq   rq   )rr   rr   )r   rq   rr   append)rq   r   rr   s      r   r-   r-     s+    %&!"G(NNK+,Nr   c                 T    ddl m}  	 ddl m} d| fd|fgS # t        $ r d| fgcY S w xY w)Nr   )r{   )sslr{   r   )r   r{   r   ri   )r{   r   s     r   r.   r.     s>    %$&6"UCL11 $6"##$s    ''c                     ddl m}  d| fgS )Nr   r   r   )r   r   r   s    r   ru   ru     s    ):&''r   c                 <    ddl m}  ddl m} ddl m} d| fd|fd|fgS )Nr   )rW   )re   )rT   rV   rS   rT   )r   rW   re   rT   )rW   re   rT   s      r   r/   r/     s'    $%(ey&1K3KLLr   c                     ddl m}  d| fgS )Nr   rz   rz   )r   rz   r   s    r   r0   r0     s    #TNr   c                 <    	 ddl m}  d| fgS # t        $ r g cY S w xY w)Nr   r|   r|   )r   r|   ri   r   s    r   r   r     s,    *G$%% 	   
 c                 <    	 ddl m}  d| fgS # t        $ r g cY S w xY w)Nr   builtinr~   )r   r   ri   r   s    r   rt   rt     s,    *W%&& 	r   c           
         || j                   }|j                  |D ci c]$  }|j                  d      s||v s|t        | |      & c}       yc c}w )a   Copy properties from *source* (assumed to be a module) to
    *destination* (assumed to be a dict).

    *ignore* lists properties that should not be thusly copied.
    *srckeys* is a list of keys to copy, if the source's __all__ is
    untrustworthy.
    N__)__all__updater4   r9   )sourcedestinationignoresrckeysr>   s        r   slurp_propertiesr     s[     ..  	
OOD)TV^ '&$''	
	
s   )A__main__exec)NN),
__future__r   _impr   ri   rg   r   ry   r   r   r   r8   r   r   r   rL   rP   rO   r   ro   rw   r   r   r   r   r   r,   r-   r.   ru   r/   r0   r   rt   r   r
   argvr1   openfcompilereadcoder  r$   r   r   <module>r
     sa   "  
 $  L4	 @EP	:(%&P I9X6"W7tS
lAHD	$(M 24T & zHHLLON	chhqk	 aqvvx!f5T
  w    j s.   C* C9 2.D*	C65C69DDD