graviti.portex.factory#

Template factory releated classes.

Module Contents#

Classes#

Factory

The base class of the template factory.

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.

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

The base class of the template factory.

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

Bases: Factory

The template factory for portex type.

Parameters
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