# Path: xpaw/errors.py
# class NotEnabled(Exception):
#     """
#     Not enabled.
#     """


import logging
import asyncio
from xpaw.errors import NotEnabled
# coding=utf-8



log = logging.getLogger(__name__)

__all__ = ['SpeedLimitMiddleware']


class SpeedLimitMiddleware:
    def __init__(self, rate=1, burst=1):
        self._rate = rate
        self._burst = burst
        if self._rate <= 0:
            raise ValueError("rate must be greater than 0")
        if self._burst <= 0:
            raise ValueError('burst must be greater than 0')
        self._interval = 1.0 / self._rate
        self._bucket = self._burst
        self._semaphore = asyncio.Semaphore(self._burst)
        self._update_future = None

    def __repr__(self):
        cls_name = self.__class__.__name__
        return '{}(speed_limit_rate={}, speed_limit_burst={})'.format(cls_name, repr(self._rate), repr(self._burst))

    @classmethod
    def from_crawler(cls, crawler):
        config = crawler.config
        if config['speed_limit'] is None:

# Path: xpaw/errors.py
# class NotEnabled(Exception):
#     """
#     Not enabled.
#     """


# Path: xpaw/extensions/speed_limit.py
import logging
import asyncio
from xpaw.errors import NotEnabled

# coding=utf-8



log = logging.getLogger(__name__)

__all__ = ['SpeedLimitMiddleware']


class SpeedLimitMiddleware:
    def __init__(self, rate=1, burst=1):
        self._rate = rate
        self._burst = burst
        if self._rate <= 0:
            raise ValueError("rate must be greater than 0")
        if self._burst <= 0:
            raise ValueError('burst must be greater than 0')
        self._interval = 1.0 / self._rate
        self._bucket = self._burst
        self._semaphore = asyncio.Semaphore(self._burst)
        self._update_future = None

    def __repr__(self):
        cls_name = self.__class__.__name__
        return '{}(speed_limit_rate={}, speed_limit_burst={})'.format(cls_name, repr(self._rate), repr(self._burst))

    @classmethod
    def from_crawler(cls, crawler):
        config = crawler.config
        if config['speed_limit'] is None:

            raise NotEnabled