-
Notifications
You must be signed in to change notification settings - Fork 107
Add generic binding support #409
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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', | ||
| 'check_input_type_annotation', 'check_output_type_annotation', | ||
| 'from_incoming_proto', 'to_outgoing_proto', | ||
| ) | ||
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| from .. import protos | ||
|
|
||
pragnagopa marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| 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) | ||
| ) | ||
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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'?
There was a problem hiding this comment.
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.)