Additional support needed when using orjson
This commit is contained in:
@@ -1,13 +1,9 @@
|
|||||||
import binascii
|
import binascii
|
||||||
import hashlib
|
import hashlib
|
||||||
import hmac
|
import hmac
|
||||||
|
import json
|
||||||
from time import time
|
from time import time
|
||||||
|
|
||||||
try:
|
|
||||||
import orjson as json
|
|
||||||
except ImportError:
|
|
||||||
import json
|
|
||||||
|
|
||||||
def _to_b64url(data):
|
def _to_b64url(data):
|
||||||
return (
|
return (
|
||||||
binascii.b2a_base64(data)
|
binascii.b2a_base64(data)
|
||||||
|
|||||||
@@ -578,9 +578,9 @@ class Response:
|
|||||||
self.headers = NoCaseDict(headers or {})
|
self.headers = NoCaseDict(headers or {})
|
||||||
self.reason = reason
|
self.reason = reason
|
||||||
if isinstance(body, (dict, list)):
|
if isinstance(body, (dict, list)):
|
||||||
self.body = json.dumps(body).encode()
|
body = json.dumps(body)
|
||||||
self.headers['Content-Type'] = 'application/json; charset=UTF-8'
|
self.headers['Content-Type'] = 'application/json; charset=UTF-8'
|
||||||
elif isinstance(body, str):
|
if isinstance(body, str):
|
||||||
self.body = body.encode()
|
self.body = body.encode()
|
||||||
else:
|
else:
|
||||||
# this applies to bytes, file-like objects or generators
|
# this applies to bytes, file-like objects or generators
|
||||||
|
|||||||
@@ -29,8 +29,8 @@ class SSE:
|
|||||||
given, it must be a string.
|
given, it must be a string.
|
||||||
"""
|
"""
|
||||||
if isinstance(data, (dict, list)):
|
if isinstance(data, (dict, list)):
|
||||||
data = json.dumps(data).encode()
|
data = json.dumps(data)
|
||||||
elif isinstance(data, str):
|
if isinstance(data, str):
|
||||||
data = data.encode()
|
data = data.encode()
|
||||||
elif not isinstance(data, bytes):
|
elif not isinstance(data, bytes):
|
||||||
data = str(data).encode()
|
data = str(data).encode()
|
||||||
|
|||||||
@@ -105,10 +105,10 @@ class TestClient:
|
|||||||
if body is None:
|
if body is None:
|
||||||
body = b''
|
body = b''
|
||||||
elif isinstance(body, (dict, list)):
|
elif isinstance(body, (dict, list)):
|
||||||
body = json.dumps(body).encode()
|
body = json.dumps(body)
|
||||||
if 'Content-Type' not in headers: # pragma: no cover
|
if 'Content-Type' not in headers: # pragma: no cover
|
||||||
headers['Content-Type'] = 'application/json'
|
headers['Content-Type'] = 'application/json'
|
||||||
elif isinstance(body, str):
|
if isinstance(body, str):
|
||||||
body = body.encode()
|
body = body.encode()
|
||||||
if body and 'Content-Length' not in headers:
|
if body and 'Content-Length' not in headers:
|
||||||
headers['Content-Length'] = str(len(body))
|
headers['Content-Length'] = str(len(body))
|
||||||
|
|||||||
Reference in New Issue
Block a user