module documentation

Undocumented

Function base36​_to​_int Convert a base 36 string to an int. Raise ValueError if the input won't fit into an int.
Function http​_date Format the time to match the RFC1123 date format as specified by HTTP RFC7231 section 7.1.1.1.
Function int​_to​_base36 Convert an integer to a base36 string.
Function urlencode A version of Python's urllib.parse.urlencode() function that can operate on MultiValueDict and non-string values.
Function urlsafe​_base64​_decode Decode a base64 encoded string. Add back any trailing equal signs that might have been stripped.
Function urlsafe​_base64​_encode Encode a bytestring to a base64 string for use in URLs. Strip any trailing equal signs.
Constant ASCTIME​_DATE Undocumented
Constant ETAG​_MATCH Undocumented
Constant MONTHS Undocumented
Constant RFC1123​_DATE Undocumented
Constant RFC3986​_GENDELIMS Undocumented
Constant RFC3986​_SUBDELIMS Undocumented
Constant RFC850​_DATE Undocumented
Function ​_url​_has​_allowed​_host​_and​_scheme Undocumented
Function ​_urlparse No summary
Function ​_urlsplit No summary
Function escape​_leading​_slashes If redirecting to an absolute path (two leading slashes), a slash must be escaped to prevent browsers from handling the path as schemaless and redirecting to another host.
Function is​_same​_domain Return True if the host is either an exact match or a match to the wildcard pattern.
Function parse​_etags 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 should be matched.
Function parse​_http​_date Parse a date format as specified by HTTP RFC7231 section 7.1.1.1.
Function parse​_http​_date​_safe Same as parse_http_date, but return None if the input is invalid.
Function quote​_etag If the provided string is already a quoted ETag, return it. Otherwise, wrap the string in quotes, making it a strong ETag.
Function url​_has​_allowed​_host​_and​_scheme Return True if the url uses an allowed host and a safe scheme.
Constant __D Undocumented
Constant __D2 Undocumented
Constant __M Undocumented
Constant __T Undocumented
Constant __Y Undocumented
Constant __Y2 Undocumented
def base36_to_int(s):
Convert a base 36 string to an int. Raise ValueError if the input won't fit into an int.
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.

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 defaults to the current time.

Output a string in the format 'Wdy, DD Mon YYYY HH:MM:SS GMT'.

def int_to_base36(i):
Convert an integer to a base36 string.
def urlencode(query, doseq=False):
A version of Python's urllib.parse.urlencode() function that can operate on MultiValueDict and non-string values.
def urlsafe_base64_decode(s):
Decode a base64 encoded string. Add back any trailing equal signs that might have been stripped.
def urlsafe_base64_encode(s):
Encode a bytestring to a base64 string for use in URLs. Strip any trailing equal signs.
ASCTIME_DATE =

Undocumented

Value
_lazy_re_compile('^\\w{3} %s %s %s %s$'%(__M, __D2, __T, __Y))
ETAG_MATCH =

Undocumented

Value
_lazy_re_compile('''
    \\A(      # start of string and capture group
    (?:W/)?  # optional weak indicator
    "        # opening quote
    [^"]*    # any sequence of non-quote characters
    "        # end quote
    )\\Z      # end of string and capture group
...
MONTHS =

Undocumented

Value
"""jan feb mar apr may jun jul aug sep oct nov dec""".split()
RFC1123_DATE =

Undocumented

Value
_lazy_re_compile('^\\w{3}, %s %s %s %s GMT$'%(__D, __M, __Y, __T))
RFC3986_GENDELIMS: str =

Undocumented

Value
':/?#[]@'
RFC3986_SUBDELIMS: str =

Undocumented

Value
'!$&\'()*+,;='
RFC850_DATE =

Undocumented

Value
_lazy_re_compile('^\\w{6,9}, %s-%s-%s %s GMT$'%(__D, __M, __Y2, __T))
def _url_has_allowed_host_and_scheme(url, allowed_hosts, require_https=False):

Undocumented

def _urlparse(url, scheme='', allow_fragments=True):
Parse a URL into 6 components: <scheme>://<netloc>/<path>;<params>?<query>#<fragment> Return a 6-tuple: (scheme, netloc, path, params, query, fragment). Note that we don't break the components up in smaller bits (e.g. netloc is a single string) and we don't expand % escapes.
def _urlsplit(url, scheme='', allow_fragments=True):
Parse a URL into 5 components: <scheme>://<netloc>/<path>?<query>#<fragment> Return a 5-tuple: (scheme, netloc, path, query, fragment). Note that we don't break the components up in smaller bits (e.g. netloc is a single string) and we don't expand % escapes.
def escape_leading_slashes(url):
If redirecting to an absolute path (two leading slashes), a slash must be escaped to prevent browsers from handling the path as schemaless and redirecting to another host.
def is_same_domain(host, pattern):

Return True if the host is either an exact match or a match to the wildcard pattern.

Any pattern beginning with a period matches a domain and all of its subdomains. (e.g. .example.com matches example.com and foo.example.com). Anything else is an exact string match.

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 should be matched.
def parse_http_date(date):

Parse a date format as specified by HTTP RFC7231 section 7.1.1.1.

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.

def parse_http_date_safe(date):
Same as parse_http_date, but return None if the input is invalid.
def quote_etag(etag_str):
If the provided string is already a quoted ETag, return it. Otherwise, wrap the string in quotes, making it a strong ETag.
def url_has_allowed_host_and_scheme(url, allowed_hosts, require_https=False):

Return True if the url uses an allowed host and a safe scheme.

Always return False on an empty url.

If require_https is True, only 'https' will be considered a valid scheme, as opposed to 'http' and 'https' with the default, False.

Note: "True" doesn't entail that a URL is "safe". It may still be e.g. quoted incorrectly. Ensure to also use django.utils.encoding.iri_to_uri() on the path component of untrusted URLs.

__D: str =

Undocumented

Value
'(?P<day>\\d{2})'
__D2: str =

Undocumented

Value
'(?P<day>[ \\d]\\d)'
__M: str =

Undocumented

Value
'(?P<mon>\\w{3})'
__T: str =

Undocumented

Value
'(?P<hour>\\d{2}):(?P<min>\\d{2}):(?P<sec>\\d{2})'
__Y: str =

Undocumented

Value
'(?P<year>\\d{4})'
__Y2: str =

Undocumented

Value
'(?P<year>\\d{2})'