Skip to content

Commit 086f2af

Browse files
Use orjson instead of json if available
1 parent f317b15 commit 086f2af

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

libs/micropython/jwt.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
import binascii
22
import hashlib
33
import hmac
4-
import json
54
from time import time
65

6+
try:
7+
import orjson as json
8+
except ImportError:
9+
import json
10+
711
def _to_b64url(data):
812
return (
913
binascii.b2a_base64(data)

src/microdot/microdot.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,14 @@
77
"""
88
import asyncio
99
import io
10-
import json
1110
import re
1211
import time
1312

13+
try:
14+
import orjson as json
15+
except ImportError:
16+
import json
17+
1418
try:
1519
from inspect import iscoroutinefunction, iscoroutine
1620
from functools import partial

src/microdot/sse.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import asyncio
2-
import json
32
from microdot.helpers import wraps
43

4+
try:
5+
import orjson as json
6+
except ImportError:
7+
import json
8+
59

610
class SSE:
711
"""Server-Sent Events object.

src/microdot/test_client.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
import json
21
from microdot.microdot import Request, Response, AsyncBytesIO
32

43
try:
54
from microdot.websocket import WebSocket
65
except: # pragma: no cover # noqa: E722
76
WebSocket = None
87

8+
try:
9+
import orjson as json
10+
except ImportError:
11+
import json
12+
913
__all__ = ['TestClient', 'TestResponse']
1014

1115

0 commit comments

Comments
 (0)