Updated parsing/yaml/objects.py with 2/3 compatibility.

pull/10754/head
Rory Finnegan 10 years ago
parent 3075a4db25
commit 7e9292c755

@ -19,14 +19,17 @@
from __future__ import (absolute_import, division, print_function) from __future__ import (absolute_import, division, print_function)
__metaclass__ = type __metaclass__ = type
class AnsibleBaseYAMLObject: from six import text_type
class AnsibleBaseYAMLObject(object):
''' '''
the base class used to sub-class python built-in objects the base class used to sub-class python built-in objects
so that we can add attributes to them during yaml parsing so that we can add attributes to them during yaml parsing
''' '''
_data_source = None _data_source = None
_line_number = 0 _line_number = 0
_column_number = 0 _column_number = 0
def _get_ansible_position(self): def _get_ansible_position(self):
@ -36,21 +39,27 @@ class AnsibleBaseYAMLObject:
try: try:
(src, line, col) = obj (src, line, col) = obj
except (TypeError, ValueError): except (TypeError, ValueError):
raise AssertionError('ansible_pos can only be set with a tuple/list of three values: source, line number, column number') raise AssertionError(
self._data_source = src 'ansible_pos can only be set with a tuple/list '
self._line_number = line 'of three values: source, line number, column number'
)
self._data_source = src
self._line_number = line
self._column_number = col self._column_number = col
ansible_pos = property(_get_ansible_position, _set_ansible_position) ansible_pos = property(_get_ansible_position, _set_ansible_position)
class AnsibleMapping(AnsibleBaseYAMLObject, dict): class AnsibleMapping(AnsibleBaseYAMLObject, dict):
''' sub class for dictionaries ''' ''' sub class for dictionaries '''
pass pass
class AnsibleUnicode(AnsibleBaseYAMLObject, unicode):
class AnsibleUnicode(AnsibleBaseYAMLObject, text_type):
''' sub class for unicode objects ''' ''' sub class for unicode objects '''
pass pass
class AnsibleSequence(AnsibleBaseYAMLObject, list): class AnsibleSequence(AnsibleBaseYAMLObject, list):
''' sub class for lists ''' ''' sub class for lists '''
pass pass

Loading…
Cancel
Save