@@ -746,25 +746,32 @@ def quote(string, safe='/', encoding=None, errors=None):
746
746
"""quote('abc def') -> 'abc%20def'
747
747
748
748
Each part of a URL, e.g. the path info, the query, etc., has a
749
- different set of reserved characters that must be quoted.
749
+ different set of reserved characters that must be quoted. The
750
+ quote function offers a cautious (not minimal) way to quote a
751
+ string for most of these parts.
750
752
751
- RFC 3986 Uniform Resource Identifiers (URI): Generic Syntax lists
752
- the following reserved characters.
753
+ RFC 3986 Uniform Resource Identifier (URI): Generic Syntax lists
754
+ the following (un) reserved characters.
753
755
754
- reserved = ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" |
755
- "$" | "," | "~"
756
+ unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
757
+ reserved = gen-delims / sub-delims
758
+ gen-delims = ":" / "/" / "?" / "#" / "[" / "]" / "@"
759
+ sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
760
+ / "*" / "+" / "," / ";" / "="
756
761
757
- Each of these characters is reserved in some component of a URL,
762
+ Each of the reserved characters is reserved in some component of a URL,
758
763
but not necessarily in all of them.
759
764
760
- Python 3.7 updates from using RFC 2396 to RFC 3986 to quote URL strings.
761
- Now, "~" is included in the set of reserved characters.
765
+ The quote function %-escapes all characters that are neither in the
766
+ unreserved chars ("always safe") nor the additional chars set via the
767
+ safe arg.
768
+
769
+ The default for the safe arg is '/'. The character is reserved, but in
770
+ typical usage the quote function is being called on a path where the
771
+ existing slash characters are to be preserved.
762
772
763
- By default, the quote function is intended for quoting the path
764
- section of a URL. Thus, it will not encode '/'. This character
765
- is reserved, but in typical usage the quote function is being
766
- called on a path where the existing slash characters are used as
767
- reserved characters.
773
+ Python 3.7 updates from using RFC 2396 to RFC 3986 to quote URL strings.
774
+ Now, "~" is included in the set of unreserved characters.
768
775
769
776
string and safe may be either str or bytes objects. encoding and errors
770
777
must not be specified if string is a bytes object.
0 commit comments