fix(parser): Improve response to json conversion
This commit is contained in:
+6
-1
@@ -939,8 +939,13 @@ class Selector(SelectorsGeneration):
|
|||||||
# Operations on text functions
|
# Operations on text functions
|
||||||
def json(self) -> Dict:
|
def json(self) -> Dict:
|
||||||
"""Return JSON response if the response is jsonable otherwise throws error"""
|
"""Return JSON response if the response is jsonable otherwise throws error"""
|
||||||
if self._raw_body and isinstance(self._raw_body, str):
|
if self._raw_body and isinstance(self._raw_body, (str, bytes)):
|
||||||
|
if isinstance(self._raw_body, str):
|
||||||
return TextHandler(self._raw_body).json()
|
return TextHandler(self._raw_body).json()
|
||||||
|
else:
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
assert isinstance(self._raw_body, bytes)
|
||||||
|
return TextHandler(self._raw_body.decode()).json()
|
||||||
elif self.text:
|
elif self.text:
|
||||||
return self.text.json()
|
return self.text.json()
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user