o
    NK&h4                  	   @  s  d dl mZ d dlmZ d dlmZ d dlmZmZm	Z	 d dl
mZ d dlmZ d dlmZmZmZ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 d dlmZ d dl m!Z! d dl"m#Z#m$Z$ eed ed ed ed ed ed f Z%dZ&i deddddddddddddd d!d"d#d$d%d&dd'd(d)d*d+ed,ed-d.d/d0i d1dd2ej'd3ed4ed5d(d6ed7dd8i d9dd:dd;d!d<d!d=d>d?d@dAdBdCdDdEdFdFd.eedGdHdHdIZ(G dJdK dKeZ)G dLdM dMe*e)dNZ+d!S )O    )annotations)ABCMeta)Sequence)
getmembersisclassisdatadescriptor)environ)Path)AnyCallableLiteralOptionalUnion)filterwarnings)LocalCertCreator)DEFAULT_FORMATcheck_error_format)Default_default)Http)error_logger)load_module_from_file_locationstr_to_booldefaulterrorignorealwaysmoduleonceSANIC__FALLBACK_ERROR_FORMAT
ACCESS_LOGFAUTO_EXTENDTAUTO_RELOADEVENT_AUTOREGISTERDEPRECATION_FILTERFORWARDED_FOR_HEADERzX-Forwarded-ForFORWARDED_SECRETNGRACEFUL_SHUTDOWN_TIMEOUTg      .@GRACEFUL_TCP_CLOSE_TIMEOUTg      @	INSPECTORINSPECTOR_HOST	localhostINSPECTOR_PORTi9  INSPECTOR_TLS_KEYINSPECTOR_TLS_CERTINSPECTOR_API_KEY KEEP_ALIVE_TIMEOUTx   
KEEP_ALIVELOCAL_CERT_CREATORLOCAL_TLS_KEYLOCAL_TLS_CERT	LOCALHOST	LOG_EXTRAMOTDMOTD_DISPLAYNO_COLORNOISY_EXCEPTIONSPROXIES_COUNTREAL_IP_HEADERREQUEST_BUFFER_SIZEi   REQUEST_MAX_HEADER_SIZEi    REQUEST_ID_HEADERzX-Request-IDREQUEST_MAX_SIZEi REQUEST_TIMEOUT<   i      )RESPONSE_TIMEOUTTLS_CERT_PASSWORDTOUCHUP
USE_UVLOOPWEBSOCKET_MAX_SIZEWEBSOCKET_PING_INTERVALWEBSOCKET_PING_TIMEOUTc                   @  s&   e Zd ZdZdd Zed	ddZdS )
DescriptorMetazMetaclass for Config.c                 G  s   dd t | | jD | _d S )Nc                 S  s   h | ]\}}|qS  rO   ).0name_rO   rO   ?/var/www/html/venv/lib/python3.10/site-packages/sanic/config.py	<setcomp>P   s    z*DescriptorMeta.__init__.<locals>.<setcomp>)r   
_is_setter__setters__)clsrR   rO   rO   rS   __init__O   s   zDescriptorMeta.__init__memberobjectc                 C  s   t | ot| dS )Nsetter)r   hasattr)rY   rO   rO   rS   rU   R   s   zDescriptorMeta._is_setterN)rY   rZ   )__name__
__module____qualname____doc__rX   staticmethodrU   rO   rO   rO   rS   rN   L   s
    rN   c                      s  e Zd ZU dZded< ded< ded< ded< ded< d	ed
