Python yaml.add_multi_constructor() Examples
The following are 3
code examples of yaml.add_multi_constructor().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
yaml
, or try the search function
.
Example #1
Source File: yaml_parse.py From TextDetector with GNU General Public License v3.0 | 7 votes |
def initialize(): """ Initialize the configuration system by installing YAML handlers. Automatically done on first call to load() specified in this file. """ global is_initialized # Add the custom multi-constructor yaml.add_multi_constructor('!obj:', multi_constructor_obj) yaml.add_multi_constructor('!pkl:', multi_constructor_pkl) yaml.add_multi_constructor('!import:', multi_constructor_import) yaml.add_constructor('!import', constructor_import) yaml.add_constructor("!float", constructor_float) pattern = re.compile(SCIENTIFIC_NOTATION_REGEXP) yaml.add_implicit_resolver('!float', pattern) is_initialized = True ############################################################################### # Callbacks used by PyYAML
Example #2
Source File: file_loader.py From cfn-sphere with Apache License 2.0 | 5 votes |
def get_yaml_or_json_file(cls, url, working_dir): """ Load yaml or json from filesystem or s3 :param url: str :param working_dir: str :return: dict """ file_content = cls.get_file(url, working_dir) try: if url.lower().endswith(".json"): return json.loads(file_content, encoding='utf-8') elif url.lower().endswith(".template"): return json.loads(file_content, encoding='utf-8') elif url.lower().endswith(".yml") or url.lower().endswith(".yaml"): if hasattr(yaml, 'FullLoader'): loader = yaml.FullLoader else: loader = yaml.Loader yaml.add_multi_constructor(u"", cls.handle_yaml_constructors, Loader=loader) return yaml.load(file_content, Loader=loader) else: raise CfnSphereException( "Invalid suffix, use [json|template|yml|yaml]") except Exception as e: raise CfnSphereException(e)
Example #3
Source File: preprocessors.py From zentral with Apache License 2.0 | 5 votes |
def __init__(self): self.clients = {} yaml.add_multi_constructor("!ruby/object:Puppet", default_constructor)