mirror of https://github.com/scrapy/scrapy.git
replaced DeprecationWarning by a new ScrapyDeprecationWarning category, since the default DeprecationWarning is silenced on Python 2.7+
This commit is contained in:
parent
f7c0aeccc6
commit
0eaa1d95f6
|
|
@ -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')
|
||||
|
|
|
|||
|
|
@ -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')
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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':
|
||||
|
|
|
|||
|
|
@ -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
|
||||
# ----------------------------
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue