azure-functions-runtime 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. azure_functions_runtime-1.0.0/PKG-INFO +120 -0
  2. azure_functions_runtime-1.0.0/README.md +71 -0
  3. azure_functions_runtime-1.0.0/azure_functions_runtime/__init__.py +21 -0
  4. azure_functions_runtime-1.0.0/azure_functions_runtime/bindings/context.py +66 -0
  5. azure_functions_runtime-1.0.0/azure_functions_runtime/bindings/datumdef.py +232 -0
  6. azure_functions_runtime-1.0.0/azure_functions_runtime/bindings/generic.py +75 -0
  7. azure_functions_runtime-1.0.0/azure_functions_runtime/bindings/meta.py +288 -0
  8. azure_functions_runtime-1.0.0/azure_functions_runtime/bindings/nullable_converters.py +126 -0
  9. azure_functions_runtime-1.0.0/azure_functions_runtime/bindings/out.py +15 -0
  10. azure_functions_runtime-1.0.0/azure_functions_runtime/bindings/retrycontext.py +47 -0
  11. azure_functions_runtime-1.0.0/azure_functions_runtime/bindings/tracecontext.py +43 -0
  12. azure_functions_runtime-1.0.0/azure_functions_runtime/functions.py +435 -0
  13. azure_functions_runtime-1.0.0/azure_functions_runtime/handle_event.py +448 -0
  14. azure_functions_runtime-1.0.0/azure_functions_runtime/http_v2.py +291 -0
  15. azure_functions_runtime-1.0.0/azure_functions_runtime/loader.py +219 -0
  16. azure_functions_runtime-1.0.0/azure_functions_runtime/logging.py +16 -0
  17. azure_functions_runtime-1.0.0/azure_functions_runtime/otel.py +116 -0
  18. azure_functions_runtime-1.0.0/azure_functions_runtime/utils/__init__.py +2 -0
  19. azure_functions_runtime-1.0.0/azure_functions_runtime/utils/app_setting_manager.py +102 -0
  20. azure_functions_runtime-1.0.0/azure_functions_runtime/utils/constants.py +63 -0
  21. azure_functions_runtime-1.0.0/azure_functions_runtime/utils/executor.py +34 -0
  22. azure_functions_runtime-1.0.0/azure_functions_runtime/utils/helpers.py +40 -0
  23. azure_functions_runtime-1.0.0/azure_functions_runtime/utils/threadpool.py +88 -0
  24. azure_functions_runtime-1.0.0/azure_functions_runtime/utils/tracing.py +70 -0
  25. azure_functions_runtime-1.0.0/azure_functions_runtime/utils/typing_inspect.py +295 -0
  26. azure_functions_runtime-1.0.0/azure_functions_runtime/utils/validators.py +19 -0
  27. azure_functions_runtime-1.0.0/azure_functions_runtime/utils/wrappers.py +52 -0
  28. azure_functions_runtime-1.0.0/azure_functions_runtime/version.py +4 -0
  29. azure_functions_runtime-1.0.0/azure_functions_runtime.egg-info/PKG-INFO +120 -0
  30. azure_functions_runtime-1.0.0/azure_functions_runtime.egg-info/SOURCES.txt +33 -0
  31. azure_functions_runtime-1.0.0/azure_functions_runtime.egg-info/dependency_links.txt +1 -0
  32. azure_functions_runtime-1.0.0/azure_functions_runtime.egg-info/requires.txt +31 -0
  33. azure_functions_runtime-1.0.0/azure_functions_runtime.egg-info/top_level.txt +2 -0
  34. azure_functions_runtime-1.0.0/pyproject.toml +103 -0
  35. azure_functions_runtime-1.0.0/setup.cfg +4 -0
