Module Expr Str ImportFrom alias Import alias Import alias Import alias Import alias ImportFrom alias ImportFrom alias ImportFrom alias ImportFrom alias alias ImportFrom alias alias alias ImportFrom alias ClassDef bases NameLoad body Expr Str Pass decorator_list ClassDef bases NameLoad body Expr Str Pass decorator_list FunctionDef arguments args NameParam defaults body Return Call AttributeLoad Call AttributeLoad NameLoad attr NameLoad attr Str decorator_list FunctionDef arguments args NameParam defaults body Assign NameStore BinOpMult Str BinOpMod UnaryOpUSub Call NameLoad NameLoad Num Return Call AttributeLoad NameLoad attr BinOpAdd NameLoad NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam defaults body Return Call NameLoad Call AttributeLoad Call NameLoad NameLoad NameLoad NameLoad attr decorator_list FunctionDef arguments args NameParam defaults Str body Assign NameStore AttributeLoad NameLoad attr Assign TupleStore NameStore NameStore Call AttributeLoad NameLoad attr Str Num TryExcept body Assign NameStore Call NameLoad NameLoad handlers ExceptHandler type NameLoad name NameStore body Raise Call NameLoad BinOpMod Str TupleLoad NameLoad NameLoad TryExcept body Assign NameStore Call NameLoad NameLoad NameLoad handlers ExceptHandler type NameLoad name NameStore body Raise Call NameLoad BinOpMod Str TupleLoad NameLoad NameLoad Return Call NameLoad BinOpAdd Str AttributeLoad NameLoad attr keyword NameLoad decorator_list ClassDef bases NameLoad body Expr Str FunctionDef arguments args NameParam NameParam defaults body Return Call AttributeLoad Call AttributeLoad NameLoad attr NameLoad keyword TupleLoad Str Str attr Str decorator_list FunctionDef arguments args NameParam NameParam defaults body Return Call AttributeLoad NameLoad attr Call AttributeLoad NameLoad attr Str decorator_list decorator_list FunctionDef arguments args NameParam NameParam NameParam NameParam NameParam defaults NameLoad Str NameLoad NameLoad body Expr Str Assign NameStore Call AttributeLoad Call NameLoad attr NameLoad Assign NameStore NameLoad If NameLoad body Assign NameStore Call AttributeLoad NameLoad attr NameLoad If CompareLt Call NameLoad NameLoad BinOpSub Call NameLoad NameLoad Num body Assign NameStore NameLoad Assign NameStore NameLoad Assign NameStore Call NameLoad NameLoad If NameLoad body Assign NameStore BinOpAdd Str NameLoad Return Call AttributeLoad Call NameLoad NameLoad keyword NameLoad attr NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam NameParam NameParam defaults NameLoad Str NameLoad NameLoad body Expr Str Assign NameStore Call NameLoad Call AttributeLoad Call NameLoad NameLoad keyword NameLoad attr NameLoad keyword NameLoad Assign NameStore NameLoad If CompareEq SubscriptLoad NameLoad Slice Num Str body Assign NameStore SubscriptLoad NameLoad Slice Num Assign NameStore NameLoad Assign NameStore Call NameLoad NameLoad If NameLoad body Assign NameStore Call AttributeLoad NameLoad attr NameLoad Return Call AttributeLoad Call NameLoad attr NameLoad decorator_list ClassDef bases NameLoad body FunctionDef arguments args NameParam NameParam NameParam NameParam defaults NameLoad Str NameLoad body Assign AttributeStore NameLoad attr Call NameLoad NameLoad Assign AttributeStore NameLoad attr Call NameLoad BoolOpOr NameLoad AttributeLoad NameLoad attr Assign AttributeStore NameLoad attr Call NameLoad BoolOpOr NameLoad BinOpMod Str TupleLoad AttributeLoad AttributeLoad NameLoad attr attr AttributeLoad AttributeLoad NameLoad attr attr decorator_list FunctionDef arguments args NameParam NameParam defaults body Assign NameStore Call NameLoad BinOpAdd AttributeLoad NameLoad attr Str NameLoad AttributeLoad NameLoad attr Return Call NameLoad NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body Assign NameStore Call NameLoad NameLoad Return BinOpMod Call NameLoad Str TupleLoad NameLoad AttributeLoad NameLoad attr Call AttributeLoad NameLoad attr NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body Assign NameStore Call NameLoad NameLoad If UnaryOpNot CompareIn AttributeLoad NameLoad attr NameLoad body Raise Call NameLoad BinOpMod Str AttributeLoad NameLoad attr Assign TupleStore NameStore NameStore Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr Num If Call NameLoad NameLoad Call AttributeLoad NameLoad attr NameLoad body Return Call NameLoad NameLoad Raise Call NameLoad BinOpMod Str NameLoad decorator_list decorator_list ClassDef bases NameLoad body FunctionDef arguments args NameParam defaults body Return Call AttributeLoad AttributeLoad NameLoad attr attr Call NameLoad Call AttributeLoad NameLoad attr decorator_list FunctionDef arguments args NameParam NameParam defaults body Assign NameStore Call NameLoad NameLoad Assign NameStore BinOpMod Call NameLoad Str TupleLoad NameLoad AttributeLoad NameLoad attr Call AttributeLoad NameLoad attr Return Call AttributeLoad Call NameLoad NameLoad NameLoad attr NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam defaults NameLoad body Assign NameStore Call AttributeLoad Call NameLoad NameLoad NameLoad attr NameLoad Assign TupleStore NameStore NameStore Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr Num Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad If CompareIsNot NameLoad NameLoad body Assign NameStore BinOpSub Call AttributeLoad NameLoad attr NameLoad If CompareGt NameLoad NameLoad body Raise Call NameLoad BinOpMod Str TupleLoad NameLoad NameLoad Return NameLoad decorator_list decorator_list
N/A N/A 
Functions for creating and restoring url-safe signed JSON objects.

