import json
import base64
from .constants import COOKIE_KEY


def parse_cookie(request):
    cookie = request.COOKIES.get(COOKIE_KEY)
    if cookie is not None:
        try:
            return json.loads(base64.b64decode(cookie))
        except:  # pylint: disable=bare-except
            pass

    return None
