o
    0׾gdA                     @   s  d Z ddlmZ ddlmZ ddlmZ g dZddl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 eZzze  W n   Y W [n[w dd ZG dd deZG dd deZG dd deZG dd deZe
eG dd deZG dd deZG dd deZe
eG dd deZG dd deZe
eG d d! d!eZG d"d# d#eZe
eG d$d% d%eZG d&d' d'eZG d(d) d)eZe
eG d*d+ d+eZ G d,d- d-eZ!e
e!G d.d/ d/eZ"G d0d1 d1eZ#e
e#G d2d3 d3e Z$G d4d5 d5e!Z%e
e%G d6d7 d7e"Z&G d8d9 d9eZ'G d:d; d;eZ(e
e'G d<d= d=e(e Z)G d>d? d?e!Z*e
e*G d@dA dAe(e"Z+G dBdC dCe!Z,e
e,G dDdE dEe(e"Z-dS )Fa  
Publish/subscribe event infrastructure.

When certain "interesting" things happen during the lifetime of the
process, gevent will "publish" an event (an object). That event is
delivered to interested "subscribers" (functions that take one
parameter, the event object).

Higher level frameworks may take this foundation and build richer
models on it.

:mod:`zope.event` will be used to provide the functionality of
`notify` and `subscribers`. See :mod:`zope.event.classhandler` for a
simple class-based approach to subscribing to a filtered list of
events, and see `zope.component
<https://zopecomponent.readthedocs.io/en/latest/event.html>`_ for a
much higher-level, flexible system. If you are using one of these
systems, you generally will not want to directly modify `subscribers`.

.. versionadded:: 1.3b1

.. versionchanged:: 23.7.0
   Now uses :mod:`importlib.metadata` instead of :mod:`pkg_resources`
   to locate entry points.
    )absolute_import)division)print_function)subscribersIEventLoopBlockedEventLoopBlockedIMemoryUsageThresholdExceededMemoryUsageThresholdExceededIMemoryUsageUnderThresholdMemoryUsageUnderThresholdIPeriodicMonitorThread"IPeriodicMonitorThreadStartedEvent!PeriodicMonitorThreadStartedEventIGeventPatchEventGeventPatchEventIGeventWillPatchEvent
DoNotPatchGeventWillPatchEventIGeventDidPatchEventIGeventWillPatchModuleEventGeventWillPatchModuleEventIGeventDidPatchModuleEventGeventDidPatchModuleEventIGeventWillPatchAllEventGeventWillPatchAllEvent"IGeventDidPatchBuiltinModulesEvent!GeventDidPatchBuiltinModulesEventIGeventDidPatchAllEventGeventDidPatchAllEventN)	Interface)	Attribute)implementer)r   )notifyc                 C   s   t |  ddlm} dd l}|jd d dkr|j| jd}n| }|}tdd || jdD }|D ]
}|	 }||  q5d S )	Nr   )metadata   )   
   )groupc                 s   s    | ]}|V  qd S N ).0epr)   r)   W/var/www/html/backend_erp/backend_erp_env/lib/python3.10/site-packages/gevent/events.py	<genexpr>   s
    
z/notify_and_call_entry_points.<locals>.<genexpr>r)   )
r"   	importlibr#   sysversion_infoentry_pointsENTRY_POINT_NAMEsetgetload)eventr#   r/   r1   ep_dict__traceback_info__plugin
subscriberr)   r)   r,   notify_and_call_entry_pointsi   s   

r;   c                   @      e Zd ZdZdd ZdS )r   zY
    The contract for the periodic monitoring thread that is started
    by the hub.
    c                 C      dS )a8  
        Schedule the *function* to be called approximately every *period* fractional seconds.

        The *function* receives one argument, the hub being monitored. It is called
        in the monitoring thread, *not* the hub thread. It **must not** attempt to
        use the gevent asynchronous API.

        If the *function* is already a monitoring function, then its *period*
        will be updated for future runs.

        If the *period* is ``None``, then the function will be removed.

        A *period* less than or equal to zero is not allowed.
        Nr)   )functionperiodr)   r)   r,   add_monitoring_function       z.IPeriodicMonitorThread.add_monitoring_functionN)__name__
