o
    0׾gS                     @   s  d Z ddlmZmZmZ ddlZddlZddlZddlm	Z	 ddlm
Z
 dgZg ZG dd deZd	d
 Zdd Zdd ZeZG dd deZedefeejZ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G dd deZG dd deZG dd  d eZG d!d" d"eeZG d#d$ d$eeZ G d%d& d&eeZ!G d'd( d(eeZ"G d)d* d*eeZ#G d+d, d,eZ$G d-d. d.eeZ%G d/d0 d0eeZ&G d1d2 d2eeZ'G d3d4 d4eeZ(G d5d6 d6eeZ)G d7d8 d8eeZ*G d9d: d:eeZ+G d;d< d<eeZ,G d=d> d>eZ-G d?d@ d@e-eZ.G dAdB dBe-eZ/G dCdD dDe-eZ0G dEdF dFe-eZ1G dGdH dHe-eZ2G dIdJ dJe-eZ3G dKdL dLe-eZ4G dMdN dNe-eZ5G dOdP dPee-eZ6e Z7ze" 8  W n
 e9yx   Y nw e:dQkre7;  dS dS )Rak  
gevent tunables.

This should be used as ``from gevent import config``. That variable
is an object of :class:`Config`.

.. versionadded:: 1.3a2

.. versionchanged:: 22.08.0
   Invoking this module like ``python -m gevent._config`` will
   print a help message about available configuration properties.
   This is handy to quickly look for environment variables.
    )print_functionabsolute_importdivisionN)string_types)WINconfigc                   @   s   e Zd Zdd Zdd ZdS )SettingTypec                    s   |dkrt | |||S tt|d< d|vr| |d< d|vr*d|d   |d< t | |||}||dd |j|_	t
| |jrg|d   fdd	} fd
d}t|||j	d}tt|d | |S )NSettingordernameenvironment_keyGEVENT_desc c                    s   | j    S N)settingsgetselfsetting_name X/var/www/html/backend_erp/backend_erp_env/lib/python3.10/site-packages/gevent/_config.pygetter6      z#SettingType.__new__.<locals>.getterc                    s   | j   | d S r   )r   setr   valuer   r   r   setter9   s   z#SettingType.__new__.<locals>.setter)doc)type__new__lenALL_SETTINGSlowerupperfmt_descr   r   __doc__appenddocumentpropertysetattrConfig)clsr   basescls_dict	new_classr   r   propr   r   r   r!   "   s$   
zSettingType.__new__c                 C   s   t | }t| dr|d7 }| jr|dt| jf 7 }t| jdr0|dt | jj  7 }t	| j
trBt| drBd| j
f }nd| j
f }|d|f 7 }|d	| jf 7 }t| d
| |S )Nshortname_mapa5  

This is an importable value. It can be given as a string naming an importable object, or a list of strings in preference order and the first successfully importable object will be used. (Separate values in the environment variable with commas.) It can also be given as the callable object itself (in code). z*Shorthand names for default objects are %rr'   z

z`%s`z`%r`z

The default value is %sz>

