Syntax Utilities¶
List of utilities for syntax objects.
- class code_aster.Cata.Language.SyntaxUtils._F[source]¶
Bases:
dictWrapper to add transitional methods to emulate old MCCOMPO objects
- class code_aster.Cata.Language.SyntaxUtils._ListFact(iterable=(), /)[source]¶
Bases:
listFor backward compatibility to add List_F method to a list of FactorKeywords.
- code_aster.Cata.Language.SyntaxUtils.ListFact(fact)[source]¶
Add List_F method to list of FactorKeywords.
It only avoids to remove all List_F calls that are now useless.
- code_aster.Cata.Language.SyntaxUtils.warn_to_stdout(message, category, filename, lineno, file=None, line=None)[source]¶
Same as showwarning but on stdout
- code_aster.Cata.Language.SyntaxUtils.deprecate(feature, case=1, help=None, level=6)[source]¶
Deprecate a feature, emit a deprecation warning depending on the case.
- Parameters:
feature (str) – Deprecated feature.
case (int) – Case 1: the feature still works but it will be removed. Case 2: the feature does nothing, it has been removed. Case 3: the feature still works but has a new implementation. Case 4: the feature does nothing but has a new implementation.
help (str) – Additional help message, should be present for case 3.
level (int) – Level of the caller in the stack.
- code_aster.Cata.Language.SyntaxUtils.mixedcopy(obj)[source]¶
Make a mixed copy (copy of all dicts, lists and tuples, no copy for all others).
- code_aster.Cata.Language.SyntaxUtils.is_undefined(value)[source]¶
Return True if the value is a null value (undefined keyword), False otherwise.
- code_aster.Cata.Language.SyntaxUtils.remove_none(obj)[source]¶
Remove undefined values from dict in place, do not change other values. Undefined values are None, empty list or empty tuple (consistent with :py:func:PartOfSyntax.undefined).
- Parameters:
obj (list|tuple|dict) – Set of user’s keywords.
- code_aster.Cata.Language.SyntaxUtils.add_none_sdprod(sd_prod, dictargs)[source]¶
Check if some arguments are missing to call sd_prod function and add them with the None value.
It could be considered as a catalog error. sd_prod function should not take optional keywords as arguments.
- Parameters:
sd_prod (callable) – sd_prod function to inspect.
dictargs (dict) – Dict of keywords, changed in place.
- code_aster.Cata.Language.SyntaxUtils.search_for(obj, predicate)[source]¶
Return all values that verify the predicate function.
- code_aster.Cata.Language.SyntaxUtils.force_list(values)[source]¶
Ensure values is iterable (list, tuple, array…) and return it as a list.
- code_aster.Cata.Language.SyntaxUtils.force_tuple(values)[source]¶
Ensure values is iterable (list, tuple, array…) and return it as a tuple.
- code_aster.Cata.Language.SyntaxUtils.value_is_sequence(value)[source]¶
Tell if value is a valid object if max > 1.
- code_aster.Cata.Language.SyntaxUtils.array_to_list(obj)[source]¶
Convert an object to a list if possible (using tolist()) or keep it unchanged otherwise.
- Parameters:
obj (misc) – Object to convert.
- Returns:
Object unchanged or a list.
- Return type:
misc
- code_aster.Cata.Language.SyntaxUtils.convert_complex(value)[source]¶
Force conversion from real to complex numbers.
- Parameters:
value (float|complex|tuple) – Real, complex, old-complex or list of these types.
- Returns:
Complex of list of complex.
- Return type:
complex|list[complex]
- code_aster.Cata.Language.SyntaxUtils.enable_0key(values)[source]¶
Emulate the legacy MCFACT behavior: MCFACT[0] returns MCFACT itself to simulate a list of length 1.
Note: disable_0key() must be called after to restore the original content of values.
- Parameters:
dict – Dict of keywords changed in place.
- code_aster.Cata.Language.SyntaxUtils.disable_0key(values)[source]¶
Restore the content of values after calling enable_0key().
- Parameters:
dict – Dict of keywords changed in place.
- code_aster.Cata.Language.SyntaxUtils.block_utils(evaluation_context)[source]¶
Define some helper functions to write block conditions.
- Parameters:
evaluation_context (dict) – The context containing the keywords.
- code_aster.Cata.Language.SyntaxUtils.sorted_dict(kwargs)[source]¶
Sort a dict in the order of the items.
- code_aster.Cata.Language.SyntaxUtils.debug_mode()[source]¶
Check if application is running in DEBUG mode.
- Returns:
0 if DEBUG mode is switched OFF; 1 or more otherwise.
- Return type:
int
- code_aster.Cata.Language.SyntaxUtils.debug_message(*args, **kwargs)[source]¶
Print debug message.
While this function is mainly dedicated for printing textual message, you may pass any printable object(s) as parameter.
Example
>>> from asterstudy.common.utilities import debug_message, debug_mode >>> previous = debug_mode() >>> debug_mode.DEBUG = 1 >>> debug_message("Start operation:", "Compute", "[args]", 100) AsterStudy: Start operation: Compute [args] 100 >>> debug_message("Operation finished:", "Compute") AsterStudy: Operation finished: Compute >>> debug_mode.DEBUG = previous
Note
Message is only printed if application is running in debug mode. See debug_mode().
- Parameters:
*args – Variable length argument list.