Esempio n. 1
0
File: jwt.py Progetto: yuiitsu/DSSP
    def verify(access_token):
        """
        JWT验签
        :param access_token:
        :return:
        """
        if access_token:
            try:
                header, p, signature = access_token.split('.')
                p = p + '=' * (-len(p) % 4)
                p = base64.decodebytes(p.encode('utf-8')).decode('utf-8')
                p_dict = json.loads(p)
            except Exception as e:
                logger.exception(e)
                return False

            create_time = p_dict['iat']
            expires_in = p_dict['exp']
            time_now = int(dateUtils.timestamps_now())
            if create_time + expires_in < time_now:
                return False

            encoded = JWT.encode(p_dict)
            if encoded != access_token:
                return False

            return p_dict

        return False
Esempio n. 2
0
    async def hmget(self, key, field):
        r = None
        result = False
        try:
            r = await self.get_connection()
            result = await r.hmget(key, field)
        except Exception as e:
            logger.exception(e)
        finally:
            if r:
                r.close()
                await r.wait_closed()

        return result
Esempio n. 3
0
    async def llen(self, key):
        r = None
        result = None
        try:
            r = await self.get_connection()
            result = await r.llen(key)
        except Exception as e:
            logger.exception(e)
        finally:
            if r:
                r.close()
                await r.wait_closed()

        return result
Esempio n. 4
0
    async def lrange(self, key, start, end):
        r = None
        result = None
        try:
            r = await self.get_connection()
            result = await r.lrange(key, start, end)
        except Exception as e:
            logger.exception(e)
        finally:
            if r:
                r.close()
                await r.wait_closed()

        return result
Esempio n. 5
0
    async def delete(self, *key):
        r = None
        result = False
        try:
            r = await self.get_connection()
            result = await r.delete(*key)
        except Exception as e:
            logger.exception(e)
        finally:
            if r:
                r.close()
                await r.wait_closed()

        return result
Esempio n. 6
0
    async def rpush(self, key, value, *args):
        r = None
        result = None
        try:
            r = await self.get_connection()
            result = await r.rpush(key, value, *args)
        except Exception as e:
            logger.exception(e)
        finally:
            if r:
                r.close()
                await r.wait_closed()

        return result
Esempio n. 7
0
    async def decr(self, key, amount=1):
        r = None
        result = None
        try:
            r = await self.get_connection()
            result = await r.decr(key, amount)
        except Exception as e:
            logger.exception(e)
        finally:
            if r:
                r.close()
                await r.wait_closed()

        return result
Esempio n. 8
0
    async def expire(self, key, second=0):
        r = None
        result = None
        try:
            r = await self.get_connection()
            result = await r.expire(key, int(second))
        except Exception as e:
            logger.exception(e)
        finally:
            if r:
                r.close()
                await r.wait_closed()

        return result
Esempio n. 9
0
    async def hincrby(self, key, field, increment=1):
        r = None
        result = False
        try:
            r = await self.get_connection()
            result = await r.hincrby(key, field, increment)
        except Exception as e:
            logger.exception(e)
        finally:
            if r:
                r.close()
                await r.wait_closed()

        return result
Esempio n. 10
0
    async def ttl(self, key):
        r = None
        result = -2
        try:
            r = await self.get_connection()
            result = await r.ttl(key)
            result = -1 if result is None else result
        except Exception as e:
            logger.exception(e)
        finally:
            if r:
                r.close()
                await r.wait_closed()

        return result
Esempio n. 11
0
    async def hmset(self, key, value, second=0):
        r = None
        result = False
        try:
            r = await self.get_connection()
            pipe = r.pipeline()
            pipe.hmset_dict(key, value)
            if second > 0:
                pipe.expire(key, int(second))

            result = await pipe.execute()
        except Exception as e:
            logger.exception(e)
        finally:
            if r:
                r.close()
                await r.wait_closed()

        return result
Esempio n. 12
0
async def save_task_error(task, e):
    """
    保存失败任务信息
    :param task: 任务数据
    :param e: 异常信息
    :return:
    """
    try:
        task = json.loads(task) if isinstance(task, str) else task
        trace = ''.join(traceback.format_exception(*sys.exc_info())[-2:])
        task = json.dumps(
            {
                'task': task,
                'e': trace,
                'time': date_utils.time_now()
            },
            cls=CJsonEncoder)
        await redis.lpush(failed_queue, task)
    except Exception as e:
        logger.exception(e)
        raise
Esempio n. 13
0
 def get(self, filename, section, option):
     try:
         return self.data[filename][section][option]
     except Exception as e:
         logs.exception(e)
         return ""