zmc
2023-12-22 9fdbf60165db0400c2e8e6be2dc6e88138ac719a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
U
L±dã@sZdZddlZddlmZddlmZmZmZdddd    gZd
d„Z    edfd d„Z
d d    „Z dS) z
Commonly useful converters.
éNé)Ú_AnnotationExtractor)ÚNOTHINGÚFactoryÚpipeÚdefault_if_noneÚoptionalrÚto_boolcsP‡fdd„}tˆƒ}| ¡}|r0tj||jd<| ¡}|rLtj||jd<|S)aO
    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
    cs|dkr dSˆ|ƒS©N©©Úval©Ú    converterr úFd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\attr/converters.pyÚoptional_converter$sz$optional.<locals>.optional_converterr Úreturn)rZget_first_param_typeÚtypingÚOptionalÚ__annotations__Zget_return_type)rrZxtrÚtÚrtr rrrs csvˆtkr|dkrtdƒ‚ˆtk    r0|dk    r0tdƒ‚|dk    r@t|ƒ‰tˆtƒrfˆjrXtdƒ‚‡fdd„}n ‡fdd„}|S)aœ
    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
    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.cs|dk    r |Sˆ ¡Sr
)Úfactoryr ©Údefaultr rÚdefault_if_none_converterYsz2default_if_none.<locals>.default_if_none_convertercs|dk    r |SˆSr
r r rr rras)rÚ    TypeErrorrÚ
isinstanceZ
takes_selfÚ
ValueError)rrrr rrr6s ÿ
ÿ cCs‚t|tƒr| ¡}ddddddddh}d    d
d d d dddh}z ||krJWdS||krXWd    SWntk
rnYnXtd|›ƒ‚dS)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ÚtruerÚyesÚyÚonÚ1rFÚfalseÚfÚnoÚnÚoffÚ0rzCannot convert value to bool: N)rÚstrÚlowerrr)r ZtruthyZfalsyr r rr    js
 
) Ú__doc__rÚ_compatrÚ_makerrrÚ__all__rrr    r r r rÚ<module>s ü 4