Skip to content

Commit 43bdea7

Browse files
committed
Decouple rich binding support from the worker
Per discussion, the worker no longer includes support for rich bindings by default. The implementation have been moved to azure-functions-python-library, and the runtime dependency on is has been removed.
1 parent a449bbc commit 43bdea7

File tree

30 files changed

+206
-1442
lines changed

30 files changed

+206
-1442
lines changed
+2-14
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,14 @@
11
from .context import Context
22
from .meta import check_input_type_annotation
33
from .meta import check_output_type_annotation
4-
from .meta import is_binding, is_trigger_binding
4+
from .meta import is_trigger_binding
55
from .meta import from_incoming_proto, to_outgoing_proto
66
from .out import Out
77

8-
# Import type implementations and converters
9-
# to get them registered and available:
10-
from . import blob # NoQA
11-
from . import cosmosdb # NoQA
12-
from . import eventgrid # NoQA
13-
from . import eventhub # NoQA
14-
from . import generic # NoQA
15-
from . import http # NoQA
16-
from . import queue # NoQA
17-
from . import servicebus # NoQA
18-
from . import timer # NoQA
19-
208

219
__all__ = (
2210
'Out', 'Context',
23-
'is_binding', 'is_trigger_binding',
11+
'is_trigger_binding',
2412
'check_input_type_annotation', 'check_output_type_annotation',
2513
'from_incoming_proto', 'to_outgoing_proto',
2614
)

azure/functions_worker/bindings/blob.py

-151
This file was deleted.

azure/functions_worker/bindings/context.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
from azure.functions import _abc as azf_abc
2-
3-
4-
class Context(azf_abc.Context):
1+
class Context:
52

63
def __init__(self, func_name: str, func_dir: str,
74
invocation_id: str) -> None:

azure/functions_worker/bindings/cosmosdb.py

-80
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
from .. import protos
2+
3+
4+
class Datum:
5+
def __init__(self, value, type):
6+
self.value = value
7+
self.type = type
8+
9+
def __eq__(self, other):
10+
if not isinstance(other, type(self)):
11+
return False
12+
13+
return self.value == other.value and self.type == other.type
14+
15+
def __hash__(self):
16+
return hash((type(self), (self.value, self.type)))
17+
18+
def __repr__(self):
19+
val_repr = repr(self.value)
20+
if len(val_repr) > 10:
21+
val_repr = val_repr[:10] + '...'
22+
return '<Datum {} {}>'.format(self.type, val_repr)
23+
24+
@classmethod
25+
def from_typed_data(cls, td: protos.TypedData):
26+
tt = td.WhichOneof('data')
27+
if tt == 'http':
28+
http = td.http
29+
val = dict(
30+
method=Datum(http.method, 'string'),
31+
url=Datum(http.url, 'string'),
32+
headers={
33+
k: Datum(v, 'string') for k, v in http.headers.items()
34+
},
35+
body=(
36+
Datum.from_typed_data(http.rawBody)
37+
or Datum(type='bytes', value=b'')
38+
),
39+
params={
40+
k: Datum(v, 'string') for k, v in http.params.items()
41+
},
42+
query={
43+
k: Datum(v, 'string') for k, v in http.query.items()
44+
},
45+
)
46+
elif tt == 'string':
47+
val = td.string
48+
elif tt == 'bytes':
49+
val = td.bytes
50+
elif tt == 'json':
51+
val = td.json
52+
elif tt is None:
53+
return None
54+
else:
55+
raise NotImplementedError(
56+
'unsupported TypeData kind: {!r}'.format(tt)
57+
)
58+
59+
return cls(val, tt)
60+
61+
62+
def datum_as_proto(datum: Datum) -> protos.TypedData:
63+
if datum.type == 'string':
64+
return protos.TypedData(string=datum.value)
65+
elif datum.type == 'bytes':
66+
return protos.TypedData(bytes=datum.value)
67+
elif datum.type == 'json':
68+
return protos.TypedData(json=datum.value)
69+
elif datum.type == 'http':
70+
return protos.TypedData(http=protos.RpcHttp(
71+
status_code=datum.value['status_code'].value,
72+
headers={
73+
k: v.value
74+
for k, v in datum.value['headers'].items()
75+
},
76+
enable_content_negotiation=False,
77+
body=datum_as_proto(datum.value['body']),
78+
))
79+
else:
80+
raise NotImplementedError(
81+
'unexpected Datum type: {!r}'.format(datum.type)
82+
)

azure/functions_worker/bindings/eventgrid.py

-45
This file was deleted.

0 commit comments

Comments
 (0)