1212# License for the specific language governing permissions and limitations
1313# under the License.
1414
15-
1615import base64
1716import re
1817from datetime import datetime
1918from json import JSONEncoder , dumps , loads
20- from typing import Any , Callable , Final , Optional , Pattern , Union
19+ from typing import Any , Callable , Final , Pattern
2120
2221from dateutil .parser import isoparse
2322
@@ -51,10 +50,10 @@ class JSONFormat(Format):
5150 def read (
5251 self ,
5352 event_factory : Callable [
54- [dict [str , Any ], Optional [ Union [ dict [str , Any ], str , bytes ]] ],
53+ [dict [str , Any ], dict [str , Any ] | str | bytes | None ],
5554 BaseCloudEvent ,
5655 ],
57- data : Union [ str , bytes ] ,
56+ data : str | bytes ,
5857 ) -> BaseCloudEvent :
5958 """
6059 Read a CloudEvent from a JSON formatted byte string.
@@ -74,7 +73,7 @@ def read(
7473 if "time" in event_attributes :
7574 event_attributes ["time" ] = isoparse (event_attributes ["time" ])
7675
77- event_data : Union [ dict [str , Any ], str , bytes , None ] = event_attributes .pop (
76+ event_data : dict [str , Any ] | str | bytes | None = event_attributes .pop (
7877 "data" , None
7978 )
8079 if event_data is None :
@@ -108,8 +107,8 @@ def write(self, event: BaseCloudEvent) -> bytes:
108107
109108 def write_data (
110109 self ,
111- data : Optional [ Union [ dict [str , Any ], str , bytes ]] ,
112- datacontenttype : Optional [ str ] ,
110+ data : dict [str , Any ] | str | bytes | None ,
111+ datacontenttype : str | None ,
113112 ) -> bytes :
114113 """
115114 Serialize just the data payload for HTTP binary mode.
@@ -143,8 +142,8 @@ def write_data(
143142 return str (data ).encode ("utf-8" )
144143
145144 def read_data (
146- self , body : bytes , datacontenttype : Optional [ str ]
147- ) -> Optional [ Union [ dict [str , Any ], str , bytes ]] :
145+ self , body : bytes , datacontenttype : str | None
146+ ) -> dict [str , Any ] | str | bytes | None :
148147 """
149148 Deserialize data payload from HTTP binary mode body.
150149
0 commit comments