def consume(self, bucket, amount, consume_some=False):
    """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.
    """
    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:
      # we still can consume some
      self.put(bucket, _OFFSET - new_quota)
      return amount - (_OFFSET - new_quota)
    else:
      self.put(bucket, amount)
      return 0
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.
    
mapreduce/quota.py