Skip to content

Commit c19cd14

Browse files
authored
Merge branch 'dev' into hallvictoria/cosmosdb-types
2 parents 89694c6 + d2e5d9f commit c19cd14

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+3084
-10614
lines changed

.azuredevops/dependabot.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Mirrored repository. We use dependabot via GitHub, not Azure DevOps.
2+
version: 2
3+
enable-security-updates: false
4+
enable-campaigned-updates: false

.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

README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,15 @@
77

88
## Overview
99

10-
Python support for Azure Functions is based on Python 3.8, 3.9, 3.10, 3.11, and 3.12 serverless hosting on Linux, and the Functions 2.x ([EOL](https://learn.microsoft.com/azure/azure-functions/functions-versions?#retired-versions)), 3.x ([EOL](https://learn.microsoft.com/azure/azure-functions/functions-versions?#retired-versions)) and 4.0 runtime.
10+
Python support for Azure Functions is based on Python 3.10, 3.11, 3.12, and 3.13 serverless hosting on Linux, and the Functions 2.x ([EOL](https://learn.microsoft.com/azure/azure-functions/functions-versions?#retired-versions)), 3.x ([EOL](https://learn.microsoft.com/azure/azure-functions/functions-versions?#retired-versions)) and 4.0 runtime.
1111

1212
Here is the current status of Python in Azure Functions:
1313

1414
_What are the supported Python versions?_
1515

16-
| Azure Functions Runtime | Python 3.8 | Python 3.9 | Python 3.10 | Python 3.11 | Python 3.12 |
17-
|-------------------------|--------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------|-------------|-------------|-------------|
18-
| Azure Functions 3.0 | [EOL](https://learn.microsoft.com/azure/azure-functions/migrate-version-3-version-4) | [EOL](https://learn.microsoft.com/azure/azure-functions/migrate-version-3-version-4) | - | - | - |
19-
| Azure Functions 4.0 | ✓ | ✓ | ✓ | ✓ | ✓ |
16+
| Azure Functions Runtime | Python 3.10 | Python 3.11 | Python 3.12 | Python 3.13 |
17+
|----------------------------------|------------|------------|-------------|-------------|
18+
| Azure Functions 4.0 ||||| | ✓ | ✓ | ✓ |
2019

2120
_What's available?_
2221
- Build, test, debug and publish using Azure Functions Core Tools (CLI) or Visual Studio Code

azure/functions/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,4 @@
102102
'BlobSource'
103103
)
104104

105-
__version__ = '1.22.0b4'
105+
__version__ = '1.25.0b1'

azure/functions/_abc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import threading
88
import typing
99

10-
from azure.functions._thirdparty.werkzeug.datastructures import Headers
10+
from werkzeug.datastructures import Headers
1111

1212
T = typing.TypeVar('T')
1313

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: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@
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
11+
from werkzeug import formparser as _wk_parser
12+
from werkzeug import http as _wk_http
13+
from werkzeug.datastructures import (Headers, FileStorage, MultiDict,
14+
ImmutableMultiDict)
15+
1116
from . import _abc
12-
from ._thirdparty.werkzeug import datastructures as _wk_datastructures
13-
from ._thirdparty.werkzeug import formparser as _wk_parser
14-
from ._thirdparty.werkzeug import http as _wk_http
15-
from ._thirdparty.werkzeug.datastructures import Headers
1617

1718

1819
class BaseHeaders(collections.abc.Mapping):
@@ -174,8 +175,8 @@ def __init__(self,
174175
self.__route_params = types.MappingProxyType(route_params or {})
175176
self.__body_bytes = body
176177
self.__form_parsed = False
177-
self.__form = None
178-
self.__files = None
178+
self.__form: MultiDict[str, str]
179+
self.__files: MultiDict[str, FileStorage]
179180

180181
@property
181182
def url(self):
@@ -222,12 +223,9 @@ def _parse_form_data(self):
222223
content_length = len(body)
223224
mimetype, options = _wk_http.parse_options_header(content_type)
224225
parser = _wk_parser.FormDataParser(
225-
_wk_parser.default_stream_factory,
226-
options.get('charset') or 'utf-8',
227-
'replace',
228-
None,
229-
None,
230-
_wk_datastructures.ImmutableMultiDict,
226+
_wk_parser.default_stream_factory, max_form_memory_size=None,
227+
max_content_length=None,
228+
cls=ImmutableMultiDict
231229
)
232230

233231
body_stream = io.BytesIO(body)

azure/functions/_http_wsgi.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
# Copyright (c) Microsoft Corporation. All rights reserved.
22
# Licensed under the MIT License.
3-
from typing import Dict, List, Optional, Any
43
import logging
54
from io import BytesIO, StringIO
65
from os import linesep
6+
from typing import Dict, List, Optional, Any
77
from urllib.parse import ParseResult, urlparse, unquote_to_bytes
88
from wsgiref.headers import Headers
99

1010
from ._abc import Context
1111
from ._http import HttpRequest, HttpResponse
12-
from ._thirdparty.werkzeug._compat import string_types, wsgi_encoding_dance
12+
13+
14+
def wsgi_encoding_dance(value):
15+
return value.encode().decode("latin1")
1316

1417

1518
class WsgiRequest:
@@ -98,7 +101,7 @@ def to_environ(self, errors_buffer: StringIO) -> Dict[str, Any]:
98101

99102
# Ensure WSGI string fits in IOS-8859-1 code points
100103
for k, v in environ.items():
101-
if isinstance(v, string_types):
104+
if isinstance(v, (str,)):
102105
environ[k] = wsgi_encoding_dance(v)
103106

104107
# Remove None values

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):

0 commit comments

Comments
 (0)