__module____qualname____doc__r@   r)   r)   r)   r,   r          r   c                   @      e Zd ZdZedZdS )r   z
    The event emitted when a hub starts a periodic monitoring thread.

    You can use this event to add additional monitoring functions.
    z:The instance of `IPeriodicMonitorThread` that was started.N)rB   rC   rD   rE   r    monitorr)   r)   r)   r,   r      s    r   c                   @      e Zd ZdZdZdd ZdS )r   zL
    The implementation of :class:`IPeriodicMonitorThreadStartedEvent`.
    z2gevent.plugins.hub.periodic_monitor_thread_startedc                 C   s
   || _ d S r(   )rH   )selfrH   r)   r)   r,   __init__   s   
z*PeriodicMonitorThreadStartedEvent.__init__N)rB   rC   rD   rE   r2   rK   r)   r)   r)   r,   r      s    r   c                   @   (   e Zd ZdZedZedZedZdS )r   zm
    The event emitted when the event loop is blocked.

    This event is emitted in the monitor thread.
    z3The greenlet that appeared to be blocking the loop.z:The approximate time in seconds the loop has been blocked.z0A sequence of string lines providing extra info.N)rB   rC   rD   rE   r    greenletblocking_timeinfor)   r)   r)   r,   r      s
    r   c                   @   r<   )r   z`
    The event emitted when the event loop is blocked.

    Implements `IEventLoopBlocked`.
    c                 C      || _ || _|| _d S r(   )rM   rN   rO   )rJ   rM   rN   rO   r)   r)   r,   rK         
zEventLoopBlocked.__init__N)rB   rC   rD   rE   rK   r)   r)   r)   r,   r      s    r   c                   @   rL   )r   aE  
    The event emitted when the memory usage threshold is exceeded.

    This event is emitted only while memory continues to grow
    above the threshold. Only if the condition or stabilized is corrected (memory
    usage drops) will the event be emitted in the future.

    This event is emitted in the monitor thread.
    +The current process memory usage, in bytes.+The maximum allowed memory usage, in bytes.1The tuple of memory usage stats return by psutil.N)rB   rC   rD   rE   r    	mem_usagemax_allowedmemory_infor)   r)   r)   r,   r      s
    
r   c                   @   s   e Zd Zdd Zdd ZdS )_AbstractMemoryEventc                 C   rP   r(   )rU   rV   rW   )rJ   rU   rV   rW   r)   r)   r,   rK      rQ   z_AbstractMemoryEvent.__init__c                 C   s   d| j j| j| j| jf S )Nz<%s used=%d max=%d details=%r>)	__class__rB   rU   rV   rW   rJ   r)   r)   r,   __repr__   s   z_AbstractMemoryEvent.__repr__N)rB   rC   rD   rK   r[   r)   r)   r)   r,   rX      s    rX   c                   @      e Zd ZdZdS )r	   z<
    Implementation of `IMemoryUsageThresholdExceeded`.
    NrB   rC   rD   rE   r)   r)   r)   r,   r	          r	   c                   @   s0   e Zd ZdZedZedZedZedZdS )r
   a  
    The event emitted when the memory usage drops below the
    threshold after having previously been above it.

    This event is emitted only the first time memory usage is detected
    to be below the threshold after having previously been above it.
    If memory usage climbs again, a `IMemoryUsageThresholdExceeded`
    event will be broadcast, and then this event could be broadcast again.

    This event is emitted in the monitor thread.
    rR   rS   zNThe memory usage that caused the previous IMemoryUsageThresholdExceeded event.rT   N)	rB   rC   rD   rE   r    rU   rV   max_memory_usagerW   r)   r)   r)   r,   r
      s    r
   c                       s    e Zd ZdZ fddZ  ZS )r   z9
    Implementation of `IMemoryUsageUnderThreshold`.
    c                    s   t t| ||| || _d S r(   )superr   rK   r_   )rJ   rU   rV   rW   	max_usagerY   r)   r,   rK     s   
z"MemoryUsageUnderThreshold.__init__)rB   rC   rD   rE   rK   __classcell__r)   r)   rb   r,   r   	  s    r   c                   @       e Zd ZdZedZedZdS )r   z<
    The root for all monkey-patch events gevent emits.
    z)The source object containing the patches.z%The destination object to be patched.N)rB   rC   rD   rE   r    sourcetargetr)   r)   r)   r,   r     s    r   c                   @   s    e Zd ZdZdd Zdd ZdS )r   z0
    Implementation of `IGeventPatchEvent`.
    c                 C   s   || _ || _d S r(   )re   rf   )rJ   re   rf   r)   r)   r,   rK   "  s   
zGeventPatchEvent.__init__c                 C   s   d| j j| j| jt| f S )Nz<%s source=%r target=%r at %x>)rY   rB   re   rf   idrZ   r)   r)   r,   r[   &  s
   zGeventPatchEvent.__repr__N)rB   rC   rD   rE   rK   r[   r)   r)   r)   r,   r     s    r   c                   @   r\   )r   z
    An event emitted *before* gevent monkey-patches something.

    If a subscriber raises `DoNotPatch`, then patching this particular
    item will not take place.
    Nr]   r)   r)   r)   r,   r   ,      r   c                   @   r\   )r   z
    Subscribers to will-patch events can raise instances
    of this class to tell gevent not to patch that particular item.
    Nr]   r)   r)   r)   r,   r   5  rh   r   c                   @   r\   )r   z4
    Implementation of `IGeventWillPatchEvent`.
    Nr]   r)   r)   r)   r,   r   <  r^   r   c                   @   r\   )r   z@
    An event emitted *after* gevent has patched something.
    Nr]   r)   r)   r)   r,   r   B  rh   r   c                   @   r\   )GeventDidPatchEventz3
    Implementation of `IGeventDidPatchEvent`.
    Nr]   r)   r)   r)   r,   ri   G  r^   ri   c                   @   rd   )r   z
    An event emitted *before* gevent begins patching a specific module.

    Both *source* and *target* attributes are module objects.
    NThe name of the module being patched. This is the same as ``target.__name__``.zLThe list of item names to patch. This can be modified in place with caution.N)rB   rC   rD   rE   r    module_nametarget_item_namesr)   r)   r)   r,   r   M  s    r   c                       $   e Zd ZdZdZ fddZ  ZS )r   z:
    Implementation of `IGeventWillPatchModuleEvent`.
    z'gevent.plugins.monkey.will_patch_modulec                    s"   t t| || || _|| _d S r(   )r`   r   rK   rk   rl   )rJ   rk   re   rf   itemsrb   r)   r,   rK   d     
