コード例 #1
0
ファイル: basehandler.py プロジェクト: gramener/gramex
 def setup_session(cls, session_conf):
     '''handler.session returns the session object. It is saved on finish.'''
     if session_conf is None:
         return
     key = store_type, store_path = session_conf.get('type'), session_conf.get('path')
     if key not in session_store_cache:
         session_store_cache[key] = get_store(
             type=store_type,
             path=store_path,
             flush=session_conf.get('flush'),
             purge=session_conf.get('purge'),
             purge_keys=cls._purge_keys
         )
     cls._session_store = session_store_cache[key]
     cls.session = property(cls.get_session)
     cls._session_expiry = session_conf.get('expiry')
     cls._session_cookie_id = session_conf.get('cookie', 'sid')
     cls._session_cookie = {
         key: session_conf[key] for key in ('domain', 'httponly', 'secure')
         if key in session_conf
     }
     cls._on_init_methods.append(cls.override_user)
     cls._on_finish_methods.append(cls.set_last_visited)
     # Ensure that session is saved AFTER we set last visited
     cls._on_finish_methods.append(cls.save_session)
コード例 #2
0
    def __init__(self, path, keys=None, **kwargs):
        if keys is None:
            keys = {}
        for cat in ('file', 'delete', 'save'):
            keys.setdefault(cat, [cat])
            if not isinstance(keys[cat], list):
                if isinstance(keys[cat], (str, bytes)):
                    keys[cat] = [keys[cat]]
                else:
                    app_log.error('FileUpload: cat: %r must be a list or str',
                                  keys[cat])
        self.keys = keys
        self.path = os.path.abspath(path)
        if not os.path.exists(self.path):
            os.makedirs(self.path)

        # store default: sqlite .meta.db
        store_kwargs = kwargs.get('store', {
            'type': 'sqlite',
            'path': os.path.join(self.path, '.meta.db')
        })
        if self.path not in self.stores:
            self.stores[self.path] = get_store(**store_kwargs)
        self.store = self.stores[self.path]
        old_store_path = os.path.abspath(os.path.join(self.path, '.meta.h5'))
        store_path = os.path.abspath(getattr(self.store, 'path', None))
        # migration: if type is not hdf5 but .meta.h5 exists, update store and remove
        if (os.path.exists(old_store_path) and store_path != old_store_path):
            self._migrate_h5(old_store_path)

        if 'file' not in keys:
            keys['file'] = ['file']
        self.keys['file'] = keys['file'] if isinstance(
            keys['file'], list) else [keys['file']]
コード例 #3
0
ファイル: basehandler.py プロジェクト: naveengattu/gramex
 def setup_session(cls, session_conf):
     '''handler.session returns the session object. It is saved on finish.'''
     if session_conf is None:
         return
     key = store_type, store_path = session_conf.get(
         'type'), session_conf.get('path')
     if key not in session_store_cache:
         session_store_cache[key] = get_store(
             type=store_type,
             path=store_path,
             flush=session_conf.get('flush'),
             purge=session_conf.get('purge'),
             purge_keys=cls._purge_keys)
     cls._session_store = session_store_cache[key]
     cls.session = property(cls.get_session)
     cls._session_expiry = session_conf.get('expiry')
     cls._on_finish_methods.append(cls.save_session)
     cls._on_init_methods.append(cls.override_user)
     cls._on_finish_methods.append(cls.set_last_visited)