

def handle_ratelimit(self, req, account_name, container_name, obj_name):
    '\n        Performs rate limiting and account white/black listing.  Sleeps\n        if necessary. If self.memcache_client is not set, immediately returns\n        None.\n\n        :param account_name: account name from path\n        :param container_name: container name from path\n        :param obj_name: object name from path\n        '
    if (not self.memcache_client):
        return None
    try:
        account_info = get_account_info(req.environ, self.app, swift_source='RL')
        account_global_ratelimit = account_info.get('sysmeta', {
            
        }).get('global-write-ratelimit')
    except ValueError:
        account_global_ratelimit = None
    if ((account_name in self.ratelimit_whitelist) or (account_global_ratelimit == 'WHITELIST')):
        return None
    if ((account_name in self.ratelimit_blacklist) or (account_global_ratelimit == 'BLACKLIST')):
        self.logger.error(_('Returning 497 because of blacklisting: %s'), account_name)
        eventlet.sleep(self.BLACK_LIST_SLEEP)
        return Response(status='497 Blacklisted', body='Your account has been blacklisted', request=req)
    for (key, max_rate) in self.get_ratelimitable_key_tuples(req, account_name, container_name=container_name, obj_name=obj_name, global_ratelimit=account_global_ratelimit):
        try:
            need_to_sleep = self._get_sleep_time(key, max_rate)
            if (self.log_sleep_time_seconds and (need_to_sleep > self.log_sleep_time_seconds)):
                self.logger.warning(_('Ratelimit sleep log: %(sleep)s for %(account)s/%(container)s/%(object)s'), {
                    'sleep': need_to_sleep,
                    'account': account_name,
                    'container': container_name,
                    'object': obj_name,
                })
            if (need_to_sleep > 0):
                eventlet.sleep(need_to_sleep)
        except MaxSleepTimeHitError as e:
            self.logger.error(_('Returning 498 for %(meth)s to %(acc)s/%(cont)s/%(obj)s . Ratelimit (Max Sleep) %(e)s'), {
                'meth': req.method,
                'acc': account_name,
                'cont': container_name,
                'obj': obj_name,
                'e': str(e),
            })
            error_resp = Response(status='498 Rate Limited', body='Slow down', request=req)
            return error_resp
    return None

dataset/ETHPy150Open openstack/swift/swift/common/middleware/ratelimit.py RateLimitMiddleware.handle_ratelimit/original