當前位置: 首頁>>代碼示例>>Python>>正文


Python sessions.FilesystemSessionStore類代碼示例

本文整理匯總了Python中werkzeug.contrib.sessions.FilesystemSessionStore的典型用法代碼示例。如果您正苦於以下問題:Python FilesystemSessionStore類的具體用法?Python FilesystemSessionStore怎麽用?Python FilesystemSessionStore使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了FilesystemSessionStore類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_non_urandom

def test_non_urandom(tmpdir):
    urandom = os.urandom
    del os.urandom
    try:
        store = FilesystemSessionStore(str(tmpdir))
        store.new()
    finally:
        os.urandom = urandom
開發者ID:Khan,項目名稱:frankenserver,代碼行數:8,代碼來源:test_sessions.py

示例2: after_request

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,代碼行數:8,代碼來源:wsgiserver.py

示例3: test_non_urandom

 def test_non_urandom(self):
     urandom = os.urandom
     del os.urandom
     try:
         store = FilesystemSessionStore(self.session_folder)
         store.new()
     finally:
         os.urandom = urandom
開發者ID:BaxterStockman,項目名稱:WorkoutBuddy,代碼行數:8,代碼來源:sessions.py

示例4: before_request

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()
開發者ID:riccardo-forina,項目名稱:Roguehell,代碼行數:8,代碼來源:wsgiserver.py

示例5: WSGIApplication

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()
開發者ID:dalinhuang,項目名稱:gybprojects,代碼行數:57,代碼來源:__init__.py

示例6: test_fs_session_lising

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,代碼行數:10,代碼來源:test_sessions.py

示例7: test_fs_session_lising

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,代碼行數:11,代碼來源:test_sessions.py

示例8: after_request

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,代碼行數:17,代碼來源:shotomatic.py

示例9: test_renewing_fs_session

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,代碼行數:7,代碼來源:test_sessions.py

示例10: test_renewing_fs_session

 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,代碼行數:7,代碼來源:sessions.py

示例11: before_request

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
開發者ID:aljoscha,項目名稱:shot-o-matic,代碼行數:18,代碼來源:shotomatic.py

示例12: __init__

    def __init__(self, urls={}, config={}):
        self.config = config

        try:
            self.session_store = FilesystemSessionStore(self.config["sessions"]["path"])
        except:
            self.session_store = None

        ruleset = self.flatten_urls(urls)
        rule_map = []
        for url, rule in ruleset.items():
            rule_map.append(Rule(url, endpoint=rule))

        self.url_map = Map(rule_map)
開發者ID:rubik,項目名稱:glim,代碼行數:14,代碼來源:dispatch.py

示例13: on_session_id

    def on_session_id(self, session_id):
        """ sockectio_manage can call all the event only if the session is
        validate"""
        path = session_path()
        session_store = FilesystemSessionStore(path)
        sid = self.request.cookies.get('sid')
        session = None
        self.uid = None
        if sid:
            session = session_store.get(sid)

        if session and session_id:
            session = session.get(session_id)
        else:
            session = None

        if not session:
            return

        session.assert_valid()
        self.context = session.context
        self.uid = session._uid
        self.database = session._db
        self.lift_acl_restrictions()
開發者ID:aaltinisik,項目名稱:customaddons,代碼行數:24,代碼來源:namespace.py

示例14: __init__

    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)
開發者ID:fmfi-svt,項目名稱:predmety,代碼行數:24,代碼來源:app.py

示例15: config

class Glim:

    """

    The class that holds the wsgi app of glim framework.

    Attributes
    ----------
      config (dict): The 'glim' key of app.config.<env>.
      session_store (werkzeug.contrib.sessions.FilesystemSessionStore):
        The session store in case of session usage.
      url_map (werkzeug.routing.Map): The url map of wsgi app.

    Usage
    -----
      app = Glim(urls, config)

      # start the web server
      run_simple(host, int(port), app, use_debugger=True, use_reloader=True)

    """

    def __init__(self, urls={}, config={}):
        self.config = config

        try:
            self.session_store = FilesystemSessionStore(
                self.config['sessions']['path']
            )
        except:
            self.session_store = None

        ruleset = self.flatten_urls(urls)
        rule_map = []
        for url, rule in ruleset.items():
            rule_map.append(Rule(url, endpoint=rule))

        self.url_map = Map(rule_map)

    def flatten_urls(self, urls, current_key="", ruleset={}):
        """

        Function flatten urls for route grouping feature of glim. Thanks
        for the stackoverflow guy!

        Args
        ----
          urls (dict): a dict of url definitions.
          current_key (unknown type): a dict or a string marking the
            current key that is used for recursive calls.
          ruleset (dict): the ruleset that is eventually returned to
            dispatcher.

        Returns
        -------
          ruleset (dict): the ruleset to be bound.

        """
        for key in urls:
            # If the value is of type `dict`, then recurse with the
            # value
            if isinstance(urls[key], dict):
                self.flatten_urls(urls[key], current_key + key)
            # Else if the value is type of list, meaning it is a filter
            elif isinstance(urls[key], (list, tuple)):
                k = ','.join(urls[key])
                ruleset[current_key + key] = k
            else:
                ruleset[current_key + key] = urls[key]

        return ruleset

    def dispatch_request(self, request):
        """

        Function dispatches the request. It also handles route
        filtering.

        Args
        ----
          request (werkzeug.wrappers.Request): the request
            object.

        Returns
        -------
          response (werkzeug.wrappers.Response): the response
            object.

        """
        adapter = self.url_map.bind_to_environ(request.environ)

        try:

            endpoint, values = adapter.match()
            mcontroller = import_module('app.controllers')

            # detect filters
            filters = endpoint.split(',')
            endpoint_pieces = filters[-1].split('.')

#.........這裏部分代碼省略.........
開發者ID:pombredanne,項目名稱:glim,代碼行數:101,代碼來源:dispatch.py


注:本文中的werkzeug.contrib.sessions.FilesystemSessionStore類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。