# Path: xpaw/queue.py
# class FifoQueue:
#     def __init__(self):
#         self._queue = deque()
#         self._semaphore = Semaphore(0)
# 
#     def __len__(self):
#         return len(self._queue)
# 
#     async def push(self, request):
#         self._queue.append(request)
#         self._semaphore.release()
# 
#     async def pop(self):
#         await self._semaphore.acquire()
#         return self._queue.popleft()
# 
# class LifoQueue(FifoQueue):
#     async def pop(self):
#         await self._semaphore.acquire()
#         return self._queue.pop()
# 
# class PriorityQueue:
#     def __init__(self):
#         self._queue = []
#         self._semaphore = Semaphore(0)
# 
#     def __len__(self):
#         return len(self._queue)
# 
#     async def push(self, request):
#         heappush(self._queue, _PriorityQueueItem(request))
#         self._semaphore.release()
# 
#     async def pop(self):
#         await self._semaphore.acquire()
#         item = heappop(self._queue)
#         return item.request
# 
# Path: xpaw/http.py
# class HttpRequest:
#     def __init__(self, url, method="GET", body=None, params=None, headers=None, proxy=None,
#                  timeout=20, verify_ssl=False, allow_redirects=True, auth=None, proxy_auth=None,
#                  priority=None, dont_filter=False, callback=None, errback=None, meta=None,
#                  render=None):
#         """
#         Construct an HTTP request.
#         """
#         self.url = make_url(url, params)
#         self.method = method
#         self.body = body
#         self.headers = headers
#         self.proxy = proxy
#         self.timeout = timeout
#         self.verify_ssl = verify_ssl
#         self.allow_redirects = allow_redirects
#         self.auth = auth
#         self.proxy_auth = proxy_auth
#         self.priority = priority
#         self.dont_filter = dont_filter
#         self.callback = callback
#         self.errback = errback
#         self._meta = dict(meta) if meta else {}
#         self.render = render
# 
#     def __str__(self):
#         return '<{}, {}>'.format(self.method, self.url)
# 
#     __repr__ = __str__
# 
#     @property
#     def meta(self):
#         return self._meta
# 
#     def copy(self):
#         return self.replace()
# 
#     def replace(self, **kwargs):
#         for i in ["url", "method", "body", "headers", "proxy",
#                   "timeout", "verify_ssl", "allow_redirects", "auth", "proxy_auth",
#                   "priority", "dont_filter", "callback", "errback", "meta",
#                   "render"]:
#             kwargs.setdefault(i, getattr(self, i))
#         return type(self)(**kwargs)
# 
#     def to_dict(self):
#         callback = self.callback
#         if inspect.ismethod(callback):
#             callback = callback.__name__
#         errback = self.errback
#         if inspect.ismethod(errback):
#             errback = errback.__name__
#         d = {
#             'url': self.url,
#             'method': self.method,
#             'body': self.body,
#             'headers': self.headers,
#             'proxy': self.proxy,
#             'timeout': self.timeout,
#             'verify_ssl': self.verify_ssl,
#             'allow_redirects': self.allow_redirects,
#             'auth': self.auth,
#             'proxy_auth': self.proxy_auth,
#             'priority': self.priority,
#             'dont_filter': self.dont_filter,
#             'callback': callback,
#             'errback': errback,
#             'meta': self.meta,
#             'render': self.render
#         }
#         return d
# 
#     @classmethod
#     def from_dict(cls, d):
#         return cls(**d)


import asyncio
import pytest
import async_timeout
from xpaw.queue import FifoQueue, LifoQueue, PriorityQueue
from xpaw.http import HttpRequest
        await q.push(o)
    for i in range(len(obj_list)):
        assert await q.pop() == obj_list[i]
    with pytest.raises(asyncio.TimeoutError):
        with async_timeout.timeout(0.1):
            await q.pop()


@pytest.mark.asyncio
async def test_lifo_queue():
    q = LifoQueue()
    with pytest.raises(asyncio.TimeoutError):
        with async_timeout.timeout(0.1):
            await q.pop()
    obj_list = [HttpRequest('1'), HttpRequest('2'), HttpRequest('3')]
    for o in obj_list:
        await q.push(o)
    for i in range(len(obj_list)):
        assert await q.pop() == obj_list[len(obj_list) - i - 1]
    with pytest.raises(asyncio.TimeoutError):
        with async_timeout.timeout(0.1):
            await q.pop()


@pytest.mark.asyncio
async def test_priority_queue():
    item1_1 = HttpRequest('1_1', priority=1)
    item1_2 = HttpRequest('1_2', priority=1)
    item2_1 = HttpRequest('2_1', priority=2)
    item2_2 = HttpRequest('2_2', priority=2)

