code: def string_escape(string, delimiter='"'):
      
      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
docs: 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:
      >>> string_escape("a line\t")
      "a line\\t"
      >>> string_escape(u"some fancy character: \\u9999")
      u"\\u9999"
      >>> string_escape(5)
      None