var/opt/nydus/ops/attr/__pycache__/converters.cpython-38.pyc000064400000006634147205560250020124 0ustar00U af @sZdZddlZddlmZddlmZmZmZdddd gZd dZ edfd dZ d d Z dS) z Commonly useful converters. N)_AnnotationExtractor)NOTHINGFactorypipedefault_if_noneoptionalrto_boolcsPfdd}t}|}|r0tj||jd<|}|rLtj||jd<|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 cs|dkr dS|SNval converterr @/opt/nydus/tmp/pip-target-53d1vnqk/lib/python/attr/converters.pyoptional_converter%sz$optional..optional_converterr return)rZget_first_param_typetypingOptional__annotations__Zget_return_type)rrZxtrtrtr rrrs cstkr|dkrd}t|tk r8|dk r8d}t||dk rHt|ttrrjrdd}t|fdd}n fdd}|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.cs|dk r |SSr )factoryr defaultr rdefault_if_none_converterasz2default_if_none..default_if_none_convertercs|dk r |SSr r r rr rris)r TypeErrorr isinstanceZ takes_self ValueError)rrmsgrr rrr7s  cCs@t|tr|}|dkrdS|dkr*dSd|}t|dS)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 )Ttrueryesyon1rT)Ffalsefnonoff0rFzCannot convert value to bool: N)rstrlowerr)r rr r rr rs  ) __doc__rZ_compatr_makerrr__all__rrr r r r rs !;