Exemple #1
0
def set_cookie(cookies,
               key,
               value,
               expires=None,
               httponly=True,
               path='/',
               samesite='lax'):
    key = ensure_str(key)
    cookies[key] = ensure_str(value)
    cookie = cookies[key]
    if expires:
        if isinstance(expires, timedelta):
            expires += utcnow()
        if isinstance(expires, datetime):
            expires = to_rfc822(expires)
        cookie['expires'] = ensure_str(expires)
    if httponly:
        cookie['httponly'] = True
    if path:
        cookie['path'] = ensure_str(path)
    if samesite:
        cookie['samesite'] = ensure_str(samesite)
    if website.cookie_domain:
        cookie['domain'] = ensure_str(website.cookie_domain)
    if website.canonical_scheme == 'https':
        cookie['secure'] = True
Exemple #2
0
def set_cookie(cookies, key, value, expires=None, httponly=True, path='/'):
    key = ensure_str(key)
    cookies[key] = ensure_str(value)
    cookie = cookies[key]
    if expires:
        if isinstance(expires, timedelta):
            expires += utcnow()
        if isinstance(expires, datetime):
            expires = to_rfc822(expires)
        cookie[str('expires')] = ensure_str(expires)
    if httponly:
        cookie[str('httponly')] = True
    if path:
        cookie[str('path')] = ensure_str(path)
    if website.cookie_domain:
        cookie[str('domain')] = ensure_str(website.cookie_domain)
    if website.canonical_scheme == 'https':
        cookie[str('secure')] = True
Exemple #3
0
from pando import Response, json
from pando.utils import to_rfc822, utcnow
from markupsafe import Markup
from postgres.cursors import SimpleCursorBase

from liberapay.constants import SAFE_METHODS
from liberapay.elsewhere._paginators import _modify_query
from liberapay.exceptions import (AccountSuspended, AuthRequired,
                                  ClosedAccount, LoginRequired,
                                  TooManyAdminActions)
from liberapay.models.community import Community
from liberapay.i18n.base import LOCALE_EN, add_helpers_to_context
from liberapay.website import website
from liberapay.utils import cbor

BEGINNING_OF_EPOCH = to_rfc822(datetime(1970, 1, 1)).encode('ascii')


def get_participant(state,
                    restrict=True,
                    redirect_stub=True,
                    allow_member=False,
                    block_suspended_user=False,
                    redirect_canon=True):
    """Given a Request, raise Response or return Participant.

    If restrict is True then we'll restrict access to owners and admins.

    """
    request = state['request']
    response = state['response']
Exemple #4
0
from pando.utils import to_rfc822, utcnow
from markupsafe import Markup
from postgres.cursors import SimpleCursorBase

from liberapay.elsewhere._paginators import _modify_query
from liberapay.exceptions import (
    AccountSuspended, AuthRequired, LoginRequired, TooManyAdminActions
)
from liberapay.models.community import Community
from liberapay.i18n.base import LOCALE_EN, add_helpers_to_context
from liberapay.security.csrf import SAFE_METHODS
from liberapay.website import website
from liberapay.utils import cbor


BEGINNING_OF_EPOCH = to_rfc822(datetime(1970, 1, 1)).encode('ascii')


class NS(object):

    def __init__(self, *d, **kw):
        self.__dict__.update(*d, **kw)

    def __str__(self):
        return 'NS(%s)' % self.__dict__


def get_participant(state, restrict=True, redirect_stub=True, allow_member=False,
                    block_suspended_user=False, redirect_canon=True):
    """Given a Request, raise Response or return Participant.
Exemple #5
0
def test_to_rfc822():
    expected = 'Thu, 01 Jan 1970 00:00:00 GMT'
    actual = to_rfc822(datetime(1970, 1, 1))
    assert actual == expected