z#GeventWillPatchModuleEvent.__init__rB   rC   rD   rE   r2   rK   rc   r)   r)   rb   r,   r   Z      r   c                   @   rG   )r   zW
    An event emitted *after* gevent has completed patching a specific
    module.
    rj   N)rB   rC   rD   rE   r    rk   r)   r)   r)   r,   r   j  rF   r   c                       rm   )r   z9
    Implementation of `IGeventDidPatchModuleEvent`.
    z&gevent.plugins.monkey.did_patch_modulec                    s   t t| || || _d S r(   )r`   r   rK   rk   )rJ   rk   re   rf   rb   r)   r,   rK   ~  s   
z"GeventDidPatchModuleEvent.__init__rp   r)   r)   rb   r,   r   t  rq   r   c                   @   s(   e Zd ZdZedZedZdd ZdS )r   a  
    An event emitted *before* gevent begins patching the system.

    Following this event will be a series of
    `IGeventWillPatchModuleEvent` and `IGeventDidPatchModuleEvent` for
    each patched module.

    Once the gevent builtin modules have been processed,
    `IGeventDidPatchBuiltinModulesEvent` will be emitted. Processing
    this event is an ideal time for third-party modules to be imported
    and patched (which may trigger its own will/did patch module
    events).

    Finally, a `IGeventDidPatchAllEvent` will be sent.

    If a subscriber to this event raises `DoNotPatch`, no patching
    will be done.

    The *source* and *target* attributes have undefined values.
    hA dictionary of all the arguments to `gevent.monkey.patch_all`. This dictionary should not be modified. jA dictionary of the extra arguments to `gevent.monkey.patch_all`. This dictionary should not be modified. c                 C   r=   )zP
        Return whether the module named *module_name* will be patched.
        Nr)   )rk   r)   r)   r,   will_patch_module  rA   z*IGeventWillPatchAllEvent.will_patch_moduleN)rB   rC   rD   rE   r    patch_all_argumentspatch_all_kwargsrt   r)   r)   r)   r,   r     s    r   c                       s<   e Zd Z fddZedd Zedd Zdd Z  ZS )	_PatchAllMixinc                    s"   t t| d d  || _|| _d S r(   )r`   rw   rK   _patch_all_arguments_patch_all_kwargs)rJ   ru   rv   rb   r)   r,   rK     ro   z_PatchAllMixin.__init__c                 C   
   | j  S r(   )rx   copyrZ   r)   r)   r,   ru        
