MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / quote

Function quote

tools/python-3.11.9-amd64/Lib/urllib/parse.py:847–899  ·  view source on GitHub ↗

quote('abc def') -> 'abc%20def' Each part of a URL, e.g. the path info, the query, etc., has a different set of reserved characters that must be quoted. The quote function offers a cautious (not minimal) way to quote a string for most of these parts. RFC 3986 Uniform Res

(string, safe='/', encoding=None, errors=None)

Source from the content-addressed store, hash-verified

845 return res
846
847def quote(string, safe='/', encoding=None, errors=None):
848 """quote('abc def') -> 'abc%20def'
849
850 Each part of a URL, e.g. the path info, the query, etc., has a
851 different set of reserved characters that must be quoted. The
852 quote function offers a cautious (not minimal) way to quote a
853 string for most of these parts.
854
855 RFC 3986 Uniform Resource Identifier (URI): Generic Syntax lists
856 the following (un)reserved characters.
857
858 unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
859 reserved = gen-delims / sub-delims
860 gen-delims = ":" / "/" / "?" / "#" / "[" / "]" / "@"
861 sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
862 / "*" / "+" / "," / ";" / "="
863
864 Each of the reserved characters is reserved in some component of a URL,
865 but not necessarily in all of them.
866
867 The quote function %-escapes all characters that are neither in the
868 unreserved chars ("always safe") nor the additional chars set via the
869 safe arg.
870
871 The default for the safe arg is '/'. The character is reserved, but in
872 typical usage the quote function is being called on a path where the
873 existing slash characters are to be preserved.
874
875 Python 3.7 updates from using RFC 2396 to RFC 3986 to quote URL strings.
876 Now, "~" is included in the set of unreserved characters.
877
878 string and safe may be either str or bytes objects. encoding and errors
879 must not be specified if string is a bytes object.
880
881 The optional encoding and errors parameters specify how to deal with
882 non-ASCII characters, as accepted by the str.encode method.
883 By default, encoding='utf-8' (characters are encoded with UTF-8), and
884 errors='strict' (unsupported characters raise a UnicodeEncodeError).
885 """
886 if isinstance(string, str):
887 if not string:
888 return string
889 if encoding is None:
890 encoding = 'utf-8'
891 if errors is None:
892 errors = 'strict'
893 string = string.encode(encoding, errors)
894 else:
895 if encoding is not None:
896 raise TypeError("quote() doesn't support 'encoding' for bytes")
897 if errors is not None:
898 raise TypeError("quote() doesn't support 'errors' for bytes")
899 return quote_from_bytes(string, safe)
900
901def quote_plus(string, safe='', encoding=None, errors=None):
902 """Like quote(), but also replace ' ' with '+', as required for quoting

Callers 10

application_uriFunction · 0.90
request_uriFunction · 0.90
http_error_302Method · 0.90
pathname2urlFunction · 0.90
openMethod · 0.90
retry_http_basic_authMethod · 0.90
quote_plusFunction · 0.70

Calls 2

quote_from_bytesFunction · 0.85
encodeMethod · 0.45

Tested by

no test coverage detected