From 5ccd4df0cd75de652632841776238b088446271b Mon Sep 17 00:00:00 2001 From: Pablo Hoffman Date: Sun, 23 Nov 2008 01:32:21 +0000 Subject: [PATCH] moved log method to BaseSpider, moved adapt_feed doc to docstring --HG-- extra : convert_revision : svn%3Ab85faa78-f9eb-468e-a121-7cced6da292c%40395 --- scrapy/trunk/scrapy/contrib/spiders.py | 14 ++++---------- scrapy/trunk/scrapy/spider/models.py | 7 +++++++ 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/scrapy/trunk/scrapy/contrib/spiders.py b/scrapy/trunk/scrapy/contrib/spiders.py index 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 log from scrapy.conf import settings from scrapy.http import Request from 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 = _log set_guid = _set_guid def __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 = _log set_guid = _set_guid iternodes = True itertag = 'item' @@ -139,15 +133,15 @@ class CSVFeedSpider(BaseSpider): You can set some options regarding the CSV file, such as the delimiter and the file's headers. """ - log = _log set_guid = _set_guid delimiter = None # When this is None, python's csv module's default delimiter is used headers = 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 response def parse_row_wrapper(self, response, row): diff --git a/scrapy/trunk/scrapy/spider/models.py b/scrapy/trunk/scrapy/spider/models.py index 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 spiders from zope.interface import Interface, Attribute, invariant, implements from twisted.plugin import IPlugin +from scrapy import log from scrapy.core.exceptions import UsageError def _valid_start_urls(obj): @@ -87,3 +88,9 @@ class BaseSpider(object): implements(ISpider) domain_name = None extra_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)