mirror of
https://github.com/scrapy/scrapy.git
synced 2025-02-25 06:44:23 +00:00
Fix backwards-compatibility for users who explicitly set _BASE settings
This commit is contained in:
parent
f249b309ab
commit
03f1720afb
@ -116,9 +116,9 @@ class BaseSettings(MutableMapping):
|
|||||||
def getbool(self, name, default=False):
|
def getbool(self, name, default=False):
|
||||||
"""
|
"""
|
||||||
Get a setting value as a boolean.
|
Get a setting value as a boolean.
|
||||||
|
|
||||||
``1``, ``'1'``, and ``True`` return ``True``, while ``0``, ``'0'``,
|
``1``, ``'1'``, and ``True`` return ``True``, while ``0``, ``'0'``,
|
||||||
``False`` and ``None`` return ``False``.
|
``False`` and ``None`` return ``False``.
|
||||||
|
|
||||||
For example, settings populated through environment variables set to
|
For example, settings populated through environment variables set to
|
||||||
``'0'`` will return ``False`` when using this method.
|
``'0'`` will return ``False`` when using this method.
|
||||||
@ -203,11 +203,17 @@ class BaseSettings(MutableMapping):
|
|||||||
if basename in self:
|
if basename in self:
|
||||||
warnings.warn('_BASE settings are deprecated.',
|
warnings.warn('_BASE settings are deprecated.',
|
||||||
category=ScrapyDeprecationWarning)
|
category=ScrapyDeprecationWarning)
|
||||||
compsett = BaseSettings(self[name + "_BASE"], priority='default')
|
# When users defined a _BASE setting, they explicitly don't want to
|
||||||
compsett.update(self[name])
|
# use any of Scrapy's defaults. Therefore, we only use these entries
|
||||||
|
# from self[name] (where the defaults now live) that have a priority
|
||||||
|
# higher than 'default'
|
||||||
|
compsett = BaseSettings(self[basename], priority='default')
|
||||||
|
for k in self[name]:
|
||||||
|
prio = self[name].getpriority(k)
|
||||||
|
if prio > get_settings_priority('default'):
|
||||||
|
compsett.set(k, self[name][k], prio)
|
||||||
return compsett
|
return compsett
|
||||||
else:
|
return self[name]
|
||||||
return self[name]
|
|
||||||
|
|
||||||
def getpriority(self, name):
|
def getpriority(self, name):
|
||||||
"""
|
"""
|
||||||
|
@ -252,12 +252,17 @@ class BaseSettingsTest(unittest.TestCase):
|
|||||||
|
|
||||||
def test_getcomposite(self):
|
def test_getcomposite(self):
|
||||||
s = BaseSettings({'TEST_BASE': {1: 1, 2: 2},
|
s = BaseSettings({'TEST_BASE': {1: 1, 2: 2},
|
||||||
'TEST': BaseSettings({1: 10}),
|
'TEST': BaseSettings({1: 10, 3: 30}, 'default'),
|
||||||
'HASNOBASE': BaseSettings({1: 1})})
|
'HASNOBASE': BaseSettings({1: 1}, 'default')})
|
||||||
|
s['TEST'].set(4, 4, priority='project')
|
||||||
|
# When users specify a _BASE setting they explicitly don't want to use
|
||||||
|
# Scrapy's defaults, so we don't want to see anything that has a
|
||||||
|
# 'default' priority from TEST
|
||||||
cs = s._getcomposite('TEST')
|
cs = s._getcomposite('TEST')
|
||||||
self.assertEqual(len(cs), 2)
|
self.assertEqual(len(cs), 3)
|
||||||
self.assertEqual(cs[1], 10)
|
self.assertEqual(cs[1], 1)
|
||||||
self.assertEqual(cs[2], 2)
|
self.assertEqual(cs[2], 2)
|
||||||
|
self.assertEqual(cs[4], 4)
|
||||||
cs = s._getcomposite('HASNOBASE')
|
cs = s._getcomposite('HASNOBASE')
|
||||||
self.assertEqual(len(cs), 1)
|
self.assertEqual(len(cs), 1)
|
||||||
self.assertEqual(cs[1], 1)
|
self.assertEqual(cs[1], 1)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user