graviti.portex.ptype#

Parameter type releated classes.

Module Contents#

Classes#

ParameterType

The base class of parameter type.

Any

Unconstrained parameter type.

Boolean

Parameter type for JSON Boolean.

Array

Parameter type for JSON Array.

Mapping

Parameter type for JSON object.

Number

Parameter type for JSON number.

Integer

Parameter type for JSON integer.

String

Parameter type for JSON string.

Enum

Parameter type for Portex enum values.

Field

Parameter type for Portex record field.

Fields

Parameter type for Portex record fields.

PortexType

Parameter type for Portex type.

Attributes#

class graviti.portex.ptype.ParameterType[source]#

The base class of parameter type.

static check(arg)[source]#

Check the parameter type.

Parameters

arg (Any) – The argument which needs to be checked.

Returns

The input argument unchanged.

Return type

Any

static load(content, _=None)[source]#

Create an instance of the parameter type from the python content.

Parameters
Returns

An instance of the parameter type.

Return type

Any

static dump(arg)[source]#

Dump the parameter type instance into the python presentation.

Parameters

arg (Any) – The parameter type instance.

Returns

The python presentation of the input instance.

Return type

Any

graviti.portex.ptype.PType[source]#
class graviti.portex.ptype.Any[source]#

Bases: ParameterType

Unconstrained parameter type.

class graviti.portex.ptype.Boolean[source]#

Bases: _JsonType

Parameter type for JSON Boolean.

class graviti.portex.ptype.Array[source]#

Bases: _JsonType

Parameter type for JSON Array.

class graviti.portex.ptype.Mapping[source]#

Bases: _JsonType

Parameter type for JSON object.

class graviti.portex.ptype.Number[source]#

Bases: _JsonType

Parameter type for JSON number.

class graviti.portex.ptype.Integer[source]#

Bases: _JsonType

Parameter type for JSON integer.

class graviti.portex.ptype.String[source]#

Bases: _JsonType

Parameter type for JSON string.

class graviti.portex.ptype.Enum[source]#

Bases: ParameterType

Parameter type for Portex enum values.

static check(arg)[source]#

Check and transfer the parameter type.

Parameters

arg (Any) – The argument which needs to be checked.

Raises
  • TypeError – When the argument is not iterable or the value of the input argument is not string type.

  • ValueError – When the value of the input argument does not fit the pattern.

Returns

A list of enum values created by the input argument.

Return type

List[str]

class graviti.portex.ptype.Field[source]#

Bases: ParameterType

Parameter type for Portex record field.

static check(arg)[source]#

Check and transfer the parameter type.

Parameters

arg (Any) – The argument which needs to be checked.

Raises

TypeError – When the input argument is not a tuple of a str and a PortexType.

Returns

A tuple of str and PortexType created by the input argument.

Return type

Tuple[str, graviti.portex.base.PortexType]

static load(content, imports=None)[source]#

Create Portex field instance from python dict.

Parameters
Returns

A tuple of name and PortexType created from the input python dict.

Return type

Tuple[str, graviti.portex.base.PortexType]

static dump(arg)[source]#

Dump the input Portex field instance to a python dict.

Parameters

arg (Tuple[str, graviti.portex.base.PortexType]) – A tuple of name and PortexType.

Returns

A Python dict representation of the Portex field.

Return type

Dict[str, Any]

class graviti.portex.ptype.Fields[source]#

Bases: ParameterType

Parameter type for Portex record fields.

static check(arg)[source]#

Check and transfer the parameter type.

Parameters

arg (Any) – The argument which needs to be checked.

Returns

A Fields instance created by the input argument.

Return type

graviti.portex.field.Fields

static load(content, imports=None)[source]#

Create Portex field list instance from python list.

Parameters
Returns

A Portex field list instance created from the input python list.

Return type

graviti.portex.field.Fields

static dump(arg)[source]#

Dump the input Portex field list instance to a python list.

Parameters

arg (graviti.portex.field.Fields) – A Portex field list instance.

Returns

A Python list representation of the Portex field list.

Return type

List[Any]

class graviti.portex.ptype.PortexType[source]#

Bases: ParameterType

Parameter type for Portex type.

static check(arg)[source]#

Check the parameter type.

Parameters

arg (Any) – The argument which needs to be checked.

Returns

The input argument unchanged.

Raises

TypeError – When the input argument is not a Portex type.

Return type

graviti.portex.base.PortexType

static load(content, imports=None)[source]#

Create Portex type instance from python dict.

Parameters
Returns

A Portex type instance created from the input python dict.

Return type

graviti.portex.base.PortexType

static dump(arg)[source]#

Dump the instance to a python dict.

Parameters

arg (graviti.portex.base.PortexType) – A Portex type instance.

Returns

A python dict representation of the Portex type.

Return type

Dict[str, Any]