1212# License for the specific language governing permissions and limitations
1313# under the License.
1414
15- import copy
1615import datetime
1716import json
18- import io
1917import typing
2018import uuid
2119
2220from cloudevents .sdk import converters
2321from cloudevents .sdk import marshaller
2422from cloudevents .sdk import types
25- from cloudevents .sdk .converters import binary
26- from cloudevents .sdk .converters import structured
2723
2824from cloudevents .sdk .event import v03 , v1
2925
30- _marshaller_by_format = {converters .TypeStructured : lambda x : x ,
31- converters .TypeBinary : json .dumps }
32- _required_by_version = {"1.0" : v1 .Event ._ce_required_fields ,
33- "0.3" : v03 .Event ._ce_required_fields }
26+ _marshaller_by_format = {
27+ converters .TypeStructured : lambda x : x ,
28+ converters .TypeBinary : json .dumps ,
29+ }
30+ _required_by_version = {
31+ "1.0" : v1 .Event ._ce_required_fields ,
32+ "0.3" : v03 .Event ._ce_required_fields ,
33+ }
3434_obj_by_version = {"1.0" : v1 .Event , "0.3" : v03 .Event }
3535
3636
@@ -61,7 +61,7 @@ def from_http(
6161 :type data: typing.IO
6262 :param headers: the HTTP headers
6363 :type headers: typing.Dict[str, str]
64- :param data_unmarshaller: A function to decode data into a python object.
64+ :param data_unmarshaller: Function to decode data into a python object.
6565 :type data_unmarshaller: types.UnmarshallerType
6666 """
6767 if data_unmarshaller is None :
@@ -76,7 +76,11 @@ def from_http(
7676
7777 return cls (attrs , event .data )
7878
79- def __init__ (self , attributes : typing .Dict [str , str ], data : typing .Any = None ):
79+ def __init__ (
80+ self ,
81+ attributes : typing .Dict [str , str ],
82+ data : typing .Any = None
83+ ):
8084 """
8185 Event Constructor
8286 :param attributes: a dict with HTTP headers
@@ -104,7 +108,8 @@ def __init__(self, attributes: typing.Dict[str, str], data: typing.Any = None):
104108 if self ._attributes ['specversion' ] not in _required_by_version :
105109 raise ValueError (
106110 f"Invalid specversion: { self ._attributes ['specversion' ]} " )
107- # There is no good way to default 'source' and 'type', so this checks for those.
111+ # There is no good way to default 'source' and 'type', so this
112+ # checks for those (or any new required attributes).
108113 required_set = _required_by_version [self ._attributes ['specversion' ]]
109114 if not required_set <= self ._attributes .keys ():
110115 raise ValueError (
@@ -120,7 +125,7 @@ def to_http(
120125
121126 :param format: constant specifying an encoding format
122127 :type format: str
123- :param data_unmarshaller: callable function used to read the data io object
128+ :param data_unmarshaller: Function used to read the data to string.
124129 :type data_unmarshaller: types.UnmarshallerType
125130 :returns: (http_headers: dict, http_body: bytes or str)
126131 """
@@ -135,7 +140,8 @@ def to_http(
135140 event .Set (k , v )
136141 event .data = self .data
137142
138- return marshaller .NewDefaultHTTPMarshaller ().ToRequest (event , format , data_marshaller )
143+ return marshaller .NewDefaultHTTPMarshaller ().ToRequest (
144+ event , format , data_marshaller )
139145
140146 # Data access is handled via `.data` member
141147 # Attribute access is managed via Mapping type
0 commit comments