def is_printable(text, printables=""): """ Check if a string is printable """ if six.PY3 and isinstance(text, six.string_types): text = six.b(text) return set(text) - set(six.b(string.printable) + six.b(printables)) == set()
def _to_binary_string_py3(text): """ Converts a string to a binary string if it is not already one. Returns a str in Python 2 and a bytes in Python3. Do not use directly, use to_binary_string instead. """ if isinstance(text, six.binary_type): return text elif isinstance(text, six.string_types): return six.b(text) else: raise Exception('only takes string types')
def _make_values_bytes(dict_): """Make shellcode in dictionaries bytes""" return {k: six.b(v) for k, v in dict_.items()}