z"_PatchAllMixin.patch_all_argumentsc                 C   rz   r(   )ry   r{   rZ   r)   r)   r,   rv     r|   z_PatchAllMixin.patch_all_kwargsc                 C   s   d| j j| jt| f S )Nz<%s %r at %x>)rY   rB   rx   rg   rZ   r)   r)   r,   r[     s   z_PatchAllMixin.__repr__)	rB   rC   rD   rK   propertyru   rv   r[   rc   r)   r)   rb   r,   rw     s    

rw   c                   @   rI   )r   z7
    Implementation of `IGeventWillPatchAllEvent`.
    z$gevent.plugins.monkey.will_patch_allc                 C   s   | j |S r(   )ru   r4   )rJ   rk   r)   r)   r,   rt     s   z)GeventWillPatchAllEvent.will_patch_moduleN)rB   rC   rD   rE   r2   rt   r)   r)   r)   r,   r     s    r   c                   @   rd   )r   z
    Event emitted *after* the builtin modules have been patched.

    If you're going to monkey-patch a third-party library, this is
    usually the event to listen for.

    The values of the *source* and *target* attributes are undefined.
    rr   rs   N)rB   rC   rD   rE   r    ru   rv   r)   r)   r)   r,   r     s    	r   c                   @      e Zd ZdZdZdS )r   zA
    Implementation of `IGeventDidPatchBuiltinModulesEvent`.
    z(gevent.plugins.monkey.did_patch_builtinsNrB   rC   rD   rE   r2   r)   r)   r)   r,   r         r   c                   @   r\   )r   z
    Event emitted after gevent has patched all modules, both builtin
    and those provided by plugins/subscribers.

    The values of the *source* and *target* attributes are undefined.
    Nr]   r)   r)   r)   r,   r     rh   r   c                   @   r~   )r   z6
    Implementation of `IGeventDidPatchAllEvent`.
    z#gevent.plugins.monkey.did_patch_allNr   r)   r)   r)   r,   r     r   r   ).rE   
__future__r   r   r   __all__platformzope.interfacer   r    r!   
zope.eventr   r"   unamer;   r   r   objectr   r   r   r   rX   r	   r
   r   r   r   r   BaseExceptionr   r   r   ri   r   r   r   r   r   rw   r   r   r   r   r   r)   r)   r)   r,   <module>   st   $$	
	
%	