def fmt_text(text):
 PRINTABLE_CHAR = set((list(range(ord(u' '), (ord(u'~') + 1))) + [ord(u'\r'), ord(u'\n')]))
 newtext = ((u'\\x{:02X}'.format(c) if (c not in PRINTABLE_CHAR) else chr(c)) for c in text)
 textlines = u'\r\n'.join((l.strip(u'\r') for l in u''.join(newtext).split(u'\n')))
 return textlines

def fmt_text ( text ) : PRINTABLE_CHAR = set ( ( list ( range ( ord ( u' ' ) , ( ord ( u'~' ) + 1 ) ) ) + [ ord ( u'\r' ) , ord ( u'\n' ) ] ) ) newtext = ( ( u'\\x{:02X}' . format ( c ) if ( c not in PRINTABLE_CHAR ) else chr ( c ) ) for c in text ) textlines = u'\r\n' . join ( ( l . strip ( u'\r' ) for l in u'' . join ( newtext ) . split ( u'\n' ) ) ) return textlines
convert characters that arent printable to hex format .