code: def escape_path(path):
      
      # There's no knowing what character encoding was used to create URLs
      # containing %-escapes, but since we have to pick one to escape invalid
      # path characters, we pick UTF-8, as recommended in the HTML 4.0
      # specification:
      # http://www.w3.org/TR/REC-html40/appendix/notes.html#h-B.2.1
      # And here, kind of: draft-fielding-uri-rfc2396bis-03
      # (And in draft IRI specification: draft-duerst-iri-05)
      # (And here, for new URI schemes: RFC 2718)
      path = quote(path, HTTP_PATH_SAFE)
      path = ESCAPED_CHAR_RE.sub(uppercase_escaped_char, path)
      return path
docs: Escape any invalid characters in HTTP URL, and uppercase all escapes.