MCPcopy Create free account
hub / github.com/bslatkin/effectivepython / deduct

Function deduct

example_code/item_059.py:77–84  ·  view source on GitHub ↗
(bucket, amount)

Source from the content-addressed store, hash-verified

75
76print("Example 3")
77def deduct(bucket, amount):
78 now = datetime.now()
79 if (now - bucket.reset_time) > bucket.period_delta:
80 return False # Bucket hasn't been filled this period
81 if bucket.quota - amount < 0:
82 return False # Bucket was filled, but not enough
83 bucket.quota -= amount
84 return True # Bucket had enough, quota consumed
85
86
87print("Example 4")

Callers 1

item_059.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected