def allow_resource_access(self, resource_name, when=None):
<EOL>period_strs = self.get_period_strs(when)<EOL>pool = self.pool_for_resource(resource_name)<EOL>limits = self.get_limits_for_pool(pool)<EOL>resource_size = self.resource_size(resource_name)<EOL>for period, period_str in period_strs.items():<EOL><INDENT>aggregate_size = self.cache.incrbyfloat(<EOL>"<STR_LIT>" % (period_str, pool), resource_size)<EOL>log.debug("<STR_LIT>",<EOL>resource_name, period_str, pool, aggregate_size)<EOL><DEDENT>del period_str<EOL>undo_actions = []<EOL>for period, period_str in period_strs.items():<EOL><INDENT>limit = limits.get(period)<EOL>key = "<STR_LIT>" % (period_str, pool)<EOL>result = self.cache.incrbyfloat(key, resource_size)<EOL>undo_actions.append((key, -resource_size))<EOL>log.debug("<STR_LIT>",<EOL>resource_name, period_str, pool, result)<EOL>if limit and result > limit:<EOL><INDENT>log.debug("<STR_LIT>"<EOL>"<STR_LIT>", resource_name,<EOL>period, limit, result)<EOL>for key, incr in undo_actions:<EOL><INDENT>self.cache.incrbyfloat(key, incr)<EOL><DEDENT>return False<EOL><DEDENT><DEDENT>log.debug("<STR_LIT>",<EOL>resource_name)<EOL>return True<EOL>
meterer.allow_resource_access(resource_name, when=None) -> bool

Indicate whether access to the specified resource should be allowed.
This checks the limit(s) for the pool associated with the resource and
records the attempt. If the attempt falls below the limit, the allowance
is also recorded and True is returned. Otherwise, False is returned.

If when is None (the default), it defaults to the current time. This is
used for testing.