'Consume amount from quota bucket.
Args:
bucket: quota bucket as string.
amount: amount to consume.
consume_some: specifies behavior in case of not enough quota. If False,
the method will leave quota intact and return 0. If True, will try to
consume as much as possible.
Returns:
Amount of quota consumed.'

def consume(self, bucket, amount, consume_some=False):

    new_quota = self.memcache_client.decr(bucket, delta=amount, initial_value=_OFFSET, namespace=_QUOTA_NAMESPACE)
    if (new_quota >= _OFFSET):
        return amount
    if (consume_some and ((_OFFSET - new_quota) < amount)):
        self.put(bucket, (_OFFSET - new_quota))
        return (amount - (_OFFSET - new_quota))
    else:
        self.put(bucket, amount)
        return 0
