forked from scrapy/scrapy
/
interfaces.py
52 lines (35 loc) · 1.63 KB
/
interfaces.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from zope.interface import Interface
class ISpiderQueue(Interface):
def from_settings(settings):
"""Class method to instantiate from settings"""
def add(name, **spider_args):
"""Add a spider to the queue given its name a some spider arguments.
This method can return a deferred. """
def pop():
"""Pop the next mesasge from the queue. The messages is a dict
conaining a key 'name' with the spider name and other keys as spider
attributes.
This method can return a deferred. """
def list():
"""Return a list with the messages in the queue. Each message is a dict
which must have a 'name' key (with the spider name), and other optional
keys that will be used as spider arguments, to create the spider.
This method can return a deferred. """
def count():
"""Return the number of spiders in the queue.
This method can return a deferred. """
def clear():
"""Clear the queue.
This method can return a deferred. """
class ISpiderManager(Interface):
def from_settings(settings):
"""Class method to instantiate from settings"""
def create(spider_name, **spider_args):
"""Returns a new Spider instance for the given spider name, and using
the given spider arguments. If the spider name is not found, it must
raise a KeyError."""
def list():
"""Return a list with the names of all spiders available in the
project"""
def find_by_request(request):
"""Returns the list of spiders names that can handle the given request"""