The environment variable ``%s`` can be used to control this.r   )textwrapdedentstriphasattrr2   listgetattrvalidater'   
isinstancedefaultstrr   r+   )r-   r   r;   r   r   r   r&   D   s$   
zSettingType.fmt_descN)__name__
__module____qualname__r!   r&   r   r   r   r   r      s    "r   c                 C   s   t d| f )NzNot a valid value: %r
ValueErrorr   r   r   r   validate_invalid]   r   rC   c                 C   sX   t | tr(|   } | dv rd} t| S | dv s| s!d} t| S td| f t| S )z
    This is a boolean value.

    In the environment variable, it may be given as ``1``, ``true``,
    ``on`` or ``yes`` for `True`, or ``0``, ``false``, ``off``, or
    ``no`` for `False`.
    )1trueonyesT)0falseoffnoFzInvalid boolean string: %r)r:   r   r$   r5   rA   boolrB   r   r   r   validate_bool`   s   
rM   c                 C   s   | S r   r   rB   r   r   r   validate_anythingr   s   rN   c                   @   sL   e Zd ZdZdZeeZdZdZ	dZ
dZdd Zdd Zdd	 Zd
d ZdS )r	   NTzT
    A long ReST description.

    The first line should be a single sentence.

    c                 C   s   t |tr
|dS |S )N,)r:   r   splitr   r   r   r   _convert   s   

zSetting._convertc                 C   s    t j| j| j}| |}|S r   )osenvironr   r   r;   rQ   )r   resultr   r   r   _default   s   
zSetting._defaultc                 C   s&   d| j v r| jS | |  | _| jS )Nr   )__dict__r   r9   rU   r   r   r   r   r      s   
zSetting.getc                 C   s   |  | || _d S r   )r9   rQ   r   )r   valr   r   r   r      s   zSetting.set)r=   r>   r?   r   r   staticmethodrC   r9   r;   r   r)   r   rQ   rU   r   r   r   r   r   r   r	   w   s    	r	   c                  C   s0   i } t D ]}| }|j| vsJ || |j< q| S )zJ
    Return fresh instances of all classes defined in `ALL_SETTINGS`.
    )r#   r   )r   setting_kindsettingr   r   r   make_settings   s   r[   c                       sH   e Zd ZdZdd Zdd Z fddZdd	 Zd
d Zdd Z	  Z
S )r,   a"  
    Global configuration for gevent.

    There is one instance of this object at ``gevent.config``. If you
    are going to make changes in code, instead of using the documented
    environment variables, you need to make the changes before using
    any parts of gevent that might need those settings. For example::

        >>> from gevent import config
        >>> config.fileobject = 'thread'

        >>> from gevent import fileobject
        >>> fileobject.FileObject.__name__
        'FileObjectThread'

    .. versionadded:: 1.3a2

    c                 C   s   t  | _d S r   )r[   r   r   r   r   r   __init__   s   zConfig.__init__c                 C   s$   || j vrtd| | j |  S Nz No configuration setting for: %r)r   AttributeErrorr   )r   r   r   r   r   __getattr__   s   
zConfig.__getattr__c                    s8   |dkr|| j v r| || d S tt| || d S )Nr   )r   r   superr,   __setattr__r   r   r   	__class__r   r   ra      s   zConfig.__setattr__c                 C   s*   || j vrtd| | j | | d S r]   )r   r^   r   rb   r   r   r   r      s   
z
Config.setc                 C   s
   t | jS r   )r7   r   r   r   r   r   __dir__   s   
zConfig.__dir__c                 C   s<   | j  D ]\}}t| tt|j d t  qd S )Nz    )r   itemsprintr3   indentr'   lstrip)r   kvr   r   r   
print_help   s
   zConfig.print_help)r=   r>   r?   r'   r\   r_   ra   r   re   rl   __classcell__r   r   rc   r   r,      s    r,   c                   @   s6   e Zd Zdd Ze fddZi Zdd Zdd Zd	S )
ImportableSettingc              	   C   s\   t |tsJ |std|d d D ]}z| |W   S  ty&   Y qw | |d S )NzCannot import from empty list)r:   r7   ImportError_import_one)r   
candidatesitemr   r   r   _import_one_of   s   z ImportableSetting._import_one_ofc                 C   sv   t |ts|S d|vsd|v rtd|t| jf |dd\}}t|}t|||}||u r9td||f |S )N./zLCannot import %r. Required format: [package.]module.class. Or choose from %r   zCannot import %r from %r)	r:   r   rp   r7   r2   rsplit	importlibimport_moduler8   )r   path_MISSINGmodulers   xr   r   r   rq      s   

zImportableSetting._import_onec                    s&   t |tr|S   fdd|D S )Nc                    s   g | ]	} j ||qS r   )r2   r   ).0r~   r   r   r   
<listcomp>  s    z.ImportableSetting.validate.<locals>.<listcomp>)r:   r    rt   r   r   r   r   r9      s   
zImportableSetting.validatec                 C   sZ   i }| j  D ]#\}}z	| |||< W q ty* } z
|||< W Y d }~qd }~ww |S r   )r2   rf   rq   rp   )r   rT   r   rW   er   r   r   get_options  s   zImportableSetting.get_optionsN)	r=   r>   r?   rt   objectrq   r2   r9   r   r   r   r   r   rn      s    rn   c                   @   s   e Zd ZeeZeeZdS )BoolSettingMixinN)r=   r>   r?   rX   rM   r9   convert_str_value_as_isrQ   r   r   r   r   r     s    r   c                   @   s   e Zd Zdd ZeeZdS )IntSettingMixinc                 C      |rt |S d S r   )intr   r   r   r   rQ        zIntSettingMixin._convertN)r=   r>   r?   rQ   rX   rN   r9   r   r   r   r   r     s    r   c                   @      e Zd Zdd ZdS )_PositiveValueMixinc                 C   s   |d ur|dkrt d|S )Nr   zMust be positiver@   r   r   r   r   r9      s   z_PositiveValueMixin.validateN)r=   r>   r?   r9   r   r   r   r   r     s    r   c                   @   r   )FloatSettingMixinc                 C   r   r   )floatr   r   r   r   rQ   '  r   zFloatSettingMixin._convertN)r=   r>   r?   rQ   r   r   r   r   r   &  s    r   c                   @   s$   e Zd ZddddZdZdd ZdS )	ByteCountSettingMixini   i   i   @)kbmbgb   c                 C   sf   |rt |ts	|S | }| j D ]\}}|| j d  |kr.t|d | j  |   S qt|S r   )r:   r<   r$   
_MULTIPLESrf   _SUFFIX_SIZEr   )r   r   smr   r   r   rQ   7  s   zByteCountSettingMixin._convertN)r=   r>   r?   r   r   rQ   r   r   r   r   r   ,  s    r   c                   @   s&   e Zd ZdZg dZdddddZdS )	Resolverz    The callable that will be used to create
    :attr:`gevent.hub.Hub.resolver`.

    See :doc:`dns` for more information.
    )thread	dnspythonaresblockzgevent.resolver.ares.Resolverzgevent.resolver.thread.Resolverz!gevent.resolver.blocking.Resolverz"gevent.resolver.dnspython.Resolver)r   r   r   r   N)r=   r>   r?   r   r;   r2   r   r   r   r   r   A  s    
r   c                   @      e Zd ZdZdZdS )
Threadpoolz'    The kind of threadpool we use.
    zgevent.threadpool.ThreadPoolN)r=   r>   r?   r   r;   r   r   r   r   r   Z  s    r   c                   @   s    e Zd ZdZdZdZdZdZdS )ThreadpoolIdleTaskTimeoutTthreadpool_idle_task_timeout#GEVENT_THREADPOOL_IDLE_TASK_TIMEOUTz    How long threads in the default threadpool (used for
    DNS by default) are allowed to be idle before exiting.

    Use -1 for no timeout.

    .. versionadded:: 22.08.0
    g      @N)r=   r>   r?   r)   r   r   r   r;   r   r   r   r   r   b  s    r   c                   @   s<   e Zd ZdZesg dng dZddddZed ed< d	S )
Loopz    The kind of the loop we use.

    On Windows, this defaults to libuv, while on
    other platforms it defaults to libev.

    )
libev-cext
libev-cffi
libuv-cffi)r   r   r   zgevent.libev.corecext.loopzgevent.libev.corecffi.loopzgevent.libuv.loop.loopr   libuvN)r=   r>   r?   r   r   r;   r2   r   r   r   r   r   u  s    
r   c                   @   r   )FormatContextformat_contextzpprint.safereprN)r=   r>   r?   r   r;   r   r   r   r   r     s    r   c                   @   s$   e Zd ZdZdZdZdZeeZ	dS )LibevBackendlibev_backendGEVENT_BACKENDz0    The backend for libev, such as 'select'
    N)
r=   r>   r?   r   r   r   r;   rX   rN   r9   r   r   r   r   r     s    r   c                   @   s(   e Zd ZdZdZddgZddddZd	S )

FileObjectzo    The kind of ``FileObject`` we will use.

    See :mod:`gevent.fileobject` for a detailed description.

    GEVENT_FILEposixr   z)gevent._fileobjectcommon.FileObjectThreadz'gevent._fileobjectposix.FileObjectPosixz(gevent._fileobjectcommon.FileObjectBlock)r   r   r   N)r=   r>   r?   r   r   r;   r2   r   r   r   r   r     s    
r   c                   @      e Zd ZdZdZdZdZdS )WatchChildrenz    Should we *not* watch children with the event loop watchers?

    This is an advanced setting.

    See :mod:`gevent.os` for a detailed description.
    disable_watch_childrenGEVENT_NOWAITPIDFN)r=   r>   r?   r   r   r   r;   r   r   r   r   r     s
    r   c                   @   r   )TraceMalloctrace_mallocPYTHONTRACEMALLOCFan      Should FFI objects track their allocation?

    This is only useful for low-level debugging.

    On Python 3, this environment variable is built in to the
    interpreter, and it may also be set with the ``-X
    tracemalloc`` command line argument.

    On Python 2, gevent interprets this argument and adds extra
    tracking information for FFI objects.
    Nr=   r>   r?   r   r   r;   r   r   r   r   r   r     
    r   c                   @   r   )TrackGreenletTreetrack_greenlet_treeGEVENT_TRACK_GREENLET_TREETa      Should `Greenlet` objects track their spawning tree?

    Setting this to a false value will make spawning `Greenlet`
    objects and using `spawn_raw` faster, but the
    ``spawning_greenlet``, ``spawn_tree_locals`` and ``spawning_stack``
    will not be captured. Setting this to a false value can also
    reduce memory usage because capturing the stack captures
    some information about Python frames.

    .. versionadded:: 1.3b1
    Nr   r   r   r   r   r     r   r   c                   @   r   )MonitorThreadmonitor_threadGEVENT_MONITOR_THREAD_ENABLEFae      Should each hub start a native OS thread to monitor
    for problems?

    Such a thread will periodically check to see if the event loop
    is blocked for longer than `max_blocking_time`, producing output on
    the hub's exception stream (stderr by default) if it detects this condition.

    If this setting is true, then this thread will be created
    the first time the hub is switched to,
    or you can call :meth:`gevent.hub.Hub.start_periodic_monitoring_thread` at any
    time to create it (from the same thread that will run the hub). That function
    will return an instance of :class:`gevent.events.IPeriodicMonitorThread`
    to which you can add your own monitoring functions. That function
    also emits an event of :class:`gevent.events.PeriodicMonitorThreadStartedEvent`.

    .. seealso:: `max_blocking_time`

    .. versionadded:: 1.3b1
    Nr   r   r   r   r   r     r   r   c                   @   r   )MaxBlockingTimemax_blocking_timeGEVENT_MAX_BLOCKING_TIMEg?a      If the `monitor_thread` is enabled, this is
    approximately how long (in seconds)
    the event loop will be allowed to block before a warning is issued.

    This function depends on using `greenlet.settrace`, so installing
    your own trace function after starting the monitoring thread will
    cause this feature to misbehave unless you call the function
    returned by `greenlet.settrace`. If you install a tracing function *before*
    the monitoring thread is started, it will still be called.

    .. note:: In the unlikely event of creating and using multiple different
        gevent hubs in the same native thread in a short period of time,
        especially without destroying the hubs, false positives may be reported.

    .. versionadded:: 1.3b1
    Nr   r   r   r   r   r     s
    r   c                   @   r   )MonitorMemoryPeriodmemory_monitor_periodGEVENT_MONITOR_MEMORY_PERIOD   a0      If `monitor_thread` is enabled, this is approximately how long
    (in seconds) we will go between checking the processes memory usage.

    Checking the memory usage is relatively expensive on some operating
    systems, so this should not be too low. gevent will place a floor
    value on it.
    Nr   r   r   r   r   r   %  
    r   c                   @   s   e Zd ZdZdZdZdZdS )MonitorMemoryMaxUsagemax_memory_usageGEVENT_MONITOR_MEMORY_MAXNa      If `monitor_thread` is enabled,
    then if memory usage exceeds this amount (in bytes), events will
    be emitted. See `gevent.events`. In the environment variable, you can use
    a suffix of 'kb', 'mb' or 'gb' to specify the value in kilobytes, megabytes
    or gigibytes.

    There is no default value for this setting. If you wish to
    cap memory usage, you must choose a value.
    r   r   r   r   r   r   4  r   r   c                   @   s,   e Zd ZdZedd ZeeZee	Z
dS )AresSettingMixinFc                 C   s   | j dd  S )Nr   )r   r   r   r   r   
kwarg_nameM  s   zAresSettingMixin.kwarg_nameN)r=   r>   r?   r)   r*   r   rX   rN   r9   r   rQ   r   r   r   r   r   I  s    
r   c                   @      e Zd ZdZdZdZdS )	AresFlags
ares_flagsNGEVENTARES_FLAGSr=   r>   r?   r   r;   r   r   r   r   r   r   U      r   c                   @       e Zd ZdZdZdZdZdZdS )AresTimeoutTares_timeoutNGEVENTARES_TIMEOUTz
    .. deprecated:: 1.3a2
       Prefer the :attr:`resolver_timeout` setting. If both are set,
       the results are not defined.
    r=   r>   r?   r)   r   r;   r   r   r   r   r   r   r   Z      r   c                   @   r   )	AresTries
ares_triesNGEVENTARES_TRIESr   r   r   r   r   r   f  r   r   c                   @   r   )	AresNdots
ares_ndotsNGEVENTARES_NDOTSr   r   r   r   r   r   k  r   r   c                   @   r   )AresUDPPortares_udp_portNGEVENTARES_UDP_PORTr   r   r   r   r   r   p  r   r   c                   @   r   )AresTCPPortares_tcp_portNGEVENTARES_TCP_PORTr   r   r   r   r   r   u  r   r   c                   @   r   )AresServersTares_serversNGEVENTARES_SERVERSa)      A list of strings giving the IP addresses of nameservers for the ares resolver.

    In the environment variable, these strings are separated by commas.

    .. deprecated:: 1.3a2
       Prefer the :attr:`resolver_nameservers` setting. If both are set,
       the results are not defined.
    r   r   r   r   r   r   z  r   r   c                   @   s2   e Zd ZdZdZdZdZdZej	Z	e
dd ZdS )ResolverNameserversTresolver_nameserversNGEVENT_RESOLVER_NAMESERVERSa      A list of strings giving the IP addresses of nameservers for the (non-system) resolver.

    In the environment variable, these strings are separated by commas.

    .. rubric:: Resolver Behaviour

    * blocking

      Ignored

    * Threaded

      Ignored

    * dnspython

      If this setting is not given, the dnspython resolver will
      load nameservers to use from ``/etc/resolv.conf``
      or the Windows registry. This setting replaces any nameservers read
      from those means. Note that the file and registry are still read
      for other settings.

      .. caution:: dnspython does not validate the members of the list.
         An improper address (such as a hostname instead of IP) has
         undefined results, including hanging the process.

    * ares

      Similar to dnspython, but with more platform and compile-time
      options. ares validates that the members of the list are valid
      addresses.
    c                 C      dS )Nserversr   r   r   r   r   r        zResolverNameservers.kwarg_name)r=   r>   r?   r)   r   r;   r   r   r	   rQ   r*   r   r   r   r   r   r     s    #r   c                   @   s(   e Zd ZdZdZdZdZedd ZdS )ResolverTimeoutTresolver_timeoutGEVENT_RESOLVER_TIMEOUTz    The total amount of time that the DNS resolver will spend making queries.

    Only the ares and dnspython resolvers support this.

    .. versionadded:: 1.3a2
    c                 C   r   )Ntimeoutr   r   r   r   r   r     r   zResolverTimeout.kwarg_nameN)	r=   r>   r?   r)   r   r   r   r*   r   r   r   r   r   r     s    r   __main__)<r'   
__future__r   r   r   ry   rR   r3   gevent._compatr   r   __all__r#   r    r   rC   rM   rN   r   r   r	   dictrV   r[   r,   rn   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   r   r   rp   r=   rl   r   r   r   r   <module>   st   >'12	4