< ded< ded< ded< ded< d	ed< ded< ded< ded< d	ed< ded< ded< ded< ded< ded< d	ed< ded < ded!< d"ed#< ded$< ded%< d&ed'< ded(< ded)< ded*< d	ed+< ded,< ded-< ded.< d	ed/< d	ed0< ded1< ded2< ded3< ded4< ded5< d6ed6fd6d7df fd?d@ZdgdCdDZdhdHdIZdhdJdKZ	di fdNdOZ
djdPdQZedkdRdSZejdTdS ZdUdV ZdWdX ZdldmdZd[Zefd\d]Zdnd`daZeZdodddeZ  ZS )pConfigzConfiguration object for Sanic.

    You can use this object to both: (1) configure how Sanic will operate, and
    (2) manage your application's custom configuration values.
    boolr!   r"   r#   r$   FilterWarningTyper%   strr&   Optional[str]r'   floatr(   r)   r*   r+   intr-   zUnion[Path, str, Default]r.   r/   r0   r2   r4   zUnion[str, LocalCertCreator]r5   r6   r7   r8   zUnion[Default, bool]r9   r:   zdict[str, str]r;   r<   r=   zOptional[int]r>   r?   r@   rA   rB   rC   rD   rG   SERVER_NAMErH   rI   rJ   rK   rL   rM   N)
convertersdefaults7Optional[dict[str, Union[str, bool, int, float, None]]]
env_prefix
keep_aliveOptional[bool]rj   (Optional[Sequence[Callable[[str], Any]]]c                  s   |pi }t  i t| |   ttttg| _|r%|D ]}| 	| q|d ur,|| _
|tkr8|r7| | n| t |   |   d| _d S )NT)superrX   DEFAULT_CONFIG_configure_warningsre   r   rg   rh   _convertersregister_typer4   SANIC_PREFIXload_environment_vars_configure_header_size_check_error_format_init)selfrk   rm   rn   rj   	converter	__class__rO   rS   rX      s"   



zConfig.__init__attrr
   c              
   C  s:   z| | W S  t y } ztd|jd  dd }~ww )NzConfig has no 'r   ')KeyErrorAttributeErrorargs)r{   r   kerO   rO   rS   __getattr__   s   
zConfig.__getattr__valuereturnNonec                 C     |  ||i d S Nupdater{   r   r   rO   rO   rS   __setattr__      zConfig.__setattr__c                 C  r   r   r   r   rO   rO   rS   __setitem__   r   zConfig.__setitem__otherkwargsc              	     s     dd |D   fddi   D }| D ]\}}z	t || W q ty2   Y qw t j di   i |  D ]
\}}|| qDdS )a  Update the config with new values.

        This method will update the config with the values from the provided
        `other` objects, and then update the config with the provided
        `kwargs`. The `other` objects can be any object that can be converted
        to a dictionary, such as a `dict`, `Config` object, or `str` path to a
        Python file. The `kwargs` must be a dictionary of key-value pairs.

        .. note::
            Only upper case settings are considered

        Args:
            *other: Any number of objects that can be converted to a
                dictionary.
            **kwargs: Any number of key-value pairs.

        Raises:
            AttributeError: If a key is not in the config.

        Examples:
            ```python
            config.update(
                {"A": 1, "B": 2},
                {"C": 3, "D": 4},
                E=5,
                F=6,
            )
            ```
        c                 S  s(   i | ]}t | D ]\}}||q
qS rO   )dictitems)rP   itemkvrO   rO   rS   
<dictcomp>   s   ( z!Config.update.<locals>.<dictcomp>c                   s$   i | ]}|j jv r| |qS rO   )r~   rV   pop)rP   r   r   r{   rO   rS   r      s
    
NrO   )r   keysr   rq   r   r   	_post_set)r{   r   r   setterskeyr   r   r}   r   rS   r      s   
zConfig.updatec                 C  sZ   |  dr|dv r|   |dkr!t| jts!t| j  | _d S |dkr+|   d S d S )Nrz   )rA   r@   rC   r5   r%   )getrx   
isinstancer5   r   upperrs   r   rO   rO   rS   r      s   


zConfig._post_setc                 C  s   t | jtrtS | jS r   )r   r    r   r   r{   rO   rO   rS   FALLBACK_ERROR_FORMAT   s   zConfig.FALLBACK_ERROR_FORMATc                 C  s4   |  | t| jts|| jkrtd || _d S )NzeSetting config.FALLBACK_ERROR_FORMAT on an already configured value may have unintended consequences.)ry   r   r    r   r   warning)r{   r   rO   rO   rS   r      s   



c                 C  s   t | j| jd | j d S )Ni   )r   set_header_max_sizerA   r@   rC   r   rO   rO   rS   rx   	  s
   zConfig._configure_header_sizec                 C  s   t | jtdd d S )Nzsanic.*)categoryr   )r   r%   DeprecationWarningr   rO   rO   rS   rs     s
   
zConfig._configure_warningsformatc                 C  s   t |p| j d S r   )r   r   )r{   r   rO   rO   rS   ry     r   zConfig._check_error_formatc              
   C  sn   t  D ]0\}}||r| sq||d\}}t| jD ]}z	||| |< W  n	 ty3   Y qw qdS )a7  Load environment variables into the config.

        Looks for prefixed environment variables and applies them to the
        configuration if present. This is called automatically when Sanic
        starts up to load environment variables into config. Environment
        variables should start with the defined prefix and should only
        contain uppercase letters.

        It will automatically hydrate the following types:

        - ``int``
        - ``float``
        - ``bool``

        Anything else will be imported as a ``str``. If you would like to add
        additional types to this list, you can use
        :meth:`sanic.config.Config.register_type`. Just make sure that they
        are registered before you instantiate your application.

        You likely won't need to call this method directly.

        See [Configuration](/en/guide/deployment/configuration) for more details.

        Args:
            prefix (str): The prefix to use when looking for environment
                variables. Defaults to `SANIC_`.


        Examples:
            ```python
            # Environment variables
            # SANIC_SERVER_NAME=example.com
            # SANIC_SERVER_PORT=9999
            # SANIC_SERVER_AUTORELOAD=true

            # Python
            app.config.load_environment_vars()
            ```
           N)r   r   
startswithisuppersplitreversedrt   
ValueError)r{   prefixr   r   rR   
config_keyr|   rO   rO   rS   rw     s   (zConfig.load_environment_varsconfig&Union[bytes, str, dict[str, Any], Any]c                   s   t  tttfrt d t  ts2i }t s(| fdd jj	
 D  t j	  | ttdd    |   dS )aV  Update app.config.

        .. note::

            Only upper case settings are considered

        See [Configuration](/en/guide/deployment/configuration) for more details.

        Args:
            config (Union[bytes, str, dict, Any]): Path to py file holding
                settings, dict holding settings, or any object holding
                settings.

        Examples:
            You can upload app config by providing path to py file
            holding settings.

            ```python
            # /some/py/file
            A = 1
            B = 2
            ```

            ```python
            config.update_config("${some}/py/file")
            ```

            Yes you can put environment variable here, but they must be provided
            in format: ``${some_env_var}``, and mark that ``$some_env_var`` is
            treated as plain string.

            You can upload app config by providing dict holding settings.

            ```python
            d = {"A": 1, "B": 2}
            config.update_config(d)
            ```

            You can upload app config by providing any object holding settings,
            but in such case config.__dict__ will be used as dict holding settings.

            ```python
            class C:
                A = 1
                B = 2

            config.update_config(C)
            ```
        )locationc                   s   i | ]}|t  |qS rO   )getattr)rP   r   r   rO   rS   r     s    
z(Config.update_config.<locals>.<dictcomp>c                 S  s   | d   S )Nr   )r   )irO   rO   rS   <lambda>  s    z&Config.update_config.<locals>.<lambda>N)r   bytesre   r	   r   r   r   r   r~   __dict__r   filterr   )r{   r   cfgrO   r   rS   update_configO  s   2





zConfig.update_configr|   Callable[[str], Any]c                 C  s2   || j v rtd|j d dS | j | dS )aP  Register a custom type converter.

        Allows for adding custom function to cast from a string value to any
        other type. The function should raise ValueError if it is not the
        correct type.

        Args:
            converter (Callable[[str], Any]): A function that takes a string
                and returns a value of any type.

        Examples:
            ```python
            def my_converter(value: str) -> Any:
                # Do something to convert the value
                return value

            config.register_type(my_converter)
            ```
        zConfiguration value converter 'z' has already been registeredN)rt   r   r   r]   append)r{   r|   rO   rO   rS   ru     s   
zConfig.register_type)rk   rl   rm   rf   rn   ro   rj   rp   )r   r
   )r   re   r   r
   r   r   )r   r
   r   r
   r   r   )r   r   )r   re   r   )r   rf   )r   r   )r|   r   r   r   )r]   r^   r_   r`   __annotations__rv   rX   r   r   r   r   r   propertyr   r[   rx   rs   ry   rw   r   loadru   __classcell__rO   rO   r}   rS   rb   W   s   
 
!


/

5Frb   )	metaclass),
__future__r   abcr   collections.abcr   inspectr   r   r   osr   pathlibr	   typingr
   r   r   r   r   warningsr   sanic.constantsr   sanic.errorpagesr   r   sanic.helpersr   r   
sanic.httpr   	sanic.logr   sanic.utilsr   r   rd   rv   AUTOrr   rN   r   rb   rO   rO   rO   rS   <module>   s    		
 !"#-