o
    !i,                     @   s   d dl Z d dlZd dlZd dlmZ d dlmZ ddlmZ e 	dZ
e 	dZdZd	d
 Ze ZG dd deZdd Zdd Zdd Zdd Zdd ZejfddZdejdefddZdd ZdS )    N)OrderedDict)deepcopy   )
HTTPStatusz(.)([A-Z][a-z]+)z([a-z0-9])([A-Z]))mergecamel_to_dash
default_idnot_nonenot_none_sortedunpackBaseResponseimport_check_view_funcc                  C   sJ   ddl } t| jddd }|dk rddlm} |S ddlm} |S )znResolve `werkzeug` `Response` class import because
    `BaseResponse` was renamed in version 2.* to `Response`r   Nwerkzeug.   )r   )Response)importlib.metadataintmetadataversionsplitwerkzeug.wrappersr   r   )	importlibwerkzeug_majorr   r    r   V/var/www/html/crm_dreinet/venv_linux/lib/python3.10/site-packages/flask_restx/utils.pyimport_werkzeug_response   s   r   c                   @   s   e Zd ZdS )FlaskCompatibilityWarningN)__name__
__module____qualname__r   r   r   r   r   .   s    r   c                 C   sb   t |ts|S t| }| D ]\}}||v r(t || tr(t|| |||< qt|||< q|S )aA  
    Recursively merges two dictionaries.

    Second dictionary values will take precedence over those from the first one.
    Nested dictionaries are merged too.

    :param dict first: The first dictionary
    :param dict second: The second dictionary
    :return: the resulting merged dictionary
    :rtype: dict
    )
isinstancedictr   itemsr   )firstsecondresultkeyvaluer   r   r   r   2   s   
r   c                 C   s   t d| }td| S )z
    Transform a CamelCase string into a low_dashed one

    :param str value: a CamelCase string to transform
    :return: the low_dashed string
    :rtype: str
    z\1_\2)FIRST_CAP_REsub
ALL_CAP_RElower)r(   	first_capr   r   r   r   I   s   r   c                 C   s   d |t| S )zDefault operation ID generatorz{0}_{1})formatr   )resourcemethodr   r   r   r   U   s   r   c                 C   s   t dd |  D S )z
    Remove all keys where value is None

    :param dict data: A dictionary with potentially some values set to None
    :return: The same dictionary without the keys with values to ``None``
    :rtype: dict
    c                 s   $    | ]\}}|d ur||fV  qd S Nr   .0kvr   r   r   	<genexpr>b      " znot_none.<locals>.<genexpr>)r"   r#   datar   r   r   r	   Z   s   r	   c                 C   s   t dd t|  D S )z
    Remove all keys where value is None

    :param OrderedDict data: A dictionary with potentially some values set to None
    :return: The same dictionary without the keys with values to ``None``
    :rtype: OrderedDict
    c                 s   r1   r2   r   r3   r   r   r   r7   m   r8   z"not_none_sorted.<locals>.<genexpr>)r   sortedr#   r9   r   r   r   r
   e   s   r
   c                 C   sx   t | ts
| |i fS t| dkr| d |i fS t| dkr&| \}}||i fS t| dkr8| \}}}||p5||fS td)ao  
    Unpack a Flask standard response.

    Flask response can be:
    - a single value
    - a 2-tuple ``(value, code)``
    - a 3-tuple ``(value, code, headers)``

    .. warning::

        When using this function, you must ensure that the tuple is not the response data.
        To do so, prefer returning list instead of tuple for listings.

    :param response: A Flask style response
    :param int default_code: The HTTP code to use as default if none is provided
    :return: a 3-tuple ``(data, code, headers)``
    :rtype: tuple
    :raise ValueError: if the response does not have one of the expected format
    r   r   r      zToo many response values)r!   tuplelen
ValueError)responsedefault_coder:   codeheadersr   r   r   r   p   s   



r   	view_funcreturnc                 C   s   | dusJ d| j S )zHelper that returns the default endpoint for a given
    function. This always is the function name.

    Note: copy of simple flask internal helper
    Nz/expected view func if endpoint is not provided.)r   )rD   r   r   r   to_view_name   s   rF   c                  C   s   ddl } | jdd}z1|d dkrddlm} n"|d dkr(ddlm} n|d dkr5ddlm} nt	d	t
 d}W n tyO   t	d	t
 d}Y nw |du rVt}|S )
a0  
    Resolve import flask _endpoint_from_view_func.

    Show warning if function cannot be found and provide copy of last known implementation.

    Note: This helper method exists because reoccurring problem with flask function, but
    actual method body remaining the same in each flask version.
    r   Nflaskr   1)_endpoint_from_view_func23once)r   r   r   r   flask.helpersrI   flask.scaffoldflask.sansio.scaffoldwarningssimplefilterr   ImportErrorrF   )r   flask_versionrI   r   r   r   r      s&   	r   )rerP   typingcollectionsr   copyr   _httpr   compiler)   r+   __all__r   r   DeprecationWarningr   r   r   r   r	   r
   OKr   CallablestrrF   r   r   r   r   r   <module>   s(    

&
