forked from orbit-oss/flask
Fixed merging confict
This commit is contained in:
commit
eeb0e94951
9 changed files with 147 additions and 13 deletions
36
flask.py
36
flask.py
|
|
@ -13,6 +13,7 @@ from __future__ import with_statement
|
|||
import os
|
||||
import sys
|
||||
import types
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from itertools import chain
|
||||
from jinja2 import Environment, PackageLoader, FileSystemLoader
|
||||
|
|
@ -93,7 +94,20 @@ class _RequestGlobals(object):
|
|||
pass
|
||||
|
||||
|
||||
class _NullSession(SecureCookie):
|
||||
class Session(SecureCookie):
|
||||
"""Expands the session for support for switching between permanent
|
||||
and non-permanent sessions.
|
||||
"""
|
||||
|
||||
def _get_permanent(self):
|
||||
return self.get('_permanent', False)
|
||||
def _set_permanent(self, value):
|
||||
self['_permanent'] = bool(value)
|
||||
permanent = property(_get_permanent, _set_permanent)
|
||||
del _get_permanent, _set_permanent
|
||||
|
||||
|
||||
class _NullSession(Session):
|
||||
"""Class used to generate nicer error messages if sessions are not
|
||||
available. Will still allow read-only access to the empty session
|
||||
but fail on setting.
|
||||
|
|
@ -158,6 +172,11 @@ def url_for(endpoint, **values):
|
|||
any ``'admin.index'`` `index` of the `admin` module
|
||||
==================== ======================= =============================
|
||||
|
||||
Variable arguments that are unknown to the target endpoint are appended
|
||||
to the generated URL as query arguments.
|
||||
|
||||
For more information, head over to the :ref:`Quickstart <url-building>`.
|
||||
|
||||
:param endpoint: the endpoint of the URL (name of the function)
|
||||
:param values: the variable arguments of the URL rule
|
||||
"""
|
||||
|
|
@ -511,6 +530,11 @@ class Flask(_PackageBoundObject):
|
|||
#: The secure cookie uses this for the name of the session cookie
|
||||
session_cookie_name = 'session'
|
||||
|
||||
#: A :class:`~datetime.timedelta` which is used to set the expiration
|
||||
#: date of a permanent session. The default is 31 days which makes a
|
||||
#: permanent session survive for roughly one month.
|
||||
permanent_session_lifetime = timedelta(days=31)
|
||||
|
||||
#: options that are passed directly to the Jinja2 environment
|
||||
jinja_options = ImmutableDict(
|
||||
autoescape=True,
|
||||
|
|
@ -664,8 +688,8 @@ class Flask(_PackageBoundObject):
|
|||
"""
|
||||
key = self.secret_key
|
||||
if key is not None:
|
||||
return SecureCookie.load_cookie(request, self.session_cookie_name,
|
||||
secret_key=key)
|
||||
return Session.load_cookie(request, self.session_cookie_name,
|
||||
secret_key=key)
|
||||
|
||||
def save_session(self, session, response):
|
||||
"""Saves the session if it needs updates. For the default
|
||||
|
|
@ -676,7 +700,11 @@ class Flask(_PackageBoundObject):
|
|||
object)
|
||||
:param response: an instance of :attr:`response_class`
|
||||
"""
|
||||
session.save_cookie(response, self.session_cookie_name)
|
||||
expires = None
|
||||
if session.permanent:
|
||||
expires = datetime.utcnow() + self.permanent_session_lifetime
|
||||
session.save_cookie(response, self.session_cookie_name,
|
||||
expires=expires, httponly=True)
|
||||
|
||||
def register_module(self, module, **options):
|
||||
"""Registers a module with this application. The keyword argument
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue