An automation script reads a multi-document YAML file containing configuration templates for various Junos router models. To process each document individually in Python using PyYAML, which function should the engineer invoke?
Trap 1: yaml.read_multi()
Incorrect. read_multi does not exist in PyYAML.
Trap 2: yaml.load_all()
Incorrect. yaml.load_all() without 'safe_' uses the full loader, which can be vulnerable to arbitrary code execution if parsing untrusted data.
Trap 3: yaml.parse_documents()
Incorrect. parse_documents is not a standard function in the PyYAML library.
- A
yaml.read_multi()
Why it fails: Incorrect. read_multi does not exist in PyYAML.
- B
yaml.load_all()
Why it fails: Incorrect. yaml.load_all() without 'safe_' uses the full loader, which can be vulnerable to arbitrary code execution if parsing untrusted data.
- C
yaml.safe_load_all()
`yaml.safe_load_all()` returns a generator yielding each document in a multi-document YAML stream separately, satisfying the requirement to process templates individually. Unlike `safe_load()`, which raises a composer error on multiple documents, it handles the `---` separators natively and safely constructs standard Python objects without arbitrary code execution.
- D
yaml.parse_documents()
Why it fails: Incorrect. parse_documents is not a standard function in the PyYAML library.