diff options
| author | Nick Pope <nick@nickpope.me.uk> | 2022-11-04 12:33:09 +0000 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-11-10 13:52:17 +0100 |
| commit | 9bd174b9a75299dce33e673a559f2b673399b971 (patch) | |
| tree | 1deaac147ece269ef6a895986291d536ed334c49 /django/utils | |
| parent | fad070b07b8c5f5022c2867d291cb6968709f2a1 (diff) | |
Updated documentation and comments for RFC updates.
- Updated references to RFC 1123 to RFC 5322
- Only partial as RFC 5322 sort of sub-references RFC 1123.
- Updated references to RFC 2388 to RFC 7578
- Except RFC 2388 Section 5.3 which has no equivalent.
- Updated references to RFC 2396 to RFC 3986
- Updated references to RFC 2616 to RFC 9110
- Updated references to RFC 3066 to RFC 5646
- Updated references to RFC 7230 to RFC 9112
- Updated references to RFC 7231 to RFC 9110
- Updated references to RFC 7232 to RFC 9110
- Updated references to RFC 7234 to RFC 9111
- Tidied up style of text when referring to RFC documents
Diffstat (limited to 'django/utils')
| -rw-r--r-- | django/utils/cache.py | 21 | ||||
| -rw-r--r-- | django/utils/encoding.py | 19 | ||||
| -rw-r--r-- | django/utils/html.py | 5 | ||||
| -rw-r--r-- | django/utils/http.py | 14 | ||||
| -rw-r--r-- | django/utils/translation/trans_real.py | 4 |
5 files changed, 31 insertions, 32 deletions
diff --git a/django/utils/cache.py b/django/utils/cache.py index 90292ce4da..2dd2c7796c 100644 --- a/django/utils/cache.py +++ b/django/utils/cache.py @@ -4,9 +4,7 @@ managing the "Vary" header of responses. It includes functions to patch the header of response objects directly and decorators that change functions to do that header-patching themselves. -For information on the Vary header, see: - - https://tools.ietf.org/html/rfc7231#section-7.1.4 +For information on the Vary header, see RFC 9110 Section 12.5.5. Essentially, the "Vary" HTTP header defines which headers a cache should take into account when building its cache key. Requests with the same path but @@ -139,7 +137,7 @@ def _precondition_failed(request): def _not_modified(request, response=None): new_response = HttpResponseNotModified() if response: - # Preserve the headers required by Section 4.1 of RFC 7232, as well as + # Preserve the headers required by RFC 9110 Section 15.4.5, as well as # Last-Modified. for header in ( "Cache-Control", @@ -177,7 +175,9 @@ def get_conditional_response(request, etag=None, last_modified=None, response=No if_modified_since = request.META.get("HTTP_IF_MODIFIED_SINCE") if_modified_since = if_modified_since and parse_http_date_safe(if_modified_since) - # Step 1 of section 6 of RFC 7232: Test the If-Match precondition. + # Evaluation of request preconditions below follows RFC 9110 Section + # 13.2.2. + # Step 1: Test the If-Match precondition. if if_match_etags and not _if_match_passes(etag, if_match_etags): return _precondition_failed(request) @@ -212,7 +212,7 @@ def get_conditional_response(request, etag=None, last_modified=None, response=No def _if_match_passes(target_etag, etags): """ - Test the If-Match comparison as defined in section 3.1 of RFC 7232. + Test the If-Match comparison as defined in RFC 9110 Section 13.1.1. """ if not target_etag: # If there isn't an ETag, then there can't be a match. @@ -233,15 +233,15 @@ def _if_match_passes(target_etag, etags): def _if_unmodified_since_passes(last_modified, if_unmodified_since): """ - Test the If-Unmodified-Since comparison as defined in section 3.4 of - RFC 7232. + Test the If-Unmodified-Since comparison as defined in RFC 9110 Section + 13.1.4. """ return last_modified and last_modified <= if_unmodified_since def _if_none_match_passes(target_etag, etags): """ - Test the If-None-Match comparison as defined in section 3.2 of RFC 7232. + Test the If-None-Match comparison as defined in RFC 9110 Section 13.1.2. """ if not target_etag: # If there isn't an ETag, then there isn't a match. @@ -260,7 +260,8 @@ def _if_none_match_passes(target_etag, etags): def _if_modified_since_passes(last_modified, if_modified_since): """ - Test the If-Modified-Since comparison as defined in section 3.3 of RFC 7232. + Test the If-Modified-Since comparison as defined in RFC 9110 Section + 13.1.3. """ return not last_modified or last_modified > if_modified_since diff --git a/django/utils/encoding.py b/django/utils/encoding.py index 360eb91ed5..43847b5385 100644 --- a/django/utils/encoding.py +++ b/django/utils/encoding.py @@ -112,16 +112,15 @@ def iri_to_uri(iri): Convert an Internationalized Resource Identifier (IRI) portion to a URI portion that is suitable for inclusion in a URL. - This is the algorithm from section 3.1 of RFC 3987, slightly simplified - since the input is assumed to be a string rather than an arbitrary byte - stream. + This is the algorithm from RFC 3987 Section 3.1, slightly simplified since + the input is assumed to be a string rather than an arbitrary byte stream. Take an IRI (string or UTF-8 bytes, e.g. '/I ♥ Django/' or b'/I \xe2\x99\xa5 Django/') and return a string containing the encoded result with ASCII chars only (e.g. '/I%20%E2%99%A5%20Django/'). """ # The list of safe characters here is constructed from the "reserved" and - # "unreserved" characters specified in sections 2.2 and 2.3 of RFC 3986: + # "unreserved" characters specified in RFC 3986 Sections 2.2 and 2.3: # reserved = gen-delims / sub-delims # gen-delims = ":" / "/" / "?" / "#" / "[" / "]" / "@" # sub-delims = "!" / "$" / "&" / "'" / "(" / ")" @@ -130,7 +129,7 @@ def iri_to_uri(iri): # Of the unreserved characters, urllib.parse.quote() already considers all # but the ~ safe. # The % character is also added to the list of safe characters here, as the - # end of section 3.1 of RFC 3987 specifically mentions that % must not be + # end of RFC 3987 Section 3.1 specifically mentions that % must not be # converted. if iri is None: return iri @@ -161,7 +160,7 @@ def uri_to_iri(uri): Convert a Uniform Resource Identifier(URI) into an Internationalized Resource Identifier(IRI). - This is the algorithm from section 3.2 of RFC 3987, excluding step 4. + This is the algorithm from RFC 3987 Section 3.2, excluding step 4. Take an URI in ASCII bytes (e.g. '/I%20%E2%99%A5%20Django/') and return a string containing the encoded result (e.g. '/I%20♥%20Django/'). @@ -197,13 +196,13 @@ def escape_uri_path(path): Escape the unsafe characters from the path portion of a Uniform Resource Identifier (URI). """ - # These are the "reserved" and "unreserved" characters specified in - # sections 2.2 and 2.3 of RFC 2396: + # These are the "reserved" and "unreserved" characters specified in RFC + # 3986 Sections 2.2 and 2.3: # reserved = ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" | "$" | "," # unreserved = alphanum | mark # mark = "-" | "_" | "." | "!" | "~" | "*" | "'" | "(" | ")" # The list of safe characters here is constructed subtracting ";", "=", - # and "?" according to section 3.3 of RFC 2396. + # and "?" according to RFC 3986 Section 3.3. # The reason for not subtracting and escaping "/" is that we are escaping # the entire path, not a path segment. return quote(path, safe="/:@&+$,-_.!~*'()") @@ -216,7 +215,7 @@ def punycode(domain): def repercent_broken_unicode(path): """ - As per section 3.2 of RFC 3987, step three of converting a URI into an IRI, + As per RFC 3987 Section 3.2, step three of converting a URI into an IRI, repercent-encode any octet produced that is not part of a strictly legal UTF-8 octet sequence. """ diff --git a/django/utils/html.py b/django/utils/html.py index 007602a14a..fdb88d6709 100644 --- a/django/utils/html.py +++ b/django/utils/html.py @@ -193,9 +193,8 @@ def smart_urlquote(url): def unquote_quote(segment): segment = unquote(segment) - # Tilde is part of RFC3986 Unreserved Characters - # https://tools.ietf.org/html/rfc3986#section-2.3 - # See also https://bugs.python.org/issue16285 + # Tilde is part of RFC 3986 Section 2.3 Unreserved Characters, + # see also https://bugs.python.org/issue16285 return quote(segment, safe=RFC3986_SUBDELIMS + RFC3986_GENDELIMS + "~") # Handle IDN before quoting. diff --git a/django/utils/http.py b/django/utils/http.py index d2ec2638b0..db4dee2f27 100644 --- a/django/utils/http.py +++ b/django/utils/http.py @@ -19,7 +19,7 @@ from urllib.parse import uses_params from django.utils.datastructures import MultiValueDict from django.utils.regex_helper import _lazy_re_compile -# based on RFC 7232, Appendix C +# Based on RFC 9110 Appendix A. ETAG_MATCH = _lazy_re_compile( r""" \A( # start of string and capture group @@ -94,8 +94,8 @@ def urlencode(query, doseq=False): def http_date(epoch_seconds=None): """ - Format the time to match the RFC1123 date format as specified by HTTP - RFC7231 section 7.1.1.1. + Format the time to match the RFC 5322 date format as specified by RFC 9110 + Section 5.6.7. `epoch_seconds` is a floating point number expressed in seconds since the epoch, in UTC - such as that outputted by time.time(). If set to None, it @@ -108,15 +108,15 @@ def http_date(epoch_seconds=None): def parse_http_date(date): """ - Parse a date format as specified by HTTP RFC7231 section 7.1.1.1. + Parse a date format as specified by HTTP RFC 9110 Section 5.6.7. The three formats allowed by the RFC are accepted, even if only the first one is still in widespread use. Return an integer expressed in seconds since the epoch, in UTC. """ - # email.utils.parsedate() does the job for RFC1123 dates; unfortunately - # RFC7231 makes it mandatory to support RFC850 dates too. So we roll + # email.utils.parsedate() does the job for RFC 1123 dates; unfortunately + # RFC 9110 makes it mandatory to support RFC 850 dates too. So we roll # our own RFC-compliant parsing. for regex in RFC1123_DATE, RFC850_DATE, ASCTIME_DATE: m = regex.match(date) @@ -210,7 +210,7 @@ def urlsafe_base64_decode(s): def parse_etags(etag_str): """ Parse a string of ETags given in an If-None-Match or If-Match header as - defined by RFC 7232. Return a list of quoted ETags, or ['*'] if all ETags + defined by RFC 9110. Return a list of quoted ETags, or ['*'] if all ETags should be matched. """ if etag_str.strip() == "*": diff --git a/django/utils/translation/trans_real.py b/django/utils/translation/trans_real.py index 595a9ec2e4..c1e64d4ebd 100644 --- a/django/utils/translation/trans_real.py +++ b/django/utils/translation/trans_real.py @@ -30,8 +30,8 @@ _default = None # magic gettext number to separate context from message CONTEXT_SEPARATOR = "\x04" -# Format of Accept-Language header values. From RFC 2616, section 14.4 and 3.9 -# and RFC 3066, section 2.1 +# Format of Accept-Language header values. From RFC 9110 Sections 12.4.2 and +# 12.5.4, and RFC 5646 Section 2.1. accept_language_re = _lazy_re_compile( r""" # "en", "en-au", "x-y-z", "es-419", "*" |
