예제 #1
0
    def __init__(self, sessid, callback=None, **data):
        self.sessid = sessid
        self._redis = RedisPool(settings.storage_socket)

        if callback and data:
            data['__callback__'] = [callback.__module__, callback.__name__]
            self._redis.set(sessid, json.dumps(data))
            del data['__callback__']
            self._redis.expire(self.sessid, settings.session_expire)
            self._callback = callback
            self._data = data
        else:
            data = self._redis.get(self.sessid)
            if not data:
                self._callback = None
                self._data = None
                return
            data = json.loads(data)
            if '__callback__' in data:
                mod, fn = tuple(data['__callback__'])
                mod = __import__(mod, globals(), locals(), [fn], -1)
                self._callback = getattr(mod, fn)
                del data['__callback__']
            else:
                self._callback = None
            self._data = data
예제 #2
0
    def __init__(self, sessid, callback=None, **data):
        self.sessid = sessid
        self._redis = RedisPool(settings.storage_socket)

        if callback and data:
            data['__callback__'] = [callback.__module__, callback.__name__]
            self._redis.set(sessid, json.dumps(data))
            del data['__callback__']
            self._redis.expire(self.sessid, settings.session_expire)
            self._callback = callback
            self._data = data
        else:
            data = self._redis.get(self.sessid)
            if not data:
                self._callback = None
                self._data = None
                return
            data = json.loads(data)
            if '__callback__' in data:
                mod, fn = tuple(data['__callback__'])
                mod = __import__(mod, globals(), locals(), [fn], -1)
                self._callback = getattr(mod, fn)
                del data['__callback__']
            else:
                self._callback = None
            self._data = data
예제 #3
0
class _Session(object):
    def __init__(self, sessid, callback=None, **data):
        self.sessid = sessid
        self._redis = RedisPool(settings.storage_socket)

        if callback and data:
            data['__callback__'] = [callback.__module__, callback.__name__]
            self._redis.set(sessid, json.dumps(data))
            del data['__callback__']
            self._redis.expire(self.sessid, settings.session_expire)
            self._callback = callback
            self._data = data
        else:
            data = self._redis.get(self.sessid)
            if not data:
                self._callback = None
                self._data = None
                return
            data = json.loads(data)
            if '__callback__' in data:
                mod, fn = tuple(data['__callback__'])
                mod = __import__(mod, globals(), locals(), [fn], -1)
                self._callback = getattr(mod, fn)
                del data['__callback__']
            else:
                self._callback = None
            self._data = data

    def __call__(self, data):
        if self._callback:
            return self._callback(data)
        raise SessionCallError

    def __getitem__(self, key):
        return self._data[key]

    def data(self):
        return self._data

    def destroy(self):
        self._redis.delete(self.sessid)
예제 #4
0
class _Session(object):
    def __init__(self, sessid, callback=None, **data):
        self.sessid = sessid
        self._redis = RedisPool(settings.storage_socket)

        if callback and data:
            data['__callback__'] = [callback.__module__, callback.__name__]
            self._redis.set(sessid, json.dumps(data))
            del data['__callback__']
            self._redis.expire(self.sessid, settings.session_expire)
            self._callback = callback
            self._data = data
        else:
            data = self._redis.get(self.sessid)
            if not data:
                self._callback = None
                self._data = None
                return
            data = json.loads(data)
            if '__callback__' in data:
                mod, fn = tuple(data['__callback__'])
                mod = __import__(mod, globals(), locals(), [fn], -1)
                self._callback = getattr(mod, fn)
                del data['__callback__']
            else:
                self._callback = None
            self._data = data

    def __call__(self, data):
        if self._callback:
            return self._callback(data)
        raise SessionCallError

    def __getitem__(self, key):
        return self._data[key]

    def data(self):
        return self._data

    def destroy(self):
        self._redis.delete(self.sessid)