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