Keyword

class ase2sprkkr.outputs.test.grammar_types.basic.Keyword(*keywords, aliases=None, transform='upper', quote=None, **kwargs)[source]

A value, that can take values from the predefined set of strings.

Class hierarchy

Inheritance diagram of ase2sprkkr.outputs.test.grammar_types.basic.Keyword

Constructor

__init__(*keywords, aliases=None, transform='upper', quote=None, **kwargs)[source]

Create the object.

Parameters:
  • prefix – The string, that will be printed before the value

  • postfix – The string, that will be printed after the value

  • format – The (python) format string, that will be used for outputing the value. The format is passed as format argument to str.format routine.

  • after_format – In some cases, the additional formating is required after converting to the string and adding postfix/prefix.

  • default_value – The default value of the options of this type. None means no default value.

  • condition – Function, that check the validity of the value. It should return True for a valid value, and False or string for invalid. The string is interpreted as an error message that explains the invalidity of the value.

  • after_convert – Function, that - if it is given - is applied to the (entered or parsed) value. The function is applied on the result of the convert method

_validate(value, why='set')[source]

Return error message if the value is not valid.

_string(val)[source]

Convert the value to the ouput.

The string() apply format and do some additional transformation (add prefix, postfix etc.), so the actual way how to convert the value for the output should be here.

grammar_name()[source]

Human readable expression of the grammar. By default, this is what is set by grammar.setName, however, sometimes is desirable to set even shorter string

convert(value)[source]

Convert a value from user to the “cannonical form”

additional_description(prefix='')[source]

If the description of the type does not fit on one line, this method should return

Returns:

The additional description (e.g. possible choices) of the type. Multiline string.

Return type:

additional_description

is_independent_on_the_predecessor = True

Options of most grammar types do not identify themselves, so they have to be either identified by their names, or if name is not given, by their predecessors. Hoewever, e.g. keyword arguments can be identified just by their value.