Syntax Objects

This module defines the base objects that allow to use the legacy syntax of code_aster commands.

Note

  • If a keyword (simple or factor) is not provided by the user, its value is None.

  • If a factor keyword is present by default (statut='d') but not filled by the user, its value is {} if max=1 or [] if max > 1.

  • Only one level of factor keywords is supported.

The keyword reuse is (will be) deprecated. So it must be present in catalogs to import command files that contain it. But it is always optional (see checkMandatory) because it is removed during import.

class code_aster.Cata.Language.SyntaxObjects.SyntaxId[source]

Bases: object

Container of the id of syntax objects.

This list of type identifiers can be extended but never change between two releases of code_aster.

class code_aster.Cata.Language.SyntaxObjects.ConversionLevel[source]

Bases: object

Enumerator for the level of conversion requirements.

NoFail

Do not fail, not strict.

Naming

Requires that all command results are explicitly named.

Type

Requires a valid type definition.

Keyword

Requires that all keywords are valid.

Syntaxic

Requires a valid syntax of all the commands.

Restore

Requires a conversion without error during restore.

Any

All conversion must pass.

Partial

Allows to make a partial conversion (to be used with another level).

NoGraphical

Force to load all stages in text mode.

class code_aster.Cata.Language.SyntaxObjects.CataDefinition[source]

Bases: OrderedDict

Dictionary to store the definition of syntax objects. Iteration over the elements is ordered by type: SimpleKeyword, FactorKeyword and Bloc.

property entities

Return the all entities.

Returns:

dict of all entities (keywords and conditional blocks) of the object.

Return type:

dict

property keywords

Return the simple and factor keywords contained in the object.

The keywords are sorted in the order of definition in the catalog. This is a workaround waiting for Python 3.6 and integration of PEP-0468.

Returns:

dict of all simple and factor keywords of the object.

Return type:

dict

property factor_keywords

Return the factor keywords contained in the object.

Returns:

dict of all factor keywords of the object.

Return type:

dict

property simple_keywords

Return the simple keywords contained in the object.

Returns:

dict of all simple keywords of the object.

Return type:

dict

_filter_entities(typeslist, with_block=True)[source]

Filter entities by type recursively.

Returns:

dict of entities of the requested types.

Return type:

dict

iterItemsByType()[source]

Iterator over dictionary’s pairs with respecting order: SimpleKeyword, FactorKeyword and Bloc objects

class code_aster.Cata.Language.SyntaxObjects.UIDMixing[source]

Bases: object

Sub class for UID based classes.

Parameters:

uid (int) – Object’s id.

__init__()[source]
property uid

Attribute that holds unique id

class code_aster.Cata.Language.SyntaxObjects.PartOfSyntax(curDict)[source]

Bases: UIDMixing

Generic object that describe a piece of syntax.

__init__(curDict)[source]

Initialization

getCataTypeId()[source]

Get the Cata type of object. Should be sub-classed.

Returns:

type id of Cata object: -1 if not defined.

Return type:

int

property name

Name of the object.

Type:

str

property udocstring

Documentation of the object.

Type:

unicode

property docstring

Documentation of the object.

Type:

str

property definition

Attribute containing the syntax definition

Type:

dict

property rules

Attribute containing the list of rules

Type:

dict

property regles

Attribute containing the list of rules

Type:

dict

__repr__()[source]

Simple representation

property entities

Return the all entities contained in the object.

Returns:

dict of all entities (keywords and conditional blocks) of the object.

Return type:

dict

property entites

Return the all entities contained in the object.

Returns:

dict of all entities (keywords and conditional blocks) of the object.

Return type:

dict

property keywords

Return the simple and factor keywords contained in the object.

Returns:

dict of all simple and factor keywords of the object.

Return type:

dict

accept(visitor, syntax=None)[source]

Called by a Visitor

_def_status()[source]

Wrapper that returns the value of ‘statut’ after precondition.

isMandatory()[source]

Tell if this keyword is mandatory

isOptional()[source]

Tell if this keyword is optional

isHidden()[source]

Tell if this keyword should be hidden

hasDefaultValue()[source]

Tell if the keyword has a default value

addDefaultKeywords(userSyntax, _parent_ctxt=None)[source]

Add default keywords into the user dict of keywords.

Optional keywords that are not defined are set to None/undefined value.

The values given in argument (userSyntax) preempt on the definition ones.

Parameters:
  • userSyntax (dict) – dict of the keywords as filled by the user, changed in place.

  • _parent_ctxt (dict) – contains the keywords as known in the parent. This context is used to evaluate block conditions.

checkMandatory(userSyntax, stack, _parent_ctxt=None)[source]

Check that the mandatory keywords are provided by the user.

Warning: Default keywords must be added before visiting the objects. Warning: this does not check recursively, only the current level.

Parameters:
  • userSyntax (dict) – dict of the user and default keywords.

  • stack (list) – used to give contextual informations in error messages.

  • _parent_ctxt (dict) – contains the keywords as known in the parent. This context is used to evaluate block conditions.

