Scrapy, a fast high-level web crawling & scraping framework for Python.
moved log method to BaseSpider, moved adapt_feed doc to docstring
Pablo Hoffman5ccd4df0cd75
diff --git a/scrapy/trunk/scrapy/contrib/spiders.py b/scrapy/trunk/scrapy/contrib/spiders.pyindex 720ef7f07..722306db7 100644--- a/scrapy/trunk/scrapy/contrib/spiders.py+++ b/scrapy/trunk/scrapy/contrib/spiders.py@@ -3,7 +3,6 @@ This module contains some basic spiders for scraping websites (CrawlSpider)and XML feeds (XMLFeedSpider)."""-from scrapy import logfrom scrapy.conf import settingsfrom scrapy.http import Requestfrom scrapy.spider import BaseSpider@@ -21,14 +20,10 @@ def _set_guid(spider, item):"""raise NotConfigured('You must define a set_guid method in order to scrape items.')-def _log(spider, message, level=log.DEBUG):- log.msg(message, domain=spider.domain_name, level=level)-class CrawlSpider(BaseSpider):"""This class works as a base class for spiders that crawl over websites"""- log = _logset_guid = _set_guiddef __init__(self):@@ -108,7 +103,6 @@ class XMLFeedSpider(BaseSpider):You can choose whether to parse the file using the iternodes tool,or not using it (which just splits the tags using xpath)"""- log = _logset_guid = _set_guiditernodes = Trueitertag = 'item'@@ -139,15 +133,15 @@ class CSVFeedSpider(BaseSpider):You can set some options regarding the CSV file, such as the delimiterand the file's headers."""- log = _logset_guid = _set_guiddelimiter = None # When this is None, python's csv module's default delimiter is usedheaders = None- # You can override this function in order to make any changes you want to- # into the feed before parsing it.- # This function may return either a response or a string.def adapt_feed(self, response):+ """You can override this function in order to make any changes you want+ to into the feed before parsing it. This function may return either a+ response or a string. """+return responsedef parse_row_wrapper(self, response, row):diff --git a/scrapy/trunk/scrapy/spider/models.py b/scrapy/trunk/scrapy/spider/models.pyindex d680b93e9..cf07b0b58 100644--- a/scrapy/trunk/scrapy/spider/models.py+++ b/scrapy/trunk/scrapy/spider/models.py@@ -4,6 +4,7 @@ Base class for scrapy spidersfrom zope.interface import Interface, Attribute, invariant, implementsfrom twisted.plugin import IPlugin+from scrapy import logfrom scrapy.core.exceptions import UsageErrordef _valid_start_urls(obj):@@ -87,3 +88,9 @@ class BaseSpider(object):implements(ISpider)domain_name = Noneextra_domain_names = []++ def log(self, message, level=log.DEBUG):+ """Log the given messages at the given log level. Always use this+ method to send log messages from your spider+ """+ log.msg(message, domain=self.domain_name, level=level)