o
    诪g                     @   sZ   d Z ddlZddlmZ ddlmZmZmZmZ g dZ	dd Z
edfd	d
Zdd ZdS )z
Commonly useful converters.
    N   )_AnnotationExtractor)NOTHING	ConverterFactorypipe)default_if_noneoptionalr   to_boolc                    s   t  tr fdd}n fdd}t }| }|r$tj| |jd< | }|r2tj| |jd< t  tr>t|dddS |S )a_  
    A converter that allows an attribute to be optional. An optional attribute
    is one which can be set to `None`.

    Type annotations will be inferred from the wrapped converter's, if it has
    any.

    Args:
        converter (typing.Callable):
            the converter that is used for non-`None` values.

    .. versionadded:: 17.1.0
    c                    s   | d u rd S  | ||S N )valinstfield	converterr   K/var/www/html/chatdoc2/venv/lib/python3.10/site-packages/attr/converters.pyoptional_converter&   s   z$optional.<locals>.optional_converterc                    s   | d u rd S  | S r   r   r   r   r   r   r   -   s   r   returnT)
takes_selftakes_field)
isinstancer   r   get_first_param_typetypingOptional__annotations__get_return_type)r   r   xtrtrtr   r   r   r	      s   

r	   c                    s    t u r|du rd}t| t ur|durd}t||dur$t| t tr: jr2d}t| fdd}|S  fdd}|S )a  
    A converter that allows to replace `None` values by *default* or the result
    of *factory*.

    Args:
        default:
            Value to be used if `None` is passed. Passing an instance of
            `attrs.Factory` is supported, however the ``takes_self`` option is
            *not*.

        factory (typing.Callable):
            A callable that takes no parameters whose result is used if `None`
            is passed.

    Raises:
        TypeError: If **neither** *default* or *factory* is passed.

        TypeError: If **both** *default* and *factory* are passed.

        ValueError:
            If an instance of `attrs.Factory` is passed with
            ``takes_self=True``.

    .. versionadded:: 18.2.0
    Nz(Must pass either `default` or `factory`.z5Must pass either `default` or `factory` but not both.z1`takes_self` is not supported by default_if_none.c                    s   | d ur| S    S r   )factoryr   defaultr   r   default_if_none_converterl   s   z2default_if_none.<locals>.default_if_none_converterc                    s   | d ur| S  S r   r   r   r"   r   r   r$   t   s   )r   	TypeErrorr   r   r   
ValueError)r#   r!   msgr$   r   r"   r   r   B   s    
r   c                 C   s<   t | tr	|  } | dv rdS | dv rdS d| }t|)a  
    Convert "boolean" strings (for example, from environment variables) to real
    booleans.

    Values mapping to `True`:

    - ``True``
    - ``"true"`` / ``"t"``
    - ``"yes"`` / ``"y"``
    - ``"on"``
    - ``"1"``
    - ``1``

    Values mapping to `False`:

    - ``False``
    - ``"false"`` / ``"f"``
    - ``"no"`` / ``"n"``
    - ``"off"``
    - ``"0"``
    - ``0``

    Raises:
        ValueError: For any other value.

    .. versionadded:: 21.3.0
    )Ttruer   yesyon1r   T)Ffalsefnonoff0r   FzCannot convert value to bool: )r   strlowerr&   )r   r'   r   r   r   r
   }   s   

r
   )__doc__r   _compatr   _maker   r   r   r   __all__r	   r   r
   r   r   r   r   <module>   s   -;