Adding type info to Converter interface.

Signed-off-by: Evan Anderson <argent@google.com>
This commit is contained in:
Evan Anderson 2019-01-14 00:21:49 +00:00
parent d90a4861f9
commit 47873fbca1
3 changed files with 6 additions and 6 deletions

View File

@ -25,10 +25,10 @@ class Converter(object):
data_unmarshaller: typing.Callable) -> base.BaseEvent:
raise Exception("not implemented")
def event_supported(self, event):
def event_supported(self, event: object) -> bool:
raise Exception("not implemented")
def can_read(self, content_type):
def can_read(self, content_type: str) -> bool:
raise Exception("not implemented")
def write(self, event: base.BaseEvent,

View File

@ -25,10 +25,10 @@ class BinaryHTTPCloudEventConverter(base.Converter):
TYPE = "binary"
SUPPORTED_VERSIONS = [v02.Event, ]
def can_read(self, content_type):
def can_read(self, content_type: str) -> bool:
return True
def event_supported(self, event):
def event_supported(self, event: object) -> bool:
return type(event) in self.SUPPORTED_VERSIONS
def read(self,

View File

@ -23,10 +23,10 @@ class JSONHTTPCloudEventConverter(base.Converter):
TYPE = "structured"
MIME_TYPE = "application/cloudevents+json"
def can_read(self, content_type):
def can_read(self, content_type: str) -> bool:
return content_type and content_type.startswith(self.MIME_TYPE)
def event_supported(self, event):
def event_supported(self, event: object) -> bool:
# structured format supported by both spec 0.1 and 0.2
return True