getKeyword(userKeyword, userSyntax, _parent_ctxt=None)[source]

Return the keyword in the current composite object.

Warning: Default keywords must be added before visiting the objects.

Parameters:
  • userKeyword (str) – name of the searched keyword.

  • userSyntax (dict) – dict of the user and default keywords.

  • _parent_ctxt (dict) – contains the keywords as known in the parent. This context is used to evaluate block conditions.

getRules(userSyntax, _parent_ctxt=None)[source]

Return the rules to be applied to the given keywords.

Warning: Default keywords must be added before visiting the objects.

Parameters:
  • userSyntax (dict) – dict of the user and default keywords.

  • _parent_ctxt (dict) – contains the keywords as known in the parent. This context is used to evaluate block conditions.

classmethod undefined(value)[source]

Return True if the value is a null value (undefined keyword), False otherwise.

is_list()[source]

Tell if the value should be stored as list.

class code_aster.Cata.Language.SyntaxObjects.SimpleKeyword(curDict)[source]

Bases: PartOfSyntax

Objet mot-clé simple équivalent à SIMP dans les capy

__init__(curDict)[source]

Initialization

getCataTypeId()[source]

Get the type id of SimpleKeyword.

Returns:

type id of SimpleKeyword.

Return type:

int

accept(visitor, syntax=None)[source]

Called by a Visitor

_context(value)[source]

Print contextual informations

hasDefaultValue()[source]

Tell if the keyword has a default value

defaultValue(default=None)[source]

Return the default value or default.

addDefaultKeywords(key, userSyntax, _parent_ctxt)[source]

Add the default value if not provided by the user dict.

Parameters:
  • userSyntax (dict) – dict of the keywords as filled by the user, changed in place.

  • _parent_ctxt (dict) – contains the keywords as known in the parent.

class code_aster.Cata.Language.SyntaxObjects.FactorKeyword(curDict)[source]

Bases: PartOfSyntax

Objet mot-clé facteur equivalent de FACT dans les capy

getCataTypeId()[source]

Get the type id of FactorKeyword.

Returns:

type id of FactorKeyword.

Return type:

int

accept(visitor, syntax=None)[source]

Called by a Visitor

defaultValue()[source]

Return the default for this factor keyword. If the keyword is present by default, its default value is {} if max=1 or [] if max > 1. If the keyword does not exist by default, its default value is None.

class code_aster.Cata.Language.SyntaxObjects.Bloc(curDict)[source]

Bases: PartOfSyntax

Objet Bloc équivalent à BLOC dans les capy

getCataTypeId()[source]

Get the type id of Bloc.

Returns:

type id of Bloc.

Return type:

int

accept(visitor, syntax=None)[source]

Called by a Visitor

getCondition()[source]

Return the BLOC condition

isEnabled(context)[source]

Tell if the block is enabled by the given context

class code_aster.Cata.Language.SyntaxObjects.Command(curDict)[source]

Bases: PartOfSyntax

Object Command qui représente toute la syntaxe d’une commande

get_compat_syntax()[source]

Return the compat_syntax keywords converter.

classmethod register_call_callback(callback)[source]

Register callback to be called in place of the default method.

Register None to revert to default.

Parameters:

callback (callable) – Function to call with signature: (Command instance, **kwargs).

getCataTypeId()[source]

Get the type id of Command.

Returns:

type id of Command.

Return type:

int

can_reuse()[source]

Tell if the result can be a reused one.

accept(visitor, syntax=None)[source]

Called by a Visitor

call_default(**args)[source]

Execute the command, only based on the command description.

Keyword Arguments:

__strict__ (bool) – If True, the syntax of the command must be valid. Otherwise the generic DataStructure type is returned.

__call__(**args)[source]

Simulate the command execution.

get_type_sd_prod(**ctxt)[source]

Return the type of the command result.

build_sd_prod(sdprodFunc, ctxt)[source]

Call the sd_prod function

get_all_types()[source]

Return the list of all possible types that the command can return.

Returns:

List of possible types or a list of list if there are additional results for macro-commands.

Return type:

list[.DataStructure.DataStructure] or list[list[.DataStructure.DataStructure]]

class code_aster.Cata.Language.SyntaxObjects.Operator(curDict)[source]

Bases: Command

class code_aster.Cata.Language.SyntaxObjects.Macro(curDict)[source]

Bases: Command

Specialization of the Command object for MACRO

build_sd_prod(sdprodFunc, ctxt)[source]

Call the sd_prod function

type_sdprod(result, astype)[source]

Define the type of the result.

accept(visitor, syntax=None)[source]

Called by a Visitor

class code_aster.Cata.Language.SyntaxObjects.Procedure(curDict)[source]

Bases: Command

class code_aster.Cata.Language.SyntaxObjects.Formule(curDict)[source]

Bases: Macro

exception code_aster.Cata.Language.SyntaxObjects.CataError[source]

Bases: Exception

Exception raised in case of error in the catalog.