<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def string_escape(string, delimiter='"'):
 """Turns special characters into escape sequences in the provided string. Supports both byte strings and unicode strings properly. Any other values will produce None. Example: "a line\\t" u"\\u9999" None """

    if isinstance(string, str):
        escaped = string.encode("string-escape")
    elif isinstance(string, str):
        escaped = str(string.encode("unicode-escape"))
    else:
        raise Error("Unexpected string type.")
    return delimiter + escape_quotes(escaped, delimiter) + delimiter