mirror of https://github.com/scrapy/scrapy.git
Deprecate ResponseTypes.CLASSES
This commit is contained in:
parent
1ea5a8e9e0
commit
54a0248301
|
|
@ -11,7 +11,19 @@ from scrapy.utils.python import binary_is_text, to_bytes, to_unicode
|
|||
from scrapy.utils.response import _MIME_TYPES
|
||||
|
||||
|
||||
class ResponseTypes:
|
||||
class _ResponseTypesMeta(type):
|
||||
|
||||
def __getattribute__(self, name):
|
||||
if name == 'CLASSES':
|
||||
warn(
|
||||
'scrapy.responsetypes.ResponseTypes.CLASSES is deprecated',
|
||||
ScrapyDeprecationWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
return type.__getattribute__(self, name)
|
||||
|
||||
|
||||
class ResponseTypes(metaclass=_ResponseTypesMeta):
|
||||
|
||||
CLASSES = {
|
||||
'text/html': 'scrapy.http.HtmlResponse',
|
||||
|
|
@ -47,6 +59,15 @@ class ResponseTypes:
|
|||
for mimetype, cls in self.CLASSES.items():
|
||||
self.classes[mimetype] = load_object(cls)
|
||||
|
||||
def __getattribute__(self, name):
|
||||
if name == 'CLASSES':
|
||||
warn(
|
||||
'scrapy.responsetypes.ResponseTypes.CLASSES is deprecated',
|
||||
ScrapyDeprecationWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
return super().__getattribute__(name)
|
||||
|
||||
def from_mimetype(self, mimetype):
|
||||
"""Return the most appropriate Response class for the given mimetype"""
|
||||
warn('ResponseTypes.from_mimetype is deprecated, '
|
||||
|
|
|
|||
|
|
@ -127,6 +127,24 @@ class ResponseTypesTest(unittest.TestCase):
|
|||
messages = {str(warning.message) for warning in warnings}
|
||||
self.assertIn(expected_message, messages)
|
||||
|
||||
def test_class_classes_deprecation(self):
|
||||
with catch_warnings(record=True) as warnings:
|
||||
ResponseTypes.CLASSES
|
||||
expected_message = (
|
||||
'scrapy.responsetypes.ResponseTypes.CLASSES is deprecated'
|
||||
)
|
||||
messages = {str(warning.message) for warning in warnings}
|
||||
self.assertIn(expected_message, messages)
|
||||
|
||||
def test_instance_classes_deprecation(self):
|
||||
with catch_warnings(record=True) as warnings:
|
||||
responsetypes.CLASSES
|
||||
expected_message = (
|
||||
'scrapy.responsetypes.ResponseTypes.CLASSES is deprecated'
|
||||
)
|
||||
messages = {str(warning.message) for warning in warnings}
|
||||
self.assertIn(expected_message, messages)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
|
|||
Loading…
Reference in New Issue