From 0eaa1d95f6dea80f807fce979d8f521729905906 Mon Sep 17 00:00:00 2001 From: Pablo Hoffman Date: Mon, 8 Aug 2011 10:39:53 -0300 Subject: [PATCH] replaced DeprecationWarning by a new ScrapyDeprecationWarning category, since the default DeprecationWarning is silenced on Python 2.7+ --- scrapy/cmdline.py | 4 ++-- scrapy/contrib/closespider.py | 3 ++- scrapy/contrib/exporter/jsonlines.py | 3 ++- scrapy/contrib/spidermiddleware/depth.py | 3 ++- scrapy/core/downloader/__init__.py | 3 ++- scrapy/exceptions.py | 7 +++++++ scrapy/http/common.py | 3 ++- scrapy/log.py | 3 ++- scrapy/utils/decorator.py | 3 ++- scrapy/utils/deprecate.py | 4 +++- 10 files changed, 26 insertions(+), 10 deletions(-) diff --git a/scrapy/cmdline.py b/scrapy/cmdline.py index e381bf537..4ff61fd86 100644 --- a/scrapy/cmdline.py +++ b/scrapy/cmdline.py @@ -11,7 +11,7 @@ from scrapy.crawler import CrawlerProcess from scrapy.xlib import lsprofcalltree from scrapy.conf import settings from scrapy.command import ScrapyCommand -from scrapy.exceptions import UsageError +from scrapy.exceptions import UsageError, ScrapyDeprecationWarning from scrapy.utils.misc import walk_modules from scrapy.utils.project import inside_project @@ -82,7 +82,7 @@ def _check_deprecated_scrapy_ctl(argv, inproject): return import warnings warnings.warn("`scrapy-ctl.py` command-line tool is deprecated and will be removed in Scrapy 0.11, use `scrapy` instead", - DeprecationWarning, stacklevel=3) + ScrapyDeprecationWarning, stacklevel=3) if inproject: projpath = os.path.abspath(os.path.dirname(os.path.dirname(settings.settings_module.__file__))) cfg_path = os.path.join(projpath, 'scrapy.cfg') diff --git a/scrapy/contrib/closespider.py b/scrapy/contrib/closespider.py index fed26e84a..7dab6c55f 100644 --- a/scrapy/contrib/closespider.py +++ b/scrapy/contrib/closespider.py @@ -12,6 +12,7 @@ from twisted.python import log as txlog from scrapy.xlib.pydispatch import dispatcher from scrapy import signals, log +from scrapy.exceptions import ScrapyDeprecationWarning from scrapy.project import crawler from scrapy.conf import settings @@ -22,7 +23,7 @@ class CloseSpider(object): self.itemcount = settings.getint('CLOSESPIDER_ITEMCOUNT') # XXX: legacy support - remove for future releases if settings.getint('CLOSESPIDER_ITEMPASSED'): - warnings.warn("CLOSESPIDER_ITEMPASSED setting is deprecated, use CLOSESPIDER_ITEMCOUNT instead", DeprecationWarning) + warnings.warn("CLOSESPIDER_ITEMPASSED setting is deprecated, use CLOSESPIDER_ITEMCOUNT instead", ScrapyDeprecationWarning) self.pagecount = settings.getint('CLOSESPIDER_ITEMPASSED') self.pagecount = settings.getint('CLOSESPIDER_PAGECOUNT') self.errorcount = settings.getint('CLOSESPIDER_ERRORCOUNT') diff --git a/scrapy/contrib/exporter/jsonlines.py b/scrapy/contrib/exporter/jsonlines.py index eb2dbcafe..fbab65735 100644 --- a/scrapy/contrib/exporter/jsonlines.py +++ b/scrapy/contrib/exporter/jsonlines.py @@ -1,5 +1,6 @@ from scrapy.contrib.exporter import JsonLinesItemExporter +from scrapy.exceptions import ScrapyDeprecationWarning import warnings warnings.warn("Module `scrapy.contrib.exporter.jsonlines` is deprecated - use `scrapy.contrib.exporter` instead", - DeprecationWarning, stacklevel=2) + ScrapyDeprecationWarning, stacklevel=2) diff --git a/scrapy/contrib/spidermiddleware/depth.py b/scrapy/contrib/spidermiddleware/depth.py index 883d828ee..978e7baef 100644 --- a/scrapy/contrib/spidermiddleware/depth.py +++ b/scrapy/contrib/spidermiddleware/depth.py @@ -8,6 +8,7 @@ import warnings from scrapy import log from scrapy.http import Request +from scrapy.exceptions import ScrapyDeprecationWarning class DepthMiddleware(object): @@ -27,7 +28,7 @@ class DepthMiddleware(object): # XXX: backwards compatibility with old SCHEDULER_ORDER setting # will be removed on Scrapy 0.15 warnings.warn("SCHEDULER_ORDER setting is deprecated, " \ - "use DEPTH_PRIORITY instead", DeprecationWarning) + "use DEPTH_PRIORITY instead", ScrapyDeprecationWarning) if sorder == 'BFO': prio = 1 elif sorder == 'DFO': diff --git a/scrapy/core/downloader/__init__.py b/scrapy/core/downloader/__init__.py index f39da779f..cd60d4d83 100644 --- a/scrapy/core/downloader/__init__.py +++ b/scrapy/core/downloader/__init__.py @@ -11,6 +11,7 @@ from scrapy.utils.defer import mustbe_deferred from scrapy.utils.signal import send_catch_log from scrapy.utils.httpobj import urlparse_cached from scrapy.resolver import dnscache +from scrapy.exceptions import ScrapyDeprecationWarning from scrapy import signals from scrapy import log from .middleware import DownloaderMiddlewareManager @@ -46,7 +47,7 @@ def _get_concurrency_delay(concurrency, spider, settings): c = settings.getint('CONCURRENT_REQUESTS_PER_SPIDER') if c: warnings.warn("CONCURRENT_REQUESTS_PER_SPIDER setting is deprecated, " \ - "use CONCURRENT_REQUESTS_PER_DOMAIN instead", DeprecationWarning) + "use CONCURRENT_REQUESTS_PER_DOMAIN instead", ScrapyDeprecationWarning) concurrency = c # ---------------------------- diff --git a/scrapy/exceptions.py b/scrapy/exceptions.py index 43e142160..8f29a4c8d 100644 --- a/scrapy/exceptions.py +++ b/scrapy/exceptions.py @@ -43,3 +43,10 @@ class UsageError(Exception): def __init__(self, *a, **kw): self.print_help = kw.pop('print_help', True) super(UsageError, self).__init__(*a, **kw) + +class ScrapyDeprecationWarning(Warning): + """Warning category for deprecated features, since the default + DeprecationWarning is silenced on Python 2.7+ + """ + pass + diff --git a/scrapy/http/common.py b/scrapy/http/common.py index 63d264264..34d5389bf 100644 --- a/scrapy/http/common.py +++ b/scrapy/http/common.py @@ -1,9 +1,10 @@ import warnings +from scrapy.exceptions import ScrapyDeprecationWarning def deprecated_setter(setter, attrname): def newsetter(self, value): c = self.__class__.__name__ warnings.warn("Don't modify %s.%s attribute, use %s.replace() instead" % \ - (c, attrname, c), DeprecationWarning, stacklevel=2) + (c, attrname, c), ScrapyDeprecationWarning, stacklevel=2) return setter(self, value) return newsetter diff --git a/scrapy/log.py b/scrapy/log.py index 6285209ce..8d79f3aef 100644 --- a/scrapy/log.py +++ b/scrapy/log.py @@ -13,6 +13,7 @@ import scrapy from scrapy.conf import settings from scrapy.utils.python import unicode_to_str from scrapy.utils.misc import load_object +from scrapy.exceptions import ScrapyDeprecationWarning # Logging levels DEBUG = logging.DEBUG @@ -114,7 +115,7 @@ def start(logfile=None, loglevel=None, logstdout=None): def msg(message, level=INFO, **kw): if 'component' in kw: warnings.warn("Argument `component` of scrapy.log.msg() is deprecated", \ - DeprecationWarning, stacklevel=2) + ScrapyDeprecationWarning, stacklevel=2) kw.setdefault('system', 'scrapy') kw['logLevel'] = level log.msg(message, **kw) diff --git a/scrapy/utils/decorator.py b/scrapy/utils/decorator.py index 54edebc85..623736577 100644 --- a/scrapy/utils/decorator.py +++ b/scrapy/utils/decorator.py @@ -3,6 +3,7 @@ from functools import wraps from twisted.internet import defer, threads +from scrapy.exceptions import ScrapyDeprecationWarning def deprecated(use_instead=None): """This is a decorator which can be used to mark functions @@ -15,7 +16,7 @@ def deprecated(use_instead=None): message = "Call to deprecated function %s." % func.__name__ if use_instead: message += " Use %s instead." % use_instead - warnings.warn(message, category=DeprecationWarning, stacklevel=2) + warnings.warn(message, category=ScrapyDeprecationWarning, stacklevel=2) return func(*args, **kwargs) return new_func return wrapped diff --git a/scrapy/utils/deprecate.py b/scrapy/utils/deprecate.py index 58f580259..a5850b6e8 100644 --- a/scrapy/utils/deprecate.py +++ b/scrapy/utils/deprecate.py @@ -2,8 +2,10 @@ import warnings +from scrapy.exceptions import ScrapyDeprecationWarning + def attribute(obj, oldattr, newattr, version='0.12'): cname = obj.__class__.__name__ warnings.warn("%s.%s attribute is deprecated and will be no longer supported " "in Scrapy %s, use %s.%s attribute instead" % \ - (cname, oldattr, version, cname, newattr), DeprecationWarning, stacklevel=3) + (cname, oldattr, version, cname, newattr), ScrapyDeprecationWarning, stacklevel=3)