当前位置: 首页>>代码示例>>Python>>正文


Python FilesystemSessionStore.save方法代码示例

本文整理汇总了Python中werkzeug.contrib.sessions.FilesystemSessionStore.save方法的典型用法代码示例。如果您正苦于以下问题:Python FilesystemSessionStore.save方法的具体用法?Python FilesystemSessionStore.save怎么用?Python FilesystemSessionStore.save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在werkzeug.contrib.sessions.FilesystemSessionStore的用法示例。


在下文中一共展示了FilesystemSessionStore.save方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_basic_fs_sessions

# 需要导入模块: from werkzeug.contrib.sessions import FilesystemSessionStore [as 别名]
# 或者: from werkzeug.contrib.sessions.FilesystemSessionStore import save [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
开发者ID:EnTeQuAk,项目名称:werkzeug,代码行数:27,代码来源:test_sessions.py

示例2: test_renewing_fs_session

# 需要导入模块: from werkzeug.contrib.sessions import FilesystemSessionStore [as 别名]
# 或者: from werkzeug.contrib.sessions.FilesystemSessionStore import save [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
开发者ID:Khan,项目名称:frankenserver,代码行数:9,代码来源:test_sessions.py

示例3: test_renewing_fs_session

# 需要导入模块: from werkzeug.contrib.sessions import FilesystemSessionStore [as 别名]
# 或者: from werkzeug.contrib.sessions.FilesystemSessionStore import save [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
开发者ID:Mirabis,项目名称:usntssearch,代码行数:9,代码来源:sessions.py

示例4: after_request

# 需要导入模块: from werkzeug.contrib.sessions import FilesystemSessionStore [as 别名]
# 或者: from werkzeug.contrib.sessions.FilesystemSessionStore import save [as 别名]
def after_request(response):
    session_store = FilesystemSessionStore(SESSIONS_DIR)
    if g.session.should_save:
        session_store.save(g.session)
        session['sid'] = g.session.sid
        session.permanent = True
        app.save_session(session, response)
    return response
开发者ID:riccardo-forina,项目名称:Roguehell,代码行数:10,代码来源:wsgiserver.py

示例5: test_fs_session_lising

# 需要导入模块: from werkzeug.contrib.sessions import FilesystemSessionStore [as 别名]
# 或者: from werkzeug.contrib.sessions.FilesystemSessionStore import save [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
开发者ID:Khan,项目名称:frankenserver,代码行数:12,代码来源:test_sessions.py

示例6: test_fs_session_lising

# 需要导入模块: from werkzeug.contrib.sessions import FilesystemSessionStore [as 别名]
# 或者: from werkzeug.contrib.sessions.FilesystemSessionStore import save [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
开发者ID:EnTeQuAk,项目名称:werkzeug,代码行数:13,代码来源:test_sessions.py

示例7: after_request

# 需要导入模块: from werkzeug.contrib.sessions import FilesystemSessionStore [as 别名]
# 或者: from werkzeug.contrib.sessions.FilesystemSessionStore import save [as 别名]
def after_request(response):
    """
    Closes the database again at the end of the request and store the
    session if neccessary.
    
    """
    session_store = FilesystemSessionStore(config.SESSIONS_DIR)
    if g.session.should_save:
        session_store.save(g.session)
        session['sid'] = g.session.sid
        session.permanent = True
        # we have to do this because Flask
        # stores the SecureCookie containing the "Session"
        # before calling the "after_request" functions
        app.save_session(session, response)
    g.db.close()
    return response
开发者ID:aljoscha,项目名称:shot-o-matic,代码行数:19,代码来源:shotomatic.py

示例8: test_basic_fs_sessions

# 需要导入模块: from werkzeug.contrib.sessions import FilesystemSessionStore [as 别名]
# 或者: from werkzeug.contrib.sessions.FilesystemSessionStore import save [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
开发者ID:BaxterStockman,项目名称:WorkoutBuddy,代码行数:26,代码来源:sessions.py

示例9: PredmetyApp

# 需要导入模块: from werkzeug.contrib.sessions import FilesystemSessionStore [as 别名]
# 或者: from werkzeug.contrib.sessions.FilesystemSessionStore import save [as 别名]
class PredmetyApp(object):
    def __init__(self, settings):
        self.settings = settings

        loader = jinja2.PackageLoader(__package__)
        def guess_autoescape(template_name):
            return template_name and any(template_name.endswith(ext)
                for ext in ('.html', '.htm', '.xml'))
        self.jinja = jinja2.Environment(loader=loader,
                                        autoescape=guess_autoescape)

        self.session_store = FilesystemSessionStore(
            renew_missing=True, path=settings.session_path)

        self.views = {}
        for module in site_modules:
            self.views.update(module.views)
        self.url_map = Map()
        self.url_map.converters['regex'] = RegexConverter
        for module in site_modules:
            for rulefactory in module.get_routes():
                self.url_map.add(rulefactory)

        self.db_engine = settings.db_connect()
        self.DbSession = sessionmaker(bind=self.db_engine)

    def create_tables(self):
        models.create_tables(self.db_engine)

    def render(self, template_name, **context):
        template = self.jinja.get_template(template_name)
        return jinja2.Markup(template.render(context))

    def dispatch_request(self, request):
        try:
            endpoint, values = request.url_adapter.match()
            return endpoint(request, **values)
        except NotFound as e:
            return self.views['not_found'](request)
        except HttpException as e:
            return e

    @Request.application
    def wsgi_app(self, request):
        request.app = self

        request.max_content_length = 16 * 1024 * 1024
        request.max_form_memory_size = 2 * 1024 * 1024

        cookie_name = self.settings.cookie_name
        sid = request.cookies.get(cookie_name, '')
        request.session = self.session_store.get(sid)

        request.db_session = self.DbSession()

        request.url_adapter = self.url_map.bind_to_environ(request.environ)

        def build_url(view_name, *args, **kwargs):
            endpoint = self.views[view_name]
            return request.url_adapter.build(endpoint, *args, **kwargs)
        request.build_url = build_url

        response = self.dispatch_request(request)

        if request.session.should_save:
            self.session_store.save(request.session)
            response.set_cookie(cookie_name, request.session.sid)
        elif sid and request.session.new and hasattr(response, 'delete_cookie'):
            response.delete_cookie(cookie_name)

        request.db_session.close()

        return response

    def __call__(self, *args):
        return self.wsgi_app(*args)
开发者ID:fmfi-svt,项目名称:predmety,代码行数:78,代码来源:app.py

示例10: config

# 需要导入模块: from werkzeug.contrib.sessions import FilesystemSessionStore [as 别名]
# 或者: from werkzeug.contrib.sessions.FilesystemSessionStore import save [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)
开发者ID:pombredanne,项目名称:glim,代码行数:104,代码来源:dispatch.py


注:本文中的werkzeug.contrib.sessions.FilesystemSessionStore.save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。