MCPcopy Index your code
hub / github.com/python/cpython / escape_path

Function escape_path

Lib/http/cookiejar.py:678–690  ·  view source on GitHub ↗

Escape any invalid characters in HTTP URL, and uppercase all escapes.

(path)

Source from the content-addressed store, hash-verified

676def uppercase_escaped_char(match):
677 return "%%%s" % match.group(1).upper()
678def escape_path(path):
679 """Escape any invalid characters in HTTP URL, and uppercase all escapes."""
680 # There's no knowing what character encoding was used to create URLs
681 # containing %-escapes, but since we have to pick one to escape invalid
682 # path characters, we pick UTF-8, as recommended in the HTML 4.0
683 # specification:
684 # http://www.w3.org/TR/REC-html40/appendix/notes.html#h-B.2.1
685 # And here, kind of: draft-fielding-uri-rfc2396bis-03
686 # (And in draft IRI specification: draft-duerst-iri-05)
687 # (And here, for new URI schemes: RFC 2718)
688 path = urllib.parse.quote(path, HTTP_PATH_SAFE)
689 path = ESCAPED_CHAR_RE.sub(uppercase_escaped_char, path)
690 return path
691
692def reach(h):
693 """Return reach of host h, as defined by RFC 2965, section 1.

Callers 3

test_escape_pathMethod · 0.90
request_pathFunction · 0.85

Calls 2

quoteMethod · 0.80
subMethod · 0.45

Tested by 1

test_escape_pathMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…