<s> from six import text_type , u , b , PY3 <EOL> from six . moves . urllib . parse import parse_qs <EOL> import base64 <EOL> import hmac <EOL> import hashlib <EOL> def token_decoder ( token ) : <EOL> token_data = { } <EOL> encoded = token [ <NUM_LIT:4> : ] <EOL> decoded = base64 . b64decode ( encoded . encode ( '<STR_LIT:utf-8>' ) ) <EOL> if PY3 : <EOL> decoded = decoded . decode ( ) <EOL> parts = decoded . split ( u ( '<STR_LIT::>' ) ) <EOL> for decoded_part in iter ( parts ) : <EOL> token_data . update ( parse_qs ( decoded_part ) ) <EOL> for k in iter ( token_data ) : <EOL> token_data [ k ] = token_data [ k ] [ <NUM_LIT:0> ] <EOL> token_data [ u ( '<STR_LIT>' ) ] = parts [ <NUM_LIT:1> ] <EOL> return token_data <EOL> def token_signature_validator ( token , secret ) : <EOL> decoded = token_decoder ( token ) <EOL> signature = hmac . new ( secret . encode ( u ( '<STR_LIT:utf-8>' ) ) , decoded [ u ( '<STR_LIT>' ) ] . encode ( '<STR_LIT:utf-8>' ) , hashlib . sha1 ) . hexdigest ( ) <EOL> return signature == decoded [ u ( '<STR_LIT>' ) ] </s>
