Coverage for lib/ansible/parsing/utils/yaml.py : 83%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# (c) 2012-2014, Michael DeHaan <michael.dehaan@gmail.com> # Copyright: (c) 2017, Ansible Project # Copyright: (c) 2018, Ansible Project # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Make coding more python3-ish
''' Optionally constructs an object (AnsibleBaseYAMLObject) to encapsulate the file name/position where a YAML exception occurred, and raises an AnsibleParserError to display the syntax exception information. '''
# if the YAML exception contains a problem mark, use it to construct # an object the error class can use to display the faulty line
''' Implements yaml.safe_load(), except using our custom loader class. '''
finally: except AttributeError: pass # older versions of yaml don't have dispose function, ignore
''' Creates a python datastructure from the given data, which can be either a JSON or YAML string. '''
# The PyYAML's libyaml bindings use PyUnicode_CheckExact so # they are unable to cope with our subclass. # Unwrap and re-wrap the unicode so we can keep track of line # numbers # Note: Cannot use to_text() because AnsibleUnicode is a subclass of the text_type. # Should not have to worry about tracebacks because python's text constructors (unicode() on # python2 and str() on python3) can handle a subtype of themselves. in_data = text_type(data) else:
# we first try to load this data as JSON. Fixes issues with extra vars json strings not # being parsed correctly by the yaml parser # must not be JSON, let the rest try
new_data = AnsibleUnicode(new_data) new_data.ansible_pos = data.ansible_pos
|