Skip to content

Commit e37a609

Browse files
authored
Merge branch 'dev' into hallvictoria/abstract-timer
2 parents 6f4bd8f + 4a19d87 commit e37a609

23 files changed

+1442
-1362
lines changed

.flake8

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ ignore = W503,E402,E731
33
exclude =
44
.git, __pycache__, build, dist, .eggs, .github, .local,
55
Samples, azure/functions/_thirdparty, docs/, .venv*/, .env*/, .vscode/, venv*, pyvenv*
6+
max-line-length = 100
7+
extend-ignore = D401, D101, D105, D400, D205, D102, D100, D107, DAR401, DAR101, DAR201
8+
strictness = short

azure/functions/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,4 @@
104104
'BlobSource'
105105
)
106106

107-
__version__ = '1.24.0b2'
107+
__version__ = '1.24.0b3'

azure/functions/_cosmosdb.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
# Licensed under the MIT License.
33

44
import collections
5-
import json
65

76
from . import _abc
7+
from ._jsonutils import json
88

99

1010
class Document(_abc.Document, collections.UserDict):

azure/functions/_http.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
import collections.abc
55
import http
66
import io
7-
import json
87
import types
98
import typing
109

10+
from ._jsonutils import json
1111
from werkzeug import formparser as _wk_parser
1212
from werkzeug import http as _wk_http
1313
from werkzeug.datastructures import (Headers, FileStorage, MultiDict,

azure/functions/_jsonutils.py

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
4+
from abc import ABC, abstractmethod
5+
from typing import Any, Union
6+
from types import SimpleNamespace
7+
8+
9+
"""
10+
Azure Functions JSON utilities.
11+
This module provides a JSON interface that can be used to serialize and
12+
deserialize objects to and from JSON format. It supports both the `orjson`
13+
and the standard `json` libraries, falling back to the standard library
14+
if `orjson` is not available (installed).
15+
"""
16+
17+
18+
try:
19+
import orjson as _orjson
20+
except ImportError:
21+
_orjson = None
22+
23+
# Standard library is always present
24+
import json as _std_json
25+
26+
27+
class JsonInterface(ABC):
28+
@abstractmethod
29+
def dumps(self, obj: Any) -> str:
30+
pass
31+
32+
@abstractmethod
33+
def loads(self, s: Union[str, bytes, bytearray]) -> Any:
34+
pass
35+
36+
37+
class OrJsonAdapter(JsonInterface):
38+
def __init__(self):
39+
assert _orjson is not None
40+
self.orjson = _orjson
41+
42+
def dumps(self, obj: Any) -> str:
43+
# orjson.dumps returns bytes, decode to str
44+
return self.orjson.dumps(obj).decode("utf-8")
45+
46+
def loads(self, s: Union[str, bytes, bytearray]) -> Any:
47+
return self.orjson.loads(s)
48+
49+
50+
class StdJsonAdapter(JsonInterface):
51+
def __init__(self):
52+
self.json = _std_json
53+
54+
def dumps(self, obj: Any) -> str:
55+
return self.json.dumps(obj)
56+
57+
def loads(self, s: Union[str, bytes, bytearray]) -> Any:
58+
return self.json.loads(s)
59+
60+
61+
if _orjson is not None:
62+
json_impl = OrJsonAdapter()
63+
else:
64+
json_impl = StdJsonAdapter()
65+
66+
67+
def dumps(obj: Any) -> str:
68+
return json_impl.dumps(obj)
69+
70+
71+
def loads(s: Union[str, bytes, bytearray]) -> Any:
72+
return json_impl.loads(s)
73+
74+
75+
json = SimpleNamespace(
76+
dumps=dumps,
77+
loads=loads
78+
)

azure/functions/_mysql.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
# Licensed under the MIT License.
33
import abc
44
import collections
5-
import json
5+
6+
from ._jsonutils import json
67

78

89
class BaseMySqlRow(abc.ABC):

azure/functions/_queue.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
# Licensed under the MIT License.
33

44
import datetime
5-
import json
65
import typing
76

87
from . import _abc
8+
from ._jsonutils import json
99

1010

1111
class QueueMessage(_abc.QueueMessage):

azure/functions/_sql.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
# Licensed under the MIT License.
33
import abc
44
import collections
5-
import json
5+
6+
from ._jsonutils import json
67

78

89
class BaseSqlRow(abc.ABC):

azure/functions/cosmosdb.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
# Licensed under the MIT License.
33

44
import collections.abc
5-
import json
65
import typing
76

87
from azure.functions import _cosmosdb as cdb
8+
from ._jsonutils import json
99

1010
from . import meta
1111

0 commit comments

Comments
 (0)