def hex_escape_str(original_str):
    """
    Function to make sure we can generate proper string reports.
    If character is not printable, call repr for that character.
    Finally join the result.
    :param original_str: Original fail reason as string.
    :return: string
    """
    new = []
    for char in original_str:
        if str(char) in string.printable:
            new.append(str(char))
            continue

        if IS_PYTHON3:
            new.append(str(char).encode("unicode_escape").decode("ascii"))
        else:
            new.append(repr(char).replace("'", ""))
    return "".join(new)
def hex_escape_str ( original_str ) : new = [ ] for char in original_str : if str ( char ) in string . printable : new . append ( str ( char ) ) continue if IS_PYTHON3 : new . append ( str ( char ) . encode ( "unicode_escape" ) . decode ( "ascii" ) ) else : new . append ( repr ( char ) . replace ( "'" , "" ) ) return "" . join ( new )
Function to make sure we can generate proper string reports.
    If character is not printable, call repr for that character.
    Finally join the result.
    :param original_str: Original fail reason as string.
    :return: string