PyR3.factory.fields package

Submodules

PyR3.factory.fields.Field module

class PyR3.factory.fields.Field.Field(**kwargs)[source]

Bases: ABC

abstract digest(value: Optional[Any] = None) None[source]

PyR3.factory.fields.Number module

class PyR3.factory.fields.Number.Float(*, default: Optional[float] = None, min: Optional[float] = None, max: Optional[float] = None)[source]

Bases: Field

check_if_in_range(parsed_float)[source]
digest(value: str | Number = None) None[source]
class PyR3.factory.fields.Number.Integer(*, default: Optional[int] = None, value_range: Optional[range] = None)[source]

Bases: Field

check_if_in_range(parsed_int)[source]
digest(value: str | Number = None) None[source]

PyR3.factory.fields.Select module

class PyR3.factory.fields.Select.Select(*values, default_index: Optional[int] = None)[source]

Bases: Field

digest(value: Optional[Any] = None) None[source]

PyR3.factory.fields.String module

class PyR3.factory.fields.String.Regex(pattern: re.Pattern | str, *, default: str = None, flags: int = 0)[source]

Bases: String

String field with possibility to use regular expression to check if string format is valid.

Parameters
  • pattern (re.Pattern or str) – Regular expression patter. String will be automatically compiled.

  • default (str, optional) – [description], defaults to None

  • flags (int, optional) – regular expression flags, from re module, defaults to 0

Raises

TypeError – if pattern is neither str or re.Pattern.

class PyR3.factory.fields.String.String(*, default: Optional[str] = None, min_length: Optional[int] = None, max_length: Optional[int] = None)[source]

Bases: Field

String factory field. You can specify length and default for it. Its value is always a string.

Parameters
  • default (str, optional) – Default value, used if no value is provided. If None, exception will be raised if no value will be given, defaults to None

  • min_length (int, optional) – Minimal length of string. Exception will be raised if requirement will not be fullfiled. Defaults to None

  • max_length (int, optional) – Minimal length of string. Exception will be raised if requirement will not be fullfiled. Defaults to None

digest(value: Optional[str] = None) str[source]

Consumes value and returns cleaned string. Raises exception if requirements for string format are not met.

Parameters

value (str, optional) – value to consume, defaults to None

Returns

cleaned string.

Return type

str

PyR3.factory.fields.Struct module

class PyR3.factory.fields.Struct.Struct[source]

Bases: Field

Parent class allowing to create custom struct classes grouping other field types by subclassing Struct in body of MeshFactory or another Strut field.

Struct field value is a SimpleNamespace.

digest(params: Optional[dict] = None) None[source]

Consumes dictionary of values and returns SimpleNamespace containing cleaned values of fields. Redundant params will be ignored. If a value is missing, None will be passed to coresponding field.

Parameters

params (dict, optional) – dictionary of values, defaults to None

Returns

namespace with cleaned values.

Return type

SimpleNamespace

PyR3.factory.fields.Unit module

class PyR3.factory.fields.Unit.Angle(*, output_unit: str = 'rad', default: str | Number = None)[source]

Bases: Length

Accepts float with optional angle unit suffix. Unit suffix causes float value to be converted to value with unit denoted by output_unit.

Valid unit suffixes are:

  • rad for radians

  • π / pi for radians, multiplied by π (3.14…)

  • deg for degrees

  • / sec for seconds of angle

  • / min for minutes of angle

Signs that doesn’t match anything are ignored and treated as separators.

parser = SuffixParser, suffixes: ['"', 'sec', "'", 'min', '°', 'deg', 'π', 'pi', 'rad', '']
class PyR3.factory.fields.Unit.Length(*, output_unit: str = 'm', default: str | Number = None)[source]

Bases: Field

Accepts float with optional length unit suffix. Unit suffix causes float value to be converted to value with unit denoted by output_unit.

Valid unit suffixes are:

  • mil for mils

  • in for inches

  • ft for feets

  • mm for millimeters

  • cm for centimeters

  • dm for decimeters

  • m for meters

Signs that doesn’t match anything are ignored and treated as separators.

digest(literal: str | Number = None) float[source]

Returns total value contained in the literal in meters.

Parameters

literal (Union[str, Number]) – literal to consume or Number

Raises
  • TypeError – If other type than str or Number is given.

  • KeyError – If value is None and no default is given.

Returns

total in meters.

Return type

float

parser = SuffixParser, suffixes: ['mil', 'in', 'ft', 'mm', 'cm', 'dm', 'm', '']

Module contents