graviti.portex.factory#

Template factory releated classes.

Module Contents#

Classes#

Factory

The base class of the template factory.

FrozenFieldsFactory

The factory for FrozenFields.

FrozenFieldsFactoryWrapper

The factory for FrozenFields which needs kwargs transformed.

ConnectedFieldsFactory

The factory for ConnectedFields.

TypeFactory

The template factory for portex type.

ConstantFactory

The template factory for a constant.

VariableFactory

The template factory for a variable.

ListFactory

The template factory for a list.

DictFactory

The template factory for a dict.

FieldFactory

The template factory for a tuple of name and PortexType.

FieldsFactory

The template factory for a Fields.

Functions#

mapping_unpack_factory_creator(decl, ptype)

Check the object unpack grammar and returns the corresponding factory.

type_factory_creator(decl, imports)

Check the input and returns the corresponding type factory.

string_factory_creator(decl, ptype = PTYPE.Any)

Check whether the input string is variable and returns the corresponding factory.

factory_creator(decl, imports, ptype = PTYPE.Any)

Check input type and returns the corresponding factory.

Attributes#

class graviti.portex.factory.Factory[source]#

The base class of the template factory.

class graviti.portex.factory.FrozenFieldsFactory(decl, imports)[source]#

Bases: Factory

The factory for FrozenFields.

Parameters
  • decl (Iterable[Dict[str, Any]]) – The decalaration of frozen fields.

  • imports (graviti.portex.package.Imports) – The Imports instance to specify the import scope of the fields.

class graviti.portex.factory.FrozenFieldsFactoryWrapper(factory, kwargs_transformer)[source]#

Bases: Factory

The factory for FrozenFields which needs kwargs transformed.

Parameters
graviti.portex.factory.UnionFieldsFactory[source]#
class graviti.portex.factory.ConnectedFieldsFactory(decl, class_, imports, kwargs_transformer)[source]#

The factory for ConnectedFields.

Parameters
  • decl (Dict[str, Any]) – A dict which indicates a portex type.

  • class – The base type.

  • imports (graviti.portex.package.Imports) – The Imports instance to specify the import scope of the template.

  • kwargs_transformer (Callable[Ellipsis, Dict[str, Any]]) – The method to transform the kwargs to the kwargs of base type.

  • class_ (Type[graviti.portex.base.PortexRecordBase]) –

classmethod from_parameter_name(cls, name)[source]#

Create ConnectedFieldsFactory for Fields with the given parameter name.

Parameters
  • name (str) – The parameter name of the input fields.

  • cls (Type[_CFF]) –

Returns

The created ConnectedFieldsFactory.

Return type

_CFF

class graviti.portex.factory.TypeFactory(decl, imports)[source]#

Bases: Factory

The template factory for portex type.

Parameters
transform_kwargs(self, kwargs)[source]#

Transform the keyword arguments to what the base type needs.

Parameters

kwargs (Dict[str, Any]) – The input arguments.

Returns

The transformed keyword arguments.

Return type

Dict[str, Any]

class graviti.portex.factory.ConstantFactory(decl)[source]#

Bases: Factory, Generic[_C]

The template factory for a constant.

Parameters

decl (_C) – The constant to be created by the factory.

class graviti.portex.factory.VariableFactory(decl, ptype=PTYPE.Any, is_unpack=False)[source]#

Bases: Factory

The template factory for a variable.

Parameters
  • decl (str) – The parameter name of the variable.

  • ptype (graviti.portex.ptype.PType) – The parameter type.

  • is_unpack (bool) –

class graviti.portex.factory.ListFactory(decl, ptype=PTYPE.Any)[source]#

Bases: Factory

The template factory for a list.

Parameters
  • decl (List[Any]) – A list template.

  • ptype (graviti.portex.ptype.PType) – The parameter type of the list.

class graviti.portex.factory.DictFactory(decl, ptype=PTYPE.Any)[source]#

Bases: Factory

The template factory for a dict.

Parameters
  • decl (Dict[str, Any]) – A dict template.

  • ptype (graviti.portex.ptype.PType) – The parameter type of the dict.

class graviti.portex.factory.FieldFactory(decl, imports)[source]#

Bases: Factory

The template factory for a tuple of name and PortexType.

Parameters
class graviti.portex.factory.FieldsFactory(decl, imports)[source]#

Bases: Factory

The template factory for a Fields.

Parameters
graviti.portex.factory.mapping_unpack_factory_creator(decl, ptype)[source]#

Check the object unpack grammar and returns the corresponding factory.

Parameters
  • decl (str) – The parameter decalaration.

  • ptype (graviti.portex.ptype.PType) – The parameter type of the input.

Raises

ValueError – When the object unpack grammar is incorrect.

Returns

A VariableFactory instance according to the input.

Return type

VariableFactory

graviti.portex.factory.type_factory_creator(decl, imports)[source]#

Check the input and returns the corresponding type factory.

Parameters
  • decl (Dict[str, Any]) – A dict which indicates a portex type or has object unpack grammar.

  • imports (graviti.portex.package.Imports) – The Imports instance to specify the import scope of the template.

Raises

ValueError – When setting the type name as a parameter.

Returns

A TypeFactory or a VariableFactory instance.

Return type

Union[TypeFactory, VariableFactory]

graviti.portex.factory.string_factory_creator(decl, ptype=PTYPE.Any)[source]#

Check whether the input string is variable and returns the corresponding factory.

Parameters
  • decl (str) – A string which indicates a constant or a variable.

  • ptype (graviti.portex.ptype.PType) – The parameter type of the string.

Returns

A VariableFactory or a ConstantFactory instance according to the input.

Return type

Union[VariableFactory, ConstantFactory[str]]

graviti.portex.factory.factory_creator(decl, imports, ptype=PTYPE.Any)[source]#

Check input type and returns the corresponding factory.

Parameters
  • decl (Any) – A template which indicates any Portex object.

  • imports (Optional[graviti.portex.package.Imports]) – The Imports instance to specify the import scope of the template.

  • ptype (graviti.portex.ptype.PType) – The parameter type of the input.

Returns

A Factory instance according the input.

Return type

Factory