# Path: xpaw/queue.py
# class FifoQueue:
#     def __init__(self):
#         self._queue = deque()
#         self._semaphore = Semaphore(0)
# 
#     def __len__(self):
#         return len(self._queue)
# 
#     async def push(self, request):
#         self._queue.append(request)
#         self._semaphore.release()
# 
#     async def pop(self):
#         await self._semaphore.acquire()
#         return self._queue.popleft()
# 
# class LifoQueue(FifoQueue):
#     async def pop(self):
#         await self._semaphore.acquire()
#         return self._queue.pop()
# 
# class PriorityQueue:
#     def __init__(self):
#         self._queue = []
#         self._semaphore = Semaphore(0)
# 
#     def __len__(self):
#         return len(self._queue)
# 
#     async def push(self, request):
#         heappush(self._queue, _PriorityQueueItem(request))
#         self._semaphore.release()
# 
#     async def pop(self):
#         await self._semaphore.acquire()
#         item = heappop(self._queue)
#         return item.request
# 
# Path: xpaw/http.py
# class HttpRequest:
#     def __init__(self, url, method="GET", body=None, params=None, headers=None, proxy=None,
#                  timeout=20, verify_ssl=False, allow_redirects=True, auth=None, proxy_auth=None,
#                  priority=None, dont_filter=False, callback=None, errback=None, meta=None,
#                  render=None):
#         """
#         Construct an HTTP request.
#         """
#         self.url = make_url(url, params)
#         self.method = method
#         self.body = body
#         self.headers = headers
#         self.proxy = proxy
#         self.timeout = timeout
#         self.verify_ssl = verify_ssl
#         self.allow_redirects = allow_redirects
#         self.auth = auth
#         self.proxy_auth = proxy_auth
#         self.priority = priority
#         self.dont_filter = dont_filter
#         self.callback = callback
#         self.errback = errback
#         self._meta = dict(meta) if meta else {}
#         self.render = render
# 
#     def __str__(self):
#         return '<{}, {}>'.format(self.method, self.url)
# 
#     __repr__ = __str__
# 
#     @property
#     def meta(self):
#         return self._meta
# 
#     def copy(self):
#         return self.replace()
# 
#     def replace(self, **kwargs):
#         for i in ["url", "method", "body", "headers", "proxy",
#                   "timeout", "verify_ssl", "allow_redirects", "auth", "proxy_auth",
#                   "priority", "dont_filter", "callback", "errback", "meta",
#                   "render"]:
#             kwargs.setdefault(i, getattr(self, i))
#         return type(self)(**kwargs)
# 
#     def to_dict(self):
#         callback = self.callback
#         if inspect.ismethod(callback):
#             callback = callback.__name__
#         errback = self.errback
#         if inspect.ismethod(errback):
#             errback = errback.__name__
#         d = {
#             'url': self.url,
#             'method': self.method,
#             'body': self.body,
#             'headers': self.headers,
#             'proxy': self.proxy,
#             'timeout': self.timeout,
#             'verify_ssl': self.verify_ssl,
#             'allow_redirects': self.allow_redirects,
#             'auth': self.auth,
#             'proxy_auth': self.proxy_auth,
#             'priority': self.priority,
#             'dont_filter': self.dont_filter,
#             'callback': callback,
#             'errback': errback,
#             'meta': self.meta,
#             'render': self.render
#         }
#         return d
# 
#     @classmethod
#     def from_dict(cls, d):
#         return cls(**d)


# Path: tests/test_queue.py
import asyncio
import pytest
import async_timeout
from xpaw.queue import FifoQueue, LifoQueue, PriorityQueue
from xpaw.http import HttpRequest

        await q.push(o)
    for i in range(len(obj_list)):
        assert await q.pop() == obj_list[i]
    with pytest.raises(asyncio.TimeoutError):
        with async_timeout.timeout(0.1):
            await q.pop()


@pytest.mark.asyncio
async def test_lifo_queue():
    q = LifoQueue()
    with pytest.raises(asyncio.TimeoutError):
        with async_timeout.timeout(0.1):
            await q.pop()
    obj_list = [HttpRequest('1'), HttpRequest('2'), HttpRequest('3')]
    for o in obj_list:
        await q.push(o)
    for i in range(len(obj_list)):
        assert await q.pop() == obj_list[len(obj_list) - i - 1]
    with pytest.raises(asyncio.TimeoutError):
        with async_timeout.timeout(0.1):
            await q.pop()


@pytest.mark.asyncio
async def test_priority_queue():
    item1_1 = HttpRequest('1_1', priority=1)
    item1_2 = HttpRequest('1_2', priority=1)
    item2_1 = HttpRequest('2_1', priority=2)
    item2_2 = HttpRequest('2_2', priority=2)

    item3_1 = HttpRequest('3_1', priority=3)