
    6h                     R    S r SSKrSSKJr  SSKJrJrJr  / SQrS r	\S4S jr
S	 rg)
z
Commonly useful converters.
    N   )_AnnotationExtractor)NOTHINGFactorypipe)default_if_noneoptionalr   to_boolc                   ^  U 4S jn[        T 5      nUR                  5       nU(       a   [        R                  U   UR                  S'   UR                  5       nU(       a   [        R                  U   UR                  S'   U$ )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.

:param callable converter: the converter that is used for non-``None``
    values.

.. versionadded:: 17.1.0
c                    > U c  g T" U 5      $ N )val	converters    F/usr/lib/python3/dist-packages/mercurial/thirdparty/attr/converters.pyoptional_converter$optional.<locals>.optional_converter$   s    ;~    r   return)r   get_first_param_typetypingOptional__annotations__get_return_type)r   r   xtrtrts   `    r   r	   r	      sp    
 y
)C  "A4:OOA4F**51				B	7=r7J**84r   c                    ^  T [         L a  Uc  [        S5      eT [         La  Ub  [        S5      eUb  [        U5      m [        T [        5      (       a$  T R                  (       a  [        S5      eU 4S jnU$ U 4S jnU$ )ah  
A converter that allows to replace ``None`` values by *default* or the
result of *factory*.

:param default: Value to be used if ``None`` is passed. Passing an instance
   of `attrs.Factory` is supported, however the ``takes_self`` option
   is *not*.
:param callable factory: A callable that takes no parameters whose result
   is used if ``None`` is passed.

:raises TypeError: If **neither** *default* or *factory* is passed.
:raises TypeError: If **both** *default* and *factory* are passed.
:raises ValueError: If an instance of `attrs.Factory` is passed with
   ``takes_self=True``.

.. versionadded:: 18.2.0
z(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                 .   > U b  U $ TR                  5       $ r   )factoryr   defaults    r   default_if_none_converter2default_if_none.<locals>.default_if_none_converterY   s    
??$$r   c                    > U b  U $ T$ r   r   r!   s    r   r#   r$   a   s    
Nr   )r   	TypeErrorr   
isinstance
takes_self
ValueError)r"   r    r#   s   `  r   r   r   6   s    $ 'goBCCg'"5C
 	
 '"'7##C 	% %$	 %$r   c                     [        U [        5      (       a  U R                  5       n 1 Skn1 Skn X;   a  gX;   a  g [	        SR                  U 5      5      e! [         a     N&f = f)a  
Convert "boolean" strings (e.g., from env. vars.) to real booleans.

Values mapping to :code:`True`:

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

Values mapping to :code:`False`:

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

:raises ValueError: for any other value.

.. versionadded:: 21.3.0
>   T1r   yonyestrue>   F0fnnoofffalseTFz Cannot convert value to bool: {})r'   strlowerr&   r)   format)r   truthyfalsys      r   r
   r
   j   sm    4 #siik:F;E=< 
 7>>sC
DD  s   A A 
A#"A#)__doc__r   _compatr   _maker   r   r   __all__r	   r   r
   r   r   r   <module>r?      s8   
  ) ) )@ $T 1%h&Er   