schrodinger.application.matsci.yamlutils module¶
Utilities for working with yaml
Copyright Schrodinger, LLC. All rights reserved.
- schrodinger.application.matsci.yamlutils.yaml_tuple_constructor(obj, node)¶
Add the ability to parse tuples to a YAML Constructor object
Note - this function is for ruamel yaml with Python 3.11 and beyond
- Parameters
obj (yaml.SafeConstructor) – The constructor object
node (yaml.nodes.SequenceNode) – The tuple node
- Return type
tuple
- Returns
The tuple derived from node
- schrodinger.application.matsci.yamlutils.yaml_tuple_representer(obj, data)¶
Add the ability to write tuples to a YAML Representer object
Note - this function is for ruamel yaml with Python 3.11 and beyond
- Parameters
obj (yaml.Representer) – The constructor object
data – The tuple to represent
- Return type
str
- Returns
A YAML representation of a tuple
- schrodinger.application.matsci.yamlutils.get_safe_yaml_with_tuples()¶
Get a safe YAML loader that can handle tuples
- Return type
yaml.YAML
- Returns
A safe yaml loader that can handle tuples
- class schrodinger.application.matsci.yamlutils.TupleSafeLoader(*args, **kwargs)¶
Bases:
ruamel.yaml.loader.SafeLoader
Yaml Loader that recognizes tuple tags.
Note - this class is for ruamel yaml with Python < 3.11
- __init__(*args, **kwargs)¶
Initialize the scanner.
- DEFAULT_MAPPING_TAG = 'tag:yaml.org,2002:map'¶
- DEFAULT_SCALAR_TAG = 'tag:yaml.org,2002:str'¶
- DEFAULT_SEQUENCE_TAG = 'tag:yaml.org,2002:seq'¶
- DEFAULT_TAGS = {'!': '!', '!!': 'tag:yaml.org,2002:'}¶
- ESCAPE_CODES = {'U': 8, 'u': 4, 'x': 2}¶
- ESCAPE_REPLACEMENTS = {'\t': '\t', ' ': ' ', '"': '"', '/': '/', '0': '\x00', 'L': '\u2028', 'N': '\x85', 'P': '\u2029', '\\': '\\', '_': '\xa0', 'a': '\x07', 'b': '\x08', 'e': '\x1b', 'f': '\x0c', 'n': '\n', 'r': '\r', 't': '\t', 'v': '\x0b'}¶
- NON_PRINTABLE = <ruamel.yaml.util.LazyEval object>¶
- classmethod add_constructor(tag: Any, constructor: Any) None ¶
- classmethod add_implicit_resolver(tag: Any, regexp: Any, first: Any) None ¶
- classmethod add_implicit_resolver_base(tag: Any, regexp: Any, first: Any) None ¶
- add_indent(column: int) bool ¶
- classmethod add_multi_constructor(tag_prefix: Any, multi_constructor: Any) None ¶
- classmethod add_path_resolver(tag: Any, path: Any, kind: Any = None) None ¶
- add_version_implicit_resolver(version: VersionType, tag: Any, regexp: Any, first: Any) None ¶
- ascend_resolver() None ¶
- bool_values = {'false': False, 'n': False, 'no': False, 'off': False, 'on': True, 'true': True, 'y': True, 'yes': True}¶
- check_block_entry() Any ¶
- check_data() Any ¶
- check_directive() Any ¶
- check_document_end() Any ¶
- check_document_start() Any ¶
- check_end_doc_comment(end_event: Any, node: Any) None ¶
- check_event(*choices: Any) bool ¶
- check_key() Any ¶
- check_mapping_key(node: Any, key_node: Any, mapping: Any, key: Any, value: Any) bool ¶
return True if key is unique
- check_node() Any ¶
- check_plain() Any ¶
- check_printable(data: Any) None ¶
- check_resolver_prefix(depth: int, path: Text, kind: Any, current_node: Any, current_index: Any) bool ¶
- check_set_key(node: Any, key_node: Any, setting: Any, key: Any) None ¶
- check_token(*choices: Any) bool ¶
- check_value() Any ¶
- compose_document() Any ¶
- compose_mapping_node(anchor: Any) Any ¶
- compose_node(parent: Any, index: Any) Any ¶
- compose_scalar_node(anchor: Any) Any ¶
- compose_sequence_node(anchor: Any) Any ¶
- property composer¶
- construct_document(node: Any) Any ¶
- construct_mapping(node: Any, deep: bool = False) Any ¶
deep is True when creating an object/mapping recursively, in that case want the underlying elements available during construction
- construct_non_recursive_object(node: Any, tag: Optional[str] = None) Any ¶
- construct_object(node: Any, deep: bool = False) Any ¶
deep is True when creating an object/mapping recursively, in that case want the underlying elements available during construction
- construct_pairs(node: Any, deep: bool = False) Any ¶
- construct_scalar(node: Any) Any ¶
- construct_sequence(node: Any, deep: bool = False) Any ¶
deep is True when creating an object/mapping recursively, in that case want the underlying elements available during construction
- construct_undefined(node: Any) None ¶
- construct_yaml_binary(node: Any) Any ¶
- construct_yaml_bool(node: Any) bool ¶
- construct_yaml_float(node: Any) float ¶
- construct_yaml_int(node: Any) int ¶
- construct_yaml_map(node: Any) Any ¶
- construct_yaml_null(node: Any) Any ¶
- construct_yaml_object(node: Any, cls: Any) Any ¶
- construct_yaml_omap(node: Any) Any ¶
- construct_yaml_pairs(node: Any) Any ¶
- construct_yaml_seq(node: Any) Any ¶
- construct_yaml_set(node: Any) Any ¶
- construct_yaml_str(node: Any) Any ¶
- construct_yaml_timestamp(node: Any, values: Any = None) Any ¶
- descend_resolver(current_node: Any, current_index: Any) None ¶
- determine_encoding() None ¶
- dispose() None ¶
- fetch_alias() None ¶
- fetch_anchor() None ¶
- fetch_block_entry() None ¶
- fetch_block_scalar(style: Any) None ¶
- fetch_comment(comment: Any) None ¶
- fetch_directive() None ¶
- fetch_document_end() None ¶
- fetch_document_indicator(TokenClass: Any) None ¶
- fetch_document_start() None ¶
- fetch_double() None ¶
- fetch_flow_collection_end(TokenClass: Any) None ¶
- fetch_flow_collection_start(TokenClass: Any, to_push: Text) None ¶
- fetch_flow_entry() None ¶
- fetch_flow_mapping_end() None ¶
- fetch_flow_mapping_start() None ¶
- fetch_flow_scalar(style: Any) None ¶
- fetch_flow_sequence_end() None ¶
- fetch_flow_sequence_start() None ¶
- fetch_folded() None ¶
- fetch_key() None ¶
- fetch_literal() None ¶
- fetch_more_tokens() Any ¶
- fetch_plain() None ¶
- fetch_single() None ¶
- fetch_stream_end() None ¶
- fetch_stream_start() None ¶
- fetch_tag() None ¶
- fetch_value() None ¶
- flatten_mapping(node: Any) Any ¶
This implements the merge key feature http://yaml.org/type/merge.html by inserting keys from the merge dict/list of dicts if not yet available in this node
- property flow_level¶
- forward(length: int = 1) None ¶
- forward_1_1(length: int = 1) None ¶
- get_data() Any ¶
- get_event() Any ¶
- get_loader_version(version: Optional[VersionType]) Any ¶
- get_mark() Any ¶
- get_node() Any ¶
- get_single_data() Any ¶
- get_single_node() Any ¶
- get_token() Any ¶
- inf_value = inf¶
- nan_value = nan¶
- need_more_tokens() bool ¶
- next_possible_simple_key() Any ¶
- parse_block_mapping_first_key() Any ¶
- parse_block_mapping_key() Any ¶
- parse_block_mapping_value() Any ¶
- parse_block_node() Any ¶
- parse_block_node_or_indentless_sequence() Any ¶
- parse_block_sequence_entry() Any ¶
- parse_block_sequence_first_entry() Any ¶
- parse_document_content() Any ¶
- parse_document_end() Any ¶
- parse_document_start() Any ¶
- parse_flow_mapping_empty_value() Any ¶
- parse_flow_mapping_first_key() Any ¶
- parse_flow_mapping_key(first: Any = False) Any ¶
- parse_flow_mapping_value() Any ¶
- parse_flow_node() Any ¶
- parse_flow_sequence_entry(first: bool = False) Any ¶
- parse_flow_sequence_entry_mapping_end() Any ¶
- parse_flow_sequence_entry_mapping_key() Any ¶
- parse_flow_sequence_entry_mapping_value() Any ¶
- parse_flow_sequence_first_entry() Any ¶
- parse_implicit_document_start() Any ¶
- parse_indentless_sequence_entry() Any ¶
- parse_node(block: bool = False, indentless_sequence: bool = False) Any ¶
- parse_stream_start() Any ¶
- property parser¶
- peek(index: int = 0) Text ¶
- peek_event() Any ¶
- peek_token() Any ¶
- prefix(length: int = 1) Any ¶
- process_directives() Any ¶
- process_empty_scalar(mark: Any, comment: Any = None) Any ¶
- property processing_version¶
- property reader¶
- remove_possible_simple_key() None ¶
- reset_parser() None ¶
- reset_reader() None ¶
- reset_scanner() None ¶
- resolve(kind: Any, value: Any, implicit: Any) Any ¶
- property resolver¶
- save_possible_simple_key() None ¶
- scan_anchor(TokenClass: Any) Any ¶
- scan_block_scalar(style: Any, rt: Optional[bool] = False) Any ¶
- scan_block_scalar_breaks(indent: int) Any ¶
- scan_block_scalar_ignored_line(start_mark: Any) Any ¶
- scan_block_scalar_indentation() Any ¶
- scan_block_scalar_indicators(start_mark: Any) Any ¶
- scan_directive() Any ¶
- scan_directive_ignored_line(start_mark: Any) None ¶
- scan_directive_name(start_mark: Any) Any ¶
- scan_flow_scalar(style: Any) Any ¶
- scan_flow_scalar_breaks(double: Any, start_mark: Any) Any ¶
- scan_flow_scalar_non_spaces(double: Any, start_mark: Any) Any ¶
- scan_flow_scalar_spaces(double: Any, start_mark: Any) Any ¶
- scan_line_break() Any ¶
- scan_plain() Any ¶
- scan_plain_spaces(indent: Any, start_mark: Any) Any ¶
- scan_tag() Any ¶
- scan_tag_directive_handle(start_mark: Any) Any ¶
- scan_tag_directive_prefix(start_mark: Any) Any ¶
- scan_tag_directive_value(start_mark: Any) Any ¶
- scan_tag_handle(name: Any, start_mark: Any) Any ¶
- scan_tag_uri(name: Any, start_mark: Any) Any ¶
- scan_to_next_token() Any ¶
- scan_uri_escapes(name: Any, start_mark: Any) Any ¶
- scan_yaml_directive_number(start_mark: Any) Any ¶
- scan_yaml_directive_value(start_mark: Any) Any ¶
- property scanner¶
- property scanner_processing_version¶
- stale_possible_simple_keys() None ¶
- property stream¶
- timestamp_regexp = <ruamel.yaml.util.LazyEval object>¶
- transform_tag(handle: Any, suffix: Any) Any ¶
- unwind_indent(column: Any) None ¶
- update(length: int) None ¶
- update_raw(size: Optional[int] = None) None ¶
- property versioned_resolver¶
select the resolver based on the version we are parsing
- yaml_constructors: Dict[Any, Any] = {'tag:yaml.org,2002:null': <function SafeConstructor.construct_yaml_null>, 'tag:yaml.org,2002:bool': <function SafeConstructor.construct_yaml_bool>, 'tag:yaml.org,2002:int': <function SafeConstructor.construct_yaml_int>, 'tag:yaml.org,2002:float': <function SafeConstructor.construct_yaml_float>, 'tag:yaml.org,2002:binary': <function SafeConstructor.construct_yaml_binary>, 'tag:yaml.org,2002:timestamp': <function SafeConstructor.construct_yaml_timestamp>, 'tag:yaml.org,2002:omap': <function SafeConstructor.construct_yaml_omap>, 'tag:yaml.org,2002:pairs': <function SafeConstructor.construct_yaml_pairs>, 'tag:yaml.org,2002:set': <function SafeConstructor.construct_yaml_set>, 'tag:yaml.org,2002:str': <function SafeConstructor.construct_yaml_str>, 'tag:yaml.org,2002:seq': <function SafeConstructor.construct_yaml_seq>, 'tag:yaml.org,2002:map': <function SafeConstructor.construct_yaml_map>, None: <function SafeConstructor.construct_undefined>}¶
- yaml_implicit_resolvers: Dict[Any, Any] = {}¶
- yaml_multi_constructors: Dict[Any, Any] = {}¶
- yaml_path_resolvers: Dict[Any, Any] = {}¶
- schrodinger.application.matsci.yamlutils.read_safe_yaml_file(path)¶
Read a yaml file safely and properly interpret tuples
- Parameters
path (str) – The path to the yaml file
- Returns
The data from the yaml file
- schrodinger.application.matsci.yamlutils.dump_yaml_file(path, data)¶
Write a yaml file safely and properly interpret tuples
- Parameters
path (str) – The path to the yaml file
data – The data to write out
- Returns
The data from the yaml file