The format used looks like this:

>>> signing.dumps("hello")
'ImhlbGxvIg:1QaUZC:YIye-ze3TTx7gtSv422nZA4sgmk'

There are two components here, separated by a ':'. The first component is a
URLsafe base64 encoded JSON of the object passed to dumps(). The second
component is a base64 encoded hmac/SHA1 hash of "$first_component:$secret"

signing.loads(s) checks the signature and returns the deserialised object.
If the signature fails, a BadSignature exception is raised.

>>> signing.loads("ImhlbGxvIg:1QaUZC:YIye-ze3TTx7gtSv422nZA4sgmk")
u'hello'
>>> signing.loads("ImhlbGxvIg:1QaUZC:YIye-ze3TTx7gtSv422nZA4sgmk-modified")
...
BadSignature: Signature failed: ImhlbGxvIg:1QaUZC:YIye-ze3TTx7gtSv422nZA4sgmk-modified

You can optionally compress the JSON prior to base64 encoding it to save
space, using the compress=True argument. This checks if compression actually
helps and only applies compression if the result is a shorter string:

>>> signing.dumps(range(1, 20), compress=True)
'.eJwFwcERACAIwLCF-rCiILN47r-GyZVJsNgkxaFxoDgxcOHGxMKD_T7vhAml:1QaUaL:BA0thEZrp4FQVXIXuOvYJtLJSrQ'

The fact that the string is compressed is signalled by the prefixed '.' at the
start of the base64 JSON.

