Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 2 additions & 13 deletions azure/functions_worker/bindings/__init__.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,14 @@
from .context import Context
from .meta import check_input_type_annotation
from .meta import check_output_type_annotation
from .meta import is_binding, is_trigger_binding
from .meta import is_trigger_binding
from .meta import from_incoming_proto, to_outgoing_proto
from .out import Out

# Import type implementations and converters
# to get them registered and available:
from . import blob # NoQA
from . import cosmosdb # NoQA
from . import eventgrid # NoQA
from . import eventhub # NoQA
from . import http # NoQA
from . import queue # NoQA
from . import servicebus # NoQA
from . import timer # NoQA


__all__ = (
'Out', 'Context',
'is_binding', 'is_trigger_binding',
'is_trigger_binding',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you need 'is_trigger_binding'?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is used to distinguish regular input bindings from trigger bindings, because there are differences in handling these (metadata, etc.)

'check_input_type_annotation', 'check_output_type_annotation',
'from_incoming_proto', 'to_outgoing_proto',
)
151 changes: 0 additions & 151 deletions azure/functions_worker/bindings/blob.py

This file was deleted.

5 changes: 1 addition & 4 deletions azure/functions_worker/bindings/context.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
from azure.functions import _abc as azf_abc


class Context(azf_abc.Context):
class Context:

def __init__(self, func_name: str, func_dir: str,
invocation_id: str) -> None:
Expand Down
80 changes: 0 additions & 80 deletions azure/functions_worker/bindings/cosmosdb.py

This file was deleted.

82 changes: 82 additions & 0 deletions azure/functions_worker/bindings/datumdef.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
from .. import protos


class Datum:
def __init__(self, value, type):
self.value = value
self.type = type

def __eq__(self, other):
if not isinstance(other, type(self)):
return False

return self.value == other.value and self.type == other.type

def __hash__(self):
return hash((type(self), (self.value, self.type)))

def __repr__(self):
val_repr = repr(self.value)
if len(val_repr) > 10:
val_repr = val_repr[:10] + '...'
return '<Datum {} {}>'.format(self.type, val_repr)

@classmethod
def from_typed_data(cls, td: protos.TypedData):
tt = td.WhichOneof('data')
if tt == 'http':
http = td.http
val = dict(
method=Datum(http.method, 'string'),
url=Datum(http.url, 'string'),
headers={
k: Datum(v, 'string') for k, v in http.headers.items()
},
body=(
Datum.from_typed_data(http.rawBody)
or Datum(type='bytes', value=b'')
),
params={
k: Datum(v, 'string') for k, v in http.params.items()
},
query={
k: Datum(v, 'string') for k, v in http.query.items()
},
)
elif tt == 'string':
val = td.string
elif tt == 'bytes':
val = td.bytes
elif tt == 'json':
val = td.json
elif tt is None:
return None
else:
raise NotImplementedError(
'unsupported TypeData kind: {!r}'.format(tt)
)

return cls(val, tt)


def datum_as_proto(datum: Datum) -> protos.TypedData:
if datum.type == 'string':
return protos.TypedData(string=datum.value)
elif datum.type == 'bytes':
return protos.TypedData(bytes=datum.value)
elif datum.type == 'json':
return protos.TypedData(json=datum.value)
elif datum.type == 'http':
return protos.TypedData(http=protos.RpcHttp(
status_code=datum.value['status_code'].value,
headers={
k: v.value
for k, v in datum.value['headers'].items()
},
enable_content_negotiation=False,
body=datum_as_proto(datum.value['body']),
))
else:
raise NotImplementedError(
'unexpected Datum type: {!r}'.format(datum.type)
)
45 changes: 0 additions & 45 deletions azure/functions_worker/bindings/eventgrid.py

This file was deleted.

Loading