mirror of https://github.com/scrapy/scrapy.git
Add JsonResponse (#6174)
This commit is contained in:
parent
b498f1376d
commit
d25cfe5315
|
|
@ -1357,3 +1357,13 @@ XmlResponse objects
|
|||
line. See :attr:`TextResponse.encoding`.
|
||||
|
||||
.. _bug in lxml: https://bugs.launchpad.net/lxml/+bug/1665241
|
||||
|
||||
JsonResponse objects
|
||||
--------------------
|
||||
|
||||
.. class:: JsonResponse(url[, ...])
|
||||
|
||||
The :class:`JsonResponse` class is a subclass of :class:`TextResponse`
|
||||
that is used when the response has a `JSON MIME type
|
||||
<https://mimesniff.spec.whatwg.org/#json-mime-type>`_ in its `Content-Type`
|
||||
header.
|
||||
|
|
|
|||
|
|
@ -12,5 +12,6 @@ from scrapy.http.request.json_request import JsonRequest
|
|||
from scrapy.http.request.rpc import XmlRpcRequest
|
||||
from scrapy.http.response import Response
|
||||
from scrapy.http.response.html import HtmlResponse
|
||||
from scrapy.http.response.json import JsonResponse
|
||||
from scrapy.http.response.text import TextResponse
|
||||
from scrapy.http.response.xml import XmlResponse
|
||||
|
|
|
|||
|
|
@ -0,0 +1,12 @@
|
|||
"""
|
||||
This module implements the JsonResponse class that is used when the response
|
||||
has a JSON MIME type in its Content-Type header.
|
||||
|
||||
See documentation in docs/topics/request-response.rst
|
||||
"""
|
||||
|
||||
from scrapy.http.response.text import TextResponse
|
||||
|
||||
|
||||
class JsonResponse(TextResponse):
|
||||
pass
|
||||
|
|
@ -21,9 +21,9 @@ class ResponseTypes:
|
|||
"application/xhtml+xml": "scrapy.http.HtmlResponse",
|
||||
"application/vnd.wap.xhtml+xml": "scrapy.http.HtmlResponse",
|
||||
"application/xml": "scrapy.http.XmlResponse",
|
||||
"application/json": "scrapy.http.TextResponse",
|
||||
"application/x-json": "scrapy.http.TextResponse",
|
||||
"application/json-amazonui-streaming": "scrapy.http.TextResponse",
|
||||
"application/json": "scrapy.http.JsonResponse",
|
||||
"application/x-json": "scrapy.http.JsonResponse",
|
||||
"application/json-amazonui-streaming": "scrapy.http.JsonResponse",
|
||||
"application/javascript": "scrapy.http.TextResponse",
|
||||
"application/x-javascript": "scrapy.http.TextResponse",
|
||||
"text/xml": "scrapy.http.XmlResponse",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,13 @@
|
|||
import unittest
|
||||
|
||||
from scrapy.http import Headers, HtmlResponse, Response, TextResponse, XmlResponse
|
||||
from scrapy.http import (
|
||||
Headers,
|
||||
HtmlResponse,
|
||||
JsonResponse,
|
||||
Response,
|
||||
TextResponse,
|
||||
XmlResponse,
|
||||
)
|
||||
from scrapy.responsetypes import responsetypes
|
||||
|
||||
|
||||
|
|
@ -40,8 +47,9 @@ class ResponseTypesTest(unittest.TestCase):
|
|||
("application/vnd.wap.xhtml+xml; charset=utf-8", HtmlResponse),
|
||||
("application/xml; charset=UTF-8", XmlResponse),
|
||||
("application/octet-stream", Response),
|
||||
("application/x-json; encoding=UTF8;charset=UTF-8", TextResponse),
|
||||
("application/json-amazonui-streaming;charset=UTF-8", TextResponse),
|
||||
("application/json; encoding=UTF8;charset=UTF-8", JsonResponse),
|
||||
("application/x-json; encoding=UTF8;charset=UTF-8", JsonResponse),
|
||||
("application/json-amazonui-streaming;charset=UTF-8", JsonResponse),
|
||||
(b"application/x-download; filename=\x80dummy.txt", Response),
|
||||
]
|
||||
for source, cls in mappings:
|
||||
|
|
|
|||
Loading…
Reference in New Issue