Example #1
0
File: site.py Project: CMGS/ymir
def check_block(sid, ip):
    if rds.get(config.BLOCK_PREFIX.format(sid=sid, ip=ip)):
        return True
    elif Block.select().where(Block.sid == sid, Block.ip == ip).first():
        rds.set(config.BLOCK_PREFIX.format(sid=sid, ip=ip), 1)
        return True
    return False
Example #2
0
File: test_up.py Project: CMGS/ymir
    def test_set_up_counts(self):
        r = range(15, 17)
        self.send_request(
            path = self.path, method = 'PUT', data = json.dumps({'cids': r})
        )

        self.assertEqual(falcon.HTTP_200, self.mock.status)
        for i in r:
            k = config.COMMENT_UP_PREFIX.format(sid = self.site.id, cid = i)
            self.assertEqual(int(rds.get(k)), 1)
Example #3
0
File: heat.py Project: CMGS/ymir
def req_rate(req, resp, params):
    ip = req.get_header('X-Real-IP')
    if not ip:
        return
    key = config.HEAT_KEY.format(ip = ip)
    current = rds.get(key)
    if current and int(current) > config.HEAT_MAX:
        raise falcon.HTTPForbidden(config.HTTP_403, 'ip %s overheat' % ip)

    if not current:
        rds.incr(key)
        rds.expire(key, config.HEAT_TIME)
    else:
        rds.incr(key)
Example #4
0
File: comment.py Project: CMGS/ymir
def get_comments_by_tid(site, tid, expand, page, num):
    total = config.COMMENT_COUNT_PREFIX.format(sid = site.id, tid = tid)
    # We don't care the count, just notify renew page cache
    count = rds.get(total) or 0
    return get_comments(site, count, page, num, tid = tid, expand = expand)