def _convert_to_unicode(data): """ Helper function that makes sure all items in the dictionary are unicode for comparing the existing state with the desired state. This function is only needed for Python 2 and can be removed once we've migrated to Python 3. The data returned by the current settings sometimes has a mix of unicode and string values (these don't matter in Py3). This causes the comparison to say it's not in the correct state even though it is. They basically compares apples to apples, etc. Also, in Python 2, the utf-16 encoded strings remain utf-16 encoded (each character separated by `/x00`) In Python 3 it returns a utf-8 string. This will just remove all the null bytes (`/x00`), again comparing apples to apples. """ if isinstance(data, str): data = data.replace("\x00", "") return salt.utils.stringutils.to_unicode(data) elif isinstance(data, dict): return { _convert_to_unicode(k): _convert_to_unicode(v) for k, v in data.items() } elif isinstance(data, list): return list(_convert_to_unicode(v) for v in data) else: return data
def _translate_newlines(self, data): if data is None or not data: return # PTY's always return \r\n as the line feeds return data.replace("\r\n", os.linesep)