Use orjson instead of json if available

This commit is contained in:
Miguel Grinberg
2025-04-12 23:24:31 +01:00
parent f317b15bdb
commit 086f2af3de
4 changed files with 20 additions and 4 deletions

View File

@@ -1,9 +1,13 @@
import binascii
import hashlib
import hmac
import json
from time import time
try:
import orjson as json
except ImportError:
import json
def _to_b64url(data):
return (
binascii.b2a_base64(data)

View File

@@ -7,10 +7,14 @@ servers for MicroPython and standard Python.
"""
import asyncio
import io
import json
import re
import time
try:
import orjson as json
except ImportError:
import json
try:
from inspect import iscoroutinefunction, iscoroutine
from functools import partial

View File

@@ -1,7 +1,11 @@
import asyncio
import json
from microdot.helpers import wraps
try:
import orjson as json
except ImportError:
import json
class SSE:
"""Server-Sent Events object.

View File

@@ -1,4 +1,3 @@
import json
from microdot.microdot import Request, Response, AsyncBytesIO
try:
@@ -6,6 +5,11 @@ try:
except: # pragma: no cover # noqa: E722
WebSocket = None
try:
import orjson as json
except ImportError:
import json
__all__ = ['TestClient', 'TestResponse']