Coverage for lib/ansible/parsing/yaml/objects.py : 53%

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> # # This file is part of Ansible # # Ansible is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # Ansible is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see <http://www.gnu.org/licenses/>.
# Make coding more python3-ish
''' the base class used to sub-class python built-in objects so that we can add attributes to them during yaml parsing
'''
except (TypeError, ValueError): raise AssertionError( 'ansible_pos can only be set with a tuple/list ' 'of three values: source, line number, column number' )
''' sub class for dictionaries '''
''' sub class for unicode objects '''
''' sub class for lists '''
# Unicode like object that is not evaluated (decrypted) until it needs to be # TODO: is there a reason these objects are subclasses for YAMLObject?
def from_plaintext(cls, seq, vault, secret): if not vault: raise vault.AnsibleVaultError('Error creating AnsibleVaultEncryptedUnicode, invalid vault (%s) provided' % vault)
ciphertext = vault.encrypt(seq, secret) avu = cls(ciphertext) avu.vault = vault return avu
'''A AnsibleUnicode with a Vault attribute that can decrypt it.
ciphertext is a byte string (str on PY2, bytestring on PY3).
The .data attribute is a property that returns the decrypted plaintext of the ciphertext as a PY2 unicode or PY3 string object. ''' super(AnsibleVaultEncryptedUnicode, self).__init__()
# after construction, calling code has to set the .vault attribute to a vaultlib object self.vault = None self._ciphertext = to_bytes(ciphertext)
def data(self): if not self.vault: # FIXME: raise exception? return self._ciphertext return self.vault.decrypt(self._ciphertext).decode()
def data(self, value): self._ciphertext = value
return repr(self.data)
# Compare a regular str/text_type with the decrypted hypertext if self.vault: return other == self.data return False
return id(self)
if self.vault: return other != self.data return True
return str(self.data)
return to_text(self.data, errors='surrogate_or_strict')
return self.data.encode(encoding, errors) |