There are 65 url-safe characters: the 64 used by url-safe base64 and the ':'.
These functions make use of all of them.
 __future__ unicode_literals N/A base64 N/A json N/A time N/A zlib django.conf settings django.core.exceptions ImproperlyConfigured django.utils baseconv django.utils.crypto constant_time_compare salted_hmac django.utils.encoding force_bytes force_str force_text django.utils.importlib import_module BadSignature N/A Exception N/A N/A 
    Signature does not match
     N/A N/A SignatureExpired N/A BadSignature N/A N/A 
    Signature timestamp is older than required max_age
     N/A N/A b64_encode N/A N/A s N/A N/A N/A N/A N/A N/A N/A base64 urlsafe_b64encode s strip = N/A b64_decode N/A N/A s N/A N/A N/A pad N/A = N/A N/A N/A len s 4 N/A N/A N/A base64 urlsafe_b64decode N/A s pad N/A base64_hmac N/A N/A salt value key N/A N/A N/A N/A b64_encode N/A N/A N/A salted_hmac salt value key digest N/A get_cookie_signer N/A N/A salt N/A django.core.signing.get_cookie_signer N/A N/A modpath N/A settings SIGNING_BACKEND N/A N/A module attr N/A N/A modpath rsplit . 1 N/A N/A N/A mod N/A import_module module N/A N/A N/A ImportError N/A e N/A N/A N/A ImproperlyConfigured N/A Error importing cookie signer %s: "%s" N/A modpath e N/A N/A N/A Signer N/A getattr mod attr N/A N/A N/A AttributeError N/A e N/A N/A N/A ImproperlyConfigured N/A Error importing cookie signer %s: "%s" N/A modpath e N/A N/A Signer N/A django.http.cookies N/A settings SECRET_KEY salt salt N/A JSONSerializer N/A object N/A N/A 
    Simple wrapper around json to be used in signing.dumps and
    signing.loads.
     dumps N/A N/A self obj N/A N/A N/A N/A N/A N/A N/A json dumps obj separators N/A , : encode latin-1 N/A loads N/A N/A self data N/A N/A N/A N/A N/A json loads N/A N/A data decode latin-1 N/A N/A dumps N/A N/A obj key salt serializer compress N/A None django.core.signing JSONSerializer False N/A N/A 
    Returns URL-safe, sha1 signed base64 compressed JSON string. If key is
    None, settings.SECRET_KEY is used instead.

    If compress is True (not the default) checks if compressing using zlib can
    save some space. Prepends a '.' to signify compression. This is included
    in the signature, to protect against zip bombs.

    Salt can be used to namespace the hash, so that a signed string is
    only valid for a given namespace. Leaving this at the default
    value or re-using a salt value across different parts of your
    application without good cause is a security risk.

    The serializer is expected to return a bytestring.
     N/A data N/A N/A N/A serializer dumps obj N/A is_compressed False N/A compress N/A N/A compressed N/A N/A zlib compress data N/A N/A N/A len compressed N/A N/A len data 1 N/A N/A data compressed N/A is_compressed True N/A base64d N/A b64_encode data N/A is_compressed N/A N/A base64d N/A . base64d N/A N/A N/A N/A TimestampSigner key salt salt sign base64d N/A loads N/A N/A s key salt serializer max_age N/A None django.core.signing JSONSerializer None N/A N/A 
    Reverse of dumps(), raises BadSignature if signature fails.

    The serializer is expected to accept a bytestring.
     N/A base64d N/A force_bytes N/A N/A N/A TimestampSigner key salt salt unsign s max_age max_age N/A decompress False N/A N/A N/A base64d N/A 1 . N/A N/A base64d N/A base64d N/A 1 N/A decompress True N/A data N/A b64_decode base64d N/A decompress N/A N/A data N/A N/A zlib decompress data N/A N/A N/A N/A serializer loads data N/A Signer N/A object N/A __init__ N/A N/A self key sep salt N/A None : None N/A N/A N/A self sep N/A str sep N/A N/A self key N/A str N/A key N/A settings SECRET_KEY N/A N/A self salt N/A str N/A salt N/A %s.%s N/A N/A N/A self __class__ __module__ N/A N/A self __class__ __name__ N/A signature N/A N/A self value N/A N/A N/A signature N/A base64_hmac N/A N/A self salt signer value N/A self key N/A N/A force_str signature N/A sign N/A N/A self value N/A N/A N/A value N/A force_str value N/A N/A N/A str %s%s%s N/A value N/A self sep N/A N/A self signature value N/A unsign N/A N/A self signed_value N/A N/A N/A signed_value N/A force_str signed_value N/A N/A N/A N/A self sep signed_value N/A N/A N/A BadSignature N/A No "%s" found in value N/A self sep N/A N/A value sig N/A N/A signed_value rsplit N/A self sep 1 N/A N/A constant_time_compare sig N/A N/A self signature value N/A N/A N/A force_text value N/A N/A BadSignature N/A Signature "%s" does not match sig N/A N/A TimestampSigner N/A Signer N/A timestamp N/A N/A self N/A N/A N/A N/A N/A N/A baseconv base62 encode N/A int N/A N/A time time N/A sign N/A N/A self value N/A N/A N/A value N/A force_str value N/A value N/A N/A str %s%s%s N/A value N/A self sep N/A N/A self timestamp N/A N/A N/A N/A super TimestampSigner self sign value N/A unsign N/A N/A self value max_age N/A None N/A N/A result N/A N/A N/A super TimestampSigner self unsign value N/A N/A value timestamp N/A N/A result rsplit N/A self sep 1 N/A timestamp N/A N/A N/A baseconv base62 decode timestamp N/A N/A max_age None N/A N/A age N/A N/A N/A time time timestamp N/A N/A age max_age N/A N/A N/A SignatureExpired N/A Signature age %s > %s seconds N/A age max_age N/A value N/A N/A