本文整理汇总了Python中werkzeug.contrib.sessions.FilesystemSessionStore.new方法的典型用法代码示例。如果您正苦于以下问题:Python FilesystemSessionStore.new方法的具体用法?Python FilesystemSessionStore.new怎么用?Python FilesystemSessionStore.new使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类werkzeug.contrib.sessions.FilesystemSessionStore
的用法示例。
在下文中一共展示了FilesystemSessionStore.new方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_non_urandom
# 需要导入模块: from werkzeug.contrib.sessions import FilesystemSessionStore [as 别名]
# 或者: from werkzeug.contrib.sessions.FilesystemSessionStore import new [as 别名]
def test_non_urandom(tmpdir):
urandom = os.urandom
del os.urandom
try:
store = FilesystemSessionStore(str(tmpdir))
store.new()
finally:
os.urandom = urandom
示例2: test_non_urandom
# 需要导入模块: from werkzeug.contrib.sessions import FilesystemSessionStore [as 别名]
# 或者: from werkzeug.contrib.sessions.FilesystemSessionStore import new [as 别名]
def test_non_urandom(self):
urandom = os.urandom
del os.urandom
try:
store = FilesystemSessionStore(self.session_folder)
store.new()
finally:
os.urandom = urandom
示例3: test_renewing_fs_session
# 需要导入模块: from werkzeug.contrib.sessions import FilesystemSessionStore [as 别名]
# 或者: from werkzeug.contrib.sessions.FilesystemSessionStore import new [as 别名]
def test_renewing_fs_session(tmpdir):
store = FilesystemSessionStore(str(tmpdir), renew_missing=True)
x = store.new()
store.save(x)
store.delete(x)
x2 = store.get(x.sid)
assert x2.new
示例4: test_renewing_fs_session
# 需要导入模块: from werkzeug.contrib.sessions import FilesystemSessionStore [as 别名]
# 或者: from werkzeug.contrib.sessions.FilesystemSessionStore import new [as 别名]
def test_renewing_fs_session(self):
store = FilesystemSessionStore(self.session_folder, renew_missing=True)
x = store.new()
store.save(x)
store.delete(x)
x2 = store.get(x.sid)
assert x2.new
示例5: test_basic_fs_sessions
# 需要导入模块: from werkzeug.contrib.sessions import FilesystemSessionStore [as 别名]
# 或者: from werkzeug.contrib.sessions.FilesystemSessionStore import new [as 别名]
def test_basic_fs_sessions():
"""Test basic file system sessions"""
store = FilesystemSessionStore(session_folder)
x = store.new()
assert x.new
assert not x.modified
x['foo'] = [1, 2, 3]
assert x.modified
store.save(x)
x2 = store.get(x.sid)
assert not x2.new
assert not x2.modified
assert x2 is not x
assert x2 == x
x2['test'] = 3
assert x2.modified
assert not x2.new
store.save(x2)
x = store.get(x.sid)
store.delete(x)
x2 = store.get(x.sid)
# the session is not new when it was used previously.
assert not x2.new
示例6: before_request
# 需要导入模块: from werkzeug.contrib.sessions import FilesystemSessionStore [as 别名]
# 或者: from werkzeug.contrib.sessions.FilesystemSessionStore import new [as 别名]
def before_request():
session_store = FilesystemSessionStore(SESSIONS_DIR)
if 'sid' in session:
sid = session.get('sid')
g.session = session_store.get(sid)
else:
session['sid'] = os.urandom(24)
g.session = session_store.new()
示例7: WSGIApplication
# 需要导入模块: from werkzeug.contrib.sessions import FilesystemSessionStore [as 别名]
# 或者: from werkzeug.contrib.sessions.FilesystemSessionStore import new [as 别名]
class WSGIApplication(object):
def __init__(self, url_mapping, middlewares=None):
self.url_mapping = url_mapping
self.session_store = FilesystemSessionStore()
#self.session_store = BDBSessionStore()
#self.session_store = MemorySessionStore()
self.middlewares = middlewares or []
def addMiddleware(self, middleware):
self.middlewares.append(middleware)
def __call__(self, environ, start_response):
# start_response('200 OK', [('Content-type','text/plain')])
# return ['Hello World!']
adapter = self.url_mapping.bind_to_environ(environ)
# build request with session
request = Request(environ)
request.session = dummy_session
request.user_id = None
# url mapping
try:
endpoint, kwargs = adapter.match()
# turn hander class path like 'www.views.main.index' to a real
# handler class like index
if isinstance(endpoint, basestring):
dot = endpoint.rindex('.')
module, cls = endpoint[:dot], endpoint[dot+1:]
endpoint = __import__(module, {}, {}, [cls])
# build handler
handler = endpoint()
if handler.with_session:
sid = request.cookies.get('session_id')
if sid is None:
request.session = self.session_store.new()
else:
request.session = self.session_store.get(sid)
# build user if possible
request.user_id = request.session.get(SESSION_USER_KEY)
handler.app = self
handler.errors = {}
if settings.store_manager:
handler.store = settings.store_manager.new()
handler.request = request
# middleware
for middleware in self.middlewares:
middleware.processRequest(handler.request)
response = handler(kwargs)
for middleware in reversed(self.middlewares):
middleware.processResponse(handler.request, response)
assert isinstance(response, BaseResponse)
except HTTPException, e:
response = e
except Exception, e:
logging.error(e)
if settings.debug:
raise
response = InternalServerError()
示例8: test_fs_session_lising
# 需要导入模块: from werkzeug.contrib.sessions import FilesystemSessionStore [as 别名]
# 或者: from werkzeug.contrib.sessions.FilesystemSessionStore import new [as 别名]
def test_fs_session_lising(tmpdir):
store = FilesystemSessionStore(str(tmpdir), renew_missing=True)
sessions = set()
for x in range(10):
sess = store.new()
store.save(sess)
sessions.add(sess.sid)
listed_sessions = set(store.list())
assert sessions == listed_sessions
示例9: test_fs_session_lising
# 需要导入模块: from werkzeug.contrib.sessions import FilesystemSessionStore [as 别名]
# 或者: from werkzeug.contrib.sessions.FilesystemSessionStore import new [as 别名]
def test_fs_session_lising():
"""Test listing of filesystem sessions"""
store = FilesystemSessionStore(session_folder, renew_missing=True)
sessions = set()
for x in xrange(10):
sess = store.new()
store.save(sess)
sessions.add(sess.sid)
listed_sessions = set(store.list())
assert sessions == listed_sessions
示例10: before_request
# 需要导入模块: from werkzeug.contrib.sessions import FilesystemSessionStore [as 别名]
# 或者: from werkzeug.contrib.sessions.FilesystemSessionStore import new [as 别名]
def before_request():
"""
Make sure we are connected to the database each request and also
do the session handling.
"""
g.db = connect_db()
session_store = FilesystemSessionStore(config.SESSIONS_DIR)
if 'sid' in session:
sid = session.get('sid')
g.session = session_store.get(sid)
if 'user' in g.session:
g.user = g.session['user']
else:
g.user = None
else:
g.session = session_store.new()
g.user = None
示例11: test_basic_fs_sessions
# 需要导入模块: from werkzeug.contrib.sessions import FilesystemSessionStore [as 别名]
# 或者: from werkzeug.contrib.sessions.FilesystemSessionStore import new [as 别名]
def test_basic_fs_sessions(self):
store = FilesystemSessionStore(self.session_folder)
x = store.new()
assert x.new
assert not x.modified
x["foo"] = [1, 2, 3]
assert x.modified
store.save(x)
x2 = store.get(x.sid)
assert not x2.new
assert not x2.modified
assert x2 is not x
assert x2 == x
x2["test"] = 3
assert x2.modified
assert not x2.new
store.save(x2)
x = store.get(x.sid)
store.delete(x)
x2 = store.get(x.sid)
# the session is not new when it was used previously.
assert not x2.new
示例12: config
# 需要导入模块: from werkzeug.contrib.sessions import FilesystemSessionStore [as 别名]
# 或者: from werkzeug.contrib.sessions.FilesystemSessionStore import new [as 别名]
#.........这里部分代码省略.........
try:
endpoint, values = adapter.match()
mcontroller = import_module('app.controllers')
# detect filters
filters = endpoint.split(',')
endpoint_pieces = filters[-1].split('.')
# if there exists any filter defined
if len(filters) > 1:
filters = filters[:-1]
# here run filters
for f in filters:
fpieces = f.split('.')
cls = fpieces[0]
fnc = fpieces[1]
mfilter = mcontroller
obj = getattr(mfilter, cls)
ifilter = obj(request)
raw = getattr(ifilter, fnc)(** values)
if isinstance(raw, basestring):
return Response(raw)
if isinstance(raw, Response):
return raw
cls = endpoint_pieces[0]
restful = False
try:
fnc = endpoint_pieces[1]
except:
restful = True
fnc = None
obj = getattr(mcontroller, cls)
instance = obj(request)
raw = None
if restful:
raw = getattr(instance, request.method.lower())(**values)
else:
raw = getattr(instance, fnc)(** values)
if isinstance(raw, Response):
return raw
else:
return Response(raw)
except HTTPException as e:
return e
def wsgi_app(self, environ, start_response):
"""
Function returns the wsgi app of glim framework.
Args
----
environ (unknown type): The werkzeug environment.
start_response (function): The werkzeug's start_response
function.
Returns
-------
response (werkzeug.wrappers.Response): the dispatched response
object.
"""
request = Request(environ)
if self.session_store is not None:
sid = request.cookies.get(self.config['sessions']['id_header'])
if sid is None:
request.session = self.session_store.new()
else:
request.session = self.session_store.get(sid)
response = self.dispatch_request(request)
if self.session_store is not None:
if request.session.should_save:
self.session_store.save(request.session)
response.set_cookie(
self.config['sessions']['id_header'],
request.session.sid
)
return response(environ, start_response)
def __call__(self, environ, start_response):
return self.wsgi_app(environ, start_response)