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 wrong: Incorrect. read_multi does not exist in PyYAML.
- B
yaml.load_all()
Why wrong: 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()
Correct. yaml.safe_load_all() safely parses a multi-document YAML stream into an iterator of Python objects.
- D
yaml.parse_documents()
Why wrong: Incorrect. parse_documents is not a standard function in the PyYAML library.