@@ -0,0 +1,120 @@
1
+ Metadata-Version: 2.4
2
+ Name: azure-functions-runtime
3
+ Version: 1.0.0
4
+ Summary: Python Language Worker for Azure Functions Runtime
5
+ Author-email: "Azure Functions team at Microsoft Corp." <azurefunctions@microsoft.com>
6
+ Project-URL: Documentation, https://github.com/Azure/azure-functions-python-worker/blob/dev/azure_functions_runtime/README.md
7
+ Project-URL: Repository, https://github.com/Azure/azure-functions-python-worker
8
+ Keywords: azure,functions,azurefunctions,python,serverless
9
+ Classifier: Development Status :: 5 - Production/Stable
10
+ Classifier: Programming Language :: Python
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.13
13
+ Classifier: Operating System :: Microsoft :: Windows
14
+ Classifier: Operating System :: POSIX
15
+ Classifier: Operating System :: MacOS :: MacOS X
16
+ Classifier: Environment :: Web Environment
17
+ Classifier: License :: OSI Approved :: MIT License
18
+ Classifier: Intended Audience :: Developers
19
+ Requires-Python: >=3.13
20
+ Description-Content-Type: text/markdown
21
+ Requires-Dist: azurefunctions-extensions-base
22
+ Requires-Dist: azure-functions
23
+ Provides-Extra: dev
24
+ Requires-Dist: azure-monitor-opentelemetry; extra == "dev"
25
+ Requires-Dist: flake8==6.*; extra == "dev"
26
+ Requires-Dist: mypy; extra == "dev"
27
+ Requires-Dist: pytest; extra == "dev"
28
+ Requires-Dist: requests==2.*; extra == "dev"
29
+ Requires-Dist: coverage; extra == "dev"
30
+ Requires-Dist: grpcio~=1.70.0; extra == "dev"
31
+ Requires-Dist: grpcio-tools~=1.70.0; extra == "dev"
32
+ Requires-Dist: protobuf~=5.29.0; extra == "dev"
33
+ Requires-Dist: pytest-sugar; extra == "dev"
34
+ Requires-Dist: pytest-cov; extra == "dev"
35
+ Requires-Dist: pytest-xdist; extra == "dev"
36
+ Requires-Dist: pytest-randomly; extra == "dev"
37
+ Requires-Dist: pytest-instafail; extra == "dev"
38
+ Requires-Dist: pytest-rerunfailures; extra == "dev"
39
+ Requires-Dist: pytest-asyncio; extra == "dev"
40
+ Requires-Dist: pre-commit; extra == "dev"
41
+ Requires-Dist: invoke; extra == "dev"
42
+ Provides-Extra: test-http-v2
43
+ Requires-Dist: azurefunctions-extensions-http-fastapi==1.0.0; extra == "test-http-v2"
44
+ Requires-Dist: ujson; extra == "test-http-v2"
45
+ Requires-Dist: orjson; extra == "test-http-v2"
46
+ Provides-Extra: test-deferred-bindings
47
+ Requires-Dist: azurefunctions-extensions-bindings-blob==1.0.0; extra == "test-deferred-bindings"
48
+ Requires-Dist: azurefunctions-extensions-bindings-eventhub==1.0.0b1; extra == "test-deferred-bindings"
49
+
50
+ # <img src="https://raw.githubusercontent.com/Azure/azure-functions-python-worker/dev/docs/Azure.Functions.svg" width = "30" alt="Functions Header Image - Lightning Logo"> Azure Functions Python Worker
51
+
52
+ | Branch | Build Status | CodeCov | Test Status |
53
+ |--------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
54
+ | dev | [![Build Status](https://img.shields.io/azure-devops/build/azfunc/public/658/dev)](https://azfunc.visualstudio.com/public/_build/latest?definitionId=658&branchName=dev) | [![codecov](https://codecov.io/gh/Azure/azure-functions-python-worker/branch/dev/graph/badge.svg)](https://codecov.io/gh/Azure/azure-functions-python-worker) | [![Test Status](https://img.shields.io/azure-devops/build/azfunc/public/658/dev)](https://azfunc.visualstudio.com/public/_build/latest?definitionId=658&branchName=dev) |
55
+
56
+ Python support for Azure Functions is based on Python 3.13 serverless hosting on Linux and the Functions 4.0 runtime.
57
+
58
+ Here is the current status of Python in Azure Functions:
59
+
60
+ What are the supported Python versions?
61
+
62
+ | Azure Functions Runtime | Python 3.13 |
63
+ |----------------------------------|-------------|
64
+ | Azure Functions 4.0 | ✔ |
65
+
66
+ For information about Azure Functions Runtime, please refer to [Azure Functions runtime versions overview](https://docs.microsoft.com/en-us/azure/azure-functions/functions-versions) page.
67
+
68
+ ### What's available?
69
+
70
+ - Build, test, debug, and publish using Azure Functions Core Tools (CLI) or Visual Studio Code
71
+ - Deploy Python Function project onto consumption, dedicated, elastic premium, or flex consumption plan.
72
+ - Deploy Python Function project in a custom docker image onto dedicated or elastic premium plan.
73
+ - Triggers / Bindings : Blob, Cosmos DB, Event Grid, Event Hub, HTTP, Kafka, MySQL, Queue, ServiceBus, SQL, Timer, and Warmup
74
+ - Triggers / Bindings : Custom binding support
75
+
76
+ ### What's new?
77
+
78
+ - [SDK Type Bindings for Blob](https://techcommunity.microsoft.com/t5/azure-compute-blog/azure-functions-sdk-type-bindings-for-azure-blob-storage-with/ba-p/4146744)
79
+ - [HTTP Streaming](https://techcommunity.microsoft.com/t5/azure-compute-blog/azure-functions-support-for-http-streams-in-python-is-now-in/ba-p/4146697)
80
+
81
+ ### Get Started
82
+
83
+ - [Create your first Python function](https://docs.microsoft.com/en-us/azure/azure-functions/functions-create-first-function-python)
84
+ - [Developer guide](https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-python)
85
+ - [Binding API reference](https://docs.microsoft.com/en-us/python/api/azure-functions/azure.functions?view=azure-python)
86
+ - [Develop using VS Code](https://docs.microsoft.com/en-us/azure/azure-functions/functions-create-first-function-vs-code)
87
+ - [Create a Python Function on Linux using a custom docker image](https://docs.microsoft.com/en-us/azure/azure-functions/functions-create-function-linux-custom-image)
88
+
89
+ # Give Feedback
90
+
91
+ Issues and feature requests are tracked in a variety of places. To report this feedback, please file an issue to the relevant repository below:
92
+
93
+ | Item | Description | Link |
94
+ |---------------|----------------------------------------------|--------------------------------------------------------------------------------|
95
+ | Python Worker | Programming Model, Triggers & Bindings | [File an Issue](https://github.com/Azure/azure-functions-python-worker/issues) |
96
+ | Runtime | Script Host & Language Extensibility | [File an Issue](https://github.com/Azure/azure-functions-host/issues) |
97
+ | VSCode | VSCode Extension for Azure Functions | [File an Issue](https://github.com/microsoft/vscode-azurefunctions/issues) |
98
+ | Core Tools | Command Line Interface for Local Development | [File an Issue](https://github.com/Azure/azure-functions-core-tools/issues) |
99
+ | Templates | Code Issues with Creation Template | [File an Issue](https://github.com/Azure/azure-functions-templates/issues) |
100
+
101
+ # Contribute
102
+
103
+ This project welcomes contributions and suggestions. Most contributions require you to agree to a
104
+ Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
105
+ the rights to use your contribution. For details, visit https://cla.microsoft.com.
106
+
107
+ Here are some pointers to get started:
108
+
109
+ - [Language worker architecture](https://github.com/Azure/azure-functions-python-worker/wiki/Worker-Architecture)
110
+ - [Setting up the development environment](https://github.com/Azure/azure-functions-python-worker/wiki/Contributor-Guide)
111
+ - [Adding support for a new binding](https://github.com/Azure/azure-functions-python-worker/wiki/Adding-support-for-a-new-binding-type)
112
+ - [Release instructions](https://github.com/Azure/azure-functions-python-worker/wiki/Release-Instructions)
113
+
114
+ When you submit a pull request, a CLA-bot will automatically determine whether you need to provide
115
+ a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions
116
+ provided by the bot. You will only need to do this once across all repos using our CLA.
117
+
118
+ This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
119
+ For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
120
+ contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
@@ -0,0 +1,71 @@
1
+ # <img src="https://raw.githubusercontent.com/Azure/azure-functions-python-worker/dev/docs/Azure.Functions.svg" width = "30" alt="Functions Header Image - Lightning Logo"> Azure Functions Python Worker
2
+
3
+ | Branch | Build Status | CodeCov | Test Status |
4
+ |--------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
5
+ | dev | [![Build Status](https://img.shields.io/azure-devops/build/azfunc/public/658/dev)](https://azfunc.visualstudio.com/public/_build/latest?definitionId=658&branchName=dev) | [![codecov](https://codecov.io/gh/Azure/azure-functions-python-worker/branch/dev/graph/badge.svg)](https://codecov.io/gh/Azure/azure-functions-python-worker) | [![Test Status](https://img.shields.io/azure-devops/build/azfunc/public/658/dev)](https://azfunc.visualstudio.com/public/_build/latest?definitionId=658&branchName=dev) |
6
+
7
+ Python support for Azure Functions is based on Python 3.13 serverless hosting on Linux and the Functions 4.0 runtime.
8
+
9
+ Here is the current status of Python in Azure Functions:
10
+
11
+ What are the supported Python versions?
12
+
13
+ | Azure Functions Runtime | Python 3.13 |
14
+ |----------------------------------|-------------|
15
+ | Azure Functions 4.0 | ✔ |
16
+
17
+ For information about Azure Functions Runtime, please refer to [Azure Functions runtime versions overview](https://docs.microsoft.com/en-us/azure/azure-functions/functions-versions) page.
18
+
19
+ ### What's available?
20
+
21
+ - Build, test, debug, and publish using Azure Functions Core Tools (CLI) or Visual Studio Code
22
+ - Deploy Python Function project onto consumption, dedicated, elastic premium, or flex consumption plan.
23
+ - Deploy Python Function project in a custom docker image onto dedicated or elastic premium plan.
24
+ - Triggers / Bindings : Blob, Cosmos DB, Event Grid, Event Hub, HTTP, Kafka, MySQL, Queue, ServiceBus, SQL, Timer, and Warmup
25
+ - Triggers / Bindings : Custom binding support
26
+
27
+ ### What's new?
28
+
29
+ - [SDK Type Bindings for Blob](https://techcommunity.microsoft.com/t5/azure-compute-blog/azure-functions-sdk-type-bindings-for-azure-blob-storage-with/ba-p/4146744)
30
+ - [HTTP Streaming](https://techcommunity.microsoft.com/t5/azure-compute-blog/azure-functions-support-for-http-streams-in-python-is-now-in/ba-p/4146697)
31
+
32
+ ### Get Started
33
+
34
+ - [Create your first Python function](https://docs.microsoft.com/en-us/azure/azure-functions/functions-create-first-function-python)
35
+ - [Developer guide](https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-python)
36
+ - [Binding API reference](https://docs.microsoft.com/en-us/python/api/azure-functions/azure.functions?view=azure-python)
37
+ - [Develop using VS Code](https://docs.microsoft.com/en-us/azure/azure-functions/functions-create-first-function-vs-code)
38
+ - [Create a Python Function on Linux using a custom docker image](https://docs.microsoft.com/en-us/azure/azure-functions/functions-create-function-linux-custom-image)
39
+
40
+ # Give Feedback
41
+
42
+ Issues and feature requests are tracked in a variety of places. To report this feedback, please file an issue to the relevant repository below:
43
+
44
+ | Item | Description | Link |
45
+ |---------------|----------------------------------------------|--------------------------------------------------------------------------------|
46
+ | Python Worker | Programming Model, Triggers & Bindings | [File an Issue](https://github.com/Azure/azure-functions-python-worker/issues) |
47
+ | Runtime | Script Host & Language Extensibility | [File an Issue](https://github.com/Azure/azure-functions-host/issues) |
48
+ | VSCode | VSCode Extension for Azure Functions | [File an Issue](https://github.com/microsoft/vscode-azurefunctions/issues) |
49
+ | Core Tools | Command Line Interface for Local Development | [File an Issue](https://github.com/Azure/azure-functions-core-tools/issues) |
50
+ | Templates | Code Issues with Creation Template | [File an Issue](https://github.com/Azure/azure-functions-templates/issues) |
51
+
52
+ # Contribute
53
+
54
+ This project welcomes contributions and suggestions. Most contributions require you to agree to a
55
+ Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
56
+ the rights to use your contribution. For details, visit https://cla.microsoft.com.
57
+
58
+ Here are some pointers to get started:
59
+
60
+ - [Language worker architecture](https://github.com/Azure/azure-functions-python-worker/wiki/Worker-Architecture)
61
+ - [Setting up the development environment](https://github.com/Azure/azure-functions-python-worker/wiki/Contributor-Guide)
62
+ - [Adding support for a new binding](https://github.com/Azure/azure-functions-python-worker/wiki/Adding-support-for-a-new-binding-type)
63
+ - [Release instructions](https://github.com/Azure/azure-functions-python-worker/wiki/Release-Instructions)
64
+
65
+ When you submit a pull request, a CLA-bot will automatically determine whether you need to provide
66
+ a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions
67
+ provided by the bot. You will only need to do this once across all repos using our CLA.
68
+
69
+ This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
70
+ For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
71
+ contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
@@ -0,0 +1,21 @@
1
+ # Copyright (c) Microsoft Corporation. All rights reserved.
2
+ # Licensed under the MIT License.
3
+ from .handle_event import (worker_init_request,
4
+ functions_metadata_request,
5
+ function_environment_reload_request,
6
+ invocation_request,
7
+ function_load_request)
8
+ from .utils.threadpool import (
9
+ start_threadpool_executor,
10
+ stop_threadpool_executor,
11
+ get_threadpool_executor,
12
+ )
13
+
14
+ __all__ = ('worker_init_request',
15
+ 'functions_metadata_request',
16
+ 'function_environment_reload_request',
17
+ 'invocation_request',
18
+ 'function_load_request',
19
+ 'start_threadpool_executor',
20
+ 'stop_threadpool_executor',
21
+ 'get_threadpool_executor')
@@ -0,0 +1,66 @@
1
+ # Copyright (c) Microsoft Corporation. All rights reserved.
2
+ # Licensed under the MIT License.
3
+ import threading
4
+
5
+ from .retrycontext import RetryContext
6
+ from .tracecontext import TraceContext
7
+
8
+
9
+ class Context:
10
+ def __init__(self,
11
+ func_name: str,
12
+ func_dir: str,
13
+ invocation_id: str,
14
+ thread_local_storage: threading.local,
15
+ trace_context: TraceContext,
16
+ retry_context: RetryContext) -> None:
17
+ self.__func_name = func_name
18
+ self.__func_dir = func_dir
19
+ self.__invocation_id = invocation_id
20
+ self.__thread_local_storage = thread_local_storage
21
+ self.__trace_context = trace_context
22
+ self.__retry_context = retry_context
23
+
24
+ @property
25
+ def invocation_id(self) -> str:
26
+ return self.__invocation_id
27
+
28
+ @property
29
+ def thread_local_storage(self) -> threading.local:
30
+ return self.__thread_local_storage
31
+
32
+ @property
33
+ def function_name(self) -> str:
34
+ return self.__func_name
35
+
36
+ @property
37
+ def function_directory(self) -> str:
38
+ return self.__func_dir
39
+
40
+ @property
41
+ def trace_context(self) -> TraceContext:
42
+ return self.__trace_context
43
+
44
+ @property
45
+ def retry_context(self) -> RetryContext:
46
+ return self.__retry_context
47
+
48
+
49
+ def get_context(invoc_request, name: str,
50
+ directory: str) -> Context:
51
+ """ For more information refer:
52
+ https://aka.ms/azfunc-invocation-context
53
+ """
54
+ trace_context = TraceContext(
55
+ invoc_request.trace_context.trace_parent,
56
+ invoc_request.trace_context.trace_state,
57
+ invoc_request.trace_context.attributes)
58
+
59
+ retry_context = RetryContext(
60
+ invoc_request.retry_context.retry_count,
61
+ invoc_request.retry_context.max_retry_count,
62
+ invoc_request.retry_context.exception)
63
+
64
+ return Context(
65
+ name, directory, invoc_request.invocation_id,
66
+ threading.local(), trace_context, retry_context)
@@ -0,0 +1,232 @@
1
+ # Copyright (c) Microsoft Corporation. All rights reserved.
2
+ # Licensed under the MIT License.
3
+ import json
4
+ import logging
5
+
6
+ from datetime import datetime
7
+ from typing import Any, List, Optional
8
+
9
+ from .nullable_converters import (
10
+ to_nullable_bool,
11
+ to_nullable_double,
12
+ to_nullable_string,
13
+ to_nullable_timestamp,
14
+ )
15
+
16
+ try:
17
+ from http.cookies import SimpleCookie
18
+ except ImportError:
19
+ from Cookie import SimpleCookie # type: ignore
20
+
21
+
22
+ class Datum:
23
+ def __init__(self, value, type):
24
+ self.value = value
25
+ self.type = type
26
+
27
+ @property
28
+ def python_value(self) -> Any:
29
+ if self.value is None or self.type is None:
30
+ return None
31
+ elif self.type in ('bytes', 'string', 'int', 'double'):
32
+ return self.value
33
+ elif self.type == 'json':
34
+ return json.loads(self.value)
35
+ elif self.type == 'collection_string':
36
+ return [v for v in self.value.string]
37
+ elif self.type == 'collection_bytes':
38
+ return [v for v in self.value.bytes]
39
+ elif self.type == 'collection_double':
40
+ return [v for v in self.value.double]
41
+ elif self.type == 'collection_sint64':
42
+ return [v for v in self.value.sint64]
43
+ else:
44
+ return self.value
45
+
46
+ @property
47
+ def python_type(self) -> type:
48
+ return type(self.python_value)
49
+
50
+ def __eq__(self, other):
51
+ if not isinstance(other, type(self)):
52
+ return False
53
+
54
+ return self.value == other.value and self.type == other.type
55
+
56
+ def __hash__(self):
57
+ return hash((type(self), (self.value, self.type)))
58
+
59
+ def __repr__(self):
60
+ val_repr = repr(self.value)
61
+ if len(val_repr) > 10:
62
+ val_repr = val_repr[:10] + '...'
63
+ return '<Datum ' + str(self.type) + val_repr + '>'
64
+
65
+ @classmethod
66
+ def from_typed_data(cls, protos):
67
+ try:
68
+ td = protos.TypedData
69
+ except Exception:
70
+ td = protos
71
+ tt = td.WhichOneof('data')
72
+ if tt == 'http':
73
+ http = td.http
74
+ val = dict(
75
+ method=Datum(http.method, 'string'),
76
+ url=Datum(http.url, 'string'),
77
+ headers={
78
+ k: Datum(v, 'string') for k, v in http.headers.items()
79
+ },
80
+ body=(
81
+ Datum.from_typed_data(http.body)
82
+ or Datum(type='bytes', value=b'')
83
+ ),
84
+ params={
85
+ k: Datum(v, 'string') for k, v in http.params.items()
86
+ },
87
+ query={
88
+ k: Datum(v, 'string') for k, v in http.query.items()
89
+ },
90
+ )
91
+ elif tt == 'string':
92
+ val = td.string
93
+ elif tt == 'bytes':
94
+ val = td.bytes
95
+ elif tt == 'json':
96
+ val = td.json
97
+ elif tt == 'collection_bytes':
98
+ val = td.collection_bytes
99
+ elif tt == 'collection_string':
100
+ val = td.collection_string
101
+ elif tt == 'collection_sint64':
102
+ val = td.collection_sint64
103
+ elif tt == 'model_binding_data':
104
+ val = td.model_binding_data
105
+ elif tt == 'collection_model_binding_data':
106
+ val = td.collection_model_binding_data
107
+ elif tt is None:
108
+ return None
109
+ else:
110
+ raise NotImplementedError(
111
+ 'unsupported TypeData kind: %s' % tt
112
+ )
113
+
114
+ return cls(val, tt)
115
+
116
+
117
+ def datum_as_proto(datum: Datum, protos):
118
+ if datum.type == 'string':
119
+ return protos.TypedData(string=datum.value)
120
+ elif datum.type == 'bytes':
121
+ return protos.TypedData(bytes=datum.value)
122
+ elif datum.type == 'json':
123
+ return protos.TypedData(json=datum.value)
124
+ elif datum.type == 'http':
125
+ return protos.TypedData(http=protos.RpcHttp(
126
+ status_code=datum.value['status_code'].value,
127
+ headers={
128
+ k: v.value
129
+ for k, v in datum.value['headers'].items()
130
+ },
131
+ cookies=parse_to_rpc_http_cookie_list(datum.value.get('cookies'), protos),
132
+ enable_content_negotiation=False,
133
+ body=datum_as_proto(datum.value['body'], protos),
134
+ ))
135
+ elif datum.type is None:
136
+ return None
137
+ elif datum.type == 'dict':
138
+ # TypedData doesn't support dict, so we return it as json
139
+ return protos.TypedData(json=json.dumps(datum.value))
140
+ elif datum.type == 'list':
141
+ # TypedData doesn't support list, so we return it as json
142
+ return protos.TypedData(json=json.dumps(datum.value))
143
+ elif datum.type == 'int':
144
+ return protos.TypedData(int=datum.value)
145
+ elif datum.type == 'double':
146
+ return protos.TypedData(double=datum.value)
147
+ elif datum.type == 'bool':
148
+ # TypedData doesn't support bool, so we return it as an int
149
+ return protos.TypedData(int=int(datum.value))
150
+ else:
151
+ raise NotImplementedError(
152
+ 'unexpected Datum type: %s' % datum.type
153
+ )
154
+
155
+
156
+ def parse_to_rpc_http_cookie_list(cookies: Optional[List[SimpleCookie]], protos):
157
+ if cookies is None:
158
+ return cookies
159
+
160
+ rpc_http_cookies = []
161
+
162
+ for cookie in cookies:
163
+ for name, cookie_entity in cookie.items():
164
+ rpc_http_cookies.append(
165
+ protos.RpcHttpCookie(name=name,
166
+ value=cookie_entity.value,
167
+ domain=to_nullable_string(
168
+ cookie_entity['domain'],
169
+ 'cookie.domain',
170
+ protos),
171
+ path=to_nullable_string(
172
+ cookie_entity['path'],
173
+ 'cookie.path',
174
+ protos),
175
+ expires=to_nullable_timestamp(
176
+ parse_cookie_attr_expires(
177
+ cookie_entity), 'cookie.expires',
178
+ protos),
179
+ secure=to_nullable_bool(
180
+ bool(cookie_entity['secure']),
181
+ 'cookie.secure',
182
+ protos),
183
+ http_only=to_nullable_bool(
184
+ bool(cookie_entity['httponly']),
185
+ 'cookie.httpOnly',
186
+ protos),
187
+ same_site=parse_cookie_attr_same_site(
188
+ cookie_entity, protos),
189
+ max_age=to_nullable_double(
190
+ cookie_entity['max-age'],
191
+ 'cookie.maxAge',
192
+ protos)))
193
+
194
+ return rpc_http_cookies
195
+
196
+
197
+ def parse_cookie_attr_expires(cookie_entity):
198
+ expires = cookie_entity['expires']
199
+
200
+ if expires is not None and len(expires) != 0:
201
+ try:
202
+ return datetime.strptime(expires, "%a, %d %b %Y %H:%M:%S GMT")
203
+ except ValueError:
204
+ logging.error(
205
+ "Can not parse value %s of expires in the cookie "
206
+ "due to invalid format.", expires)
207
+ raise
208
+ except OverflowError:
209
+ logging.error(
210
+ "Can not parse value %s of expires in the cookie "
211
+ "because the parsed date exceeds the largest valid C "
212
+ "integer on your system.", expires)
213
+ raise
214
+
215
+ return None
216
+
217
+
218
+ def parse_cookie_attr_same_site(cookie_entity, protos):
219
+ same_site = getattr(protos.RpcHttpCookie.SameSite, "None")
220
+ try:
221
+ raw_same_site_str = cookie_entity['samesite'].lower()
222
+
223
+ if raw_same_site_str == 'lax':
224
+ same_site = protos.RpcHttpCookie.SameSite.Lax
225
+ elif raw_same_site_str == 'strict':
226
+ same_site = protos.RpcHttpCookie.SameSite.Strict
227
+ elif raw_same_site_str == 'none':
228
+ same_site = protos.RpcHttpCookie.SameSite.ExplicitNone
229
+ except Exception:
230
+ return same_site
231
+
232
+ return same_site
@@ -0,0 +1,75 @@
1
+ # Copyright (c) Microsoft Corporation. All rights reserved.
2
+ # Licensed under the MIT License.
3
+ import typing
4
+
5
+ from typing import Any, Optional
6
+
7
+ from .datumdef import Datum
8
+
9
+
10
+ class GenericBinding:
11
+
12
+ @classmethod
13
+ def has_trigger_support(cls) -> bool:
14
+ return False
15
+
16
+ @classmethod
17
+ def check_input_type_annotation(cls, pytype: type) -> bool:
18
+ return issubclass(pytype, (str, bytes))
19
+
20
+ @classmethod
21
+ def check_output_type_annotation(cls, pytype: type) -> bool:
22
+ return issubclass(pytype, (str, bytes, bytearray))
23
+
24
+ @classmethod
25
+ def encode(cls, obj: Any, *,
26
+ expected_type: Optional[type]) -> Datum:
27
+ if isinstance(obj, str):
28
+ return Datum(type='string', value=obj)
29
+
30
+ elif isinstance(obj, (bytes, bytearray)):
31
+ return Datum(type='bytes', value=bytes(obj))
32
+ elif obj is None:
33
+ return Datum(type=None, value=obj)
34
+ elif isinstance(obj, dict):
35
+ return Datum(type='dict', value=obj)
36
+ elif isinstance(obj, list):
37
+ return Datum(type='list', value=obj)
38
+ elif isinstance(obj, int):
39
+ return Datum(type='int', value=obj)
40
+ elif isinstance(obj, float):
41
+ return Datum(type='double', value=obj)
42
+ elif isinstance(obj, bool):
43
+ return Datum(type='bool', value=obj)
44
+ else:
45
+ raise NotImplementedError
46
+
47
+ @classmethod
48
+ def decode(cls, data: Datum, *, trigger_metadata) -> typing.Any:
49
+ # Enabling support for Dapr bindings
50
+ # https://github.com/Azure/azure-functions-python-worker/issues/1316
51
+ if data is None:
52
+ return None
53
+ data_type = data.type
54
+
55
+ if data_type == 'string':
56
+ result = data.value
57
+ elif data_type == 'bytes':
58
+ result = data.value
59
+ elif data_type == 'json':
60
+ result = data.value
61
+ elif data_type is None:
62
+ result = None
63
+ else:
64
+ raise ValueError(
65
+ 'unexpected type of data received for the "generic" binding ',
66
+ repr(data_type)
67
+ )
68
+
69
+ return result
70
+
71
+ @classmethod
72
+ def has_implicit_output(cls, bind_name: Optional[str]) -> bool:
73
+ if bind_name == 'durableClient':
74
+ return False
75
+ return True