argsloader.units.build¶
TransformUnit¶
-
class
argsloader.units.build.
TransformUnit
(*values)[source]¶ - Overview:
Common transform unit.
-
__init__
(*values)[source]¶ Constructor of class
argsloader.units.base.TransformUnit
.- Parameters
values – Values need to be pre-processed, should be mapped one-to-one with
__names__
.
-
_easy_process
(v: argsloader.base.value.PValue, proxy: argsloader.units.base.UnitProcessProxy) → argsloader.base.result.ParseResult[source]¶ Easy process method,
proxy
can be used to quickly build parse result object.- Parameters
v –
PValue
object.proxy – Proxy object.
- Returns
Parse result object.
-
_transform
(v: argsloader.base.value.PValue, pres: Mapping[str, Any]) → argsloader.base.value.PValue[source]¶ Transform method.
- Parameters
v – Original
PValue
object.pres – Pre-processed values.
- Returns
Returned
PValue
object.- Raises
Exception – Raised exception which is instance of
__errors__
will be processed.
CalculateUnit¶
-
class
argsloader.units.build.
CalculateUnit
(*values)[source]¶ - Overview:
Simple value calculation unit.
-
_calculate
(v: object, pres: Mapping[str, Any]) → object[source]¶ Calculation method.
- Parameters
v – Original value.
pres – Pre-processed values.
- Returns
Returned value.
- Raises
Exception – Raised exception which is instance of
__errors__
will be processed.
-
_transform
(v: argsloader.base.value.PValue, pres: Mapping[str, Any]) → argsloader.base.value.PValue[source]¶ Transform method.
- Parameters
v – Original
PValue
object.pres – Pre-processed values.
- Returns
Returned
PValue
object.- Raises
Exception – Raised exception which is instance of
__errors__
will be processed.
UnitBuilder¶
-
class
argsloader.units.build.
UnitBuilder
[source]¶ A builder for units.
-
__init__
()[source]¶ Constructor of class
UnitBuilder
.
-
__repr__
()[source]¶ Get representation format of this builder.
- Examples::
>>> from argsloader.units import is_type, mul, add >>> from argsloader.units.base import BaseUnit >>> from argsloader.units.build import UnitBuilder >>> >>> class LinearFunctionBuilder(UnitBuilder): ... def __init__(self, k, b_): ... UnitBuilder.__init__(self) ... self.__k = k ... self.__b = b_ ... ... def _build(self) -> BaseUnit: ... return is_type((float, int)) >> mul.by(self.__k) >> add.by(self.__b) ... >>> LinearFunctionBuilder(2, 3) <LinearFunctionBuilder, unit: <PipeUnit count: 3> ├── 0 --> <IsTypeUnit> │ └── type --> tuple(2) │ ├── 0 --> <class 'float'> │ └── 1 --> <class 'int'> ├── 1 --> <MulOpUnit> │ ├── v1 --> <KeepUnit> │ └── v2 --> 2 └── 2 --> <AddOpUnit> ├── v1 --> <KeepUnit> └── v2 --> 3 >
-
_build
() → argsloader.units.base.BaseUnit[source]¶ Build a unit by the given variables. :return: A built unit.
Note
This method will be only executed once. The built unit will be cached in class
UnitBuilder
.
-
_rinfo
()[source]¶ Warning
Method
_rinfo()
is useless forUnitBuilder
.
-
call
(v, err_mode='ALL')[source]¶ Calculate with given value, similar to
__call__()
.See
argsloader.units.based.BaseUnit.call()
.
-
log
(v) → argsloader.base.result.ParseResult[source]¶ Get full log of this parsing process.
See
argsloader.units.based.BaseUnit.log()
.
-
property
unit
¶ Get built unit from this builder.
-
property
validity
¶ Validity of this unit.
See
argsloader.units.based.BaseUnit.validity
.
-