1+ # -*- coding: utf-8 -*-
2+
13"""
24Copyright 2023 The Dapr Authors
35Licensed under the Apache License, Version 2.0 (the "License");
@@ -70,6 +72,7 @@ def get_metadata(self, as_dict: bool = False) -> Union[MetadataDict, MetadataTup
7072 return tuple_to_dict (self ._metadata )
7173 return self ._metadata
7274
75+
7376class InvokeMethodRequest (DaprRequest ):
7477 """A request data representation for invoke_method API.
7578
@@ -103,10 +106,10 @@ def __init__(
103106 Raises:
104107 ValueError: data is not supported.
105108 """
106- super ().__init__ (())
109+ super (InvokeMethodRequest , self ).__init__ (())
107110
108111 self ._content_type = content_type
109- self ._http_verb = None
112+ self ._http_verb : Optional [ str ] = None
110113 self ._http_querystring : Dict [str , str ] = {}
111114
112115 self .set_data (data )
@@ -124,7 +127,7 @@ def http_verb(self) -> Optional[str]:
124127 @http_verb .setter
125128 def http_verb (self , val : Optional [str ]) -> None :
126129 """Sets HTTP method to Dapr invocation request."""
127- if val not in self .HTTP_METHODS :
130+ if val is not None and val not in self .HTTP_METHODS :
128131 raise ValueError (f'{ val } is the invalid HTTP verb.' )
129132 self ._http_verb = val
130133
@@ -213,6 +216,7 @@ def content_type(self, val: Optional[str]) -> None:
213216 """Sets content type for bytes data."""
214217 self ._content_type = val
215218
219+
216220class BindingRequest (DaprRequest ):
217221 """A request data representation for invoke_binding API.
218222
@@ -224,7 +228,7 @@ class BindingRequest(DaprRequest):
224228 metadata (Dict[str, str]): the metadata sent to the binding.
225229 """
226230
227- def __init__ (self , data : Union [str , bytes ], binding_metadata : Optional [ Dict [str , str ]] = None ):
231+ def __init__ (self , data : Union [str , bytes ], binding_metadata : Dict [str , str ] = {} ):
228232 """Inits BindingRequest with data and metadata if given.
229233
230234 Args:
@@ -234,9 +238,9 @@ def __init__(self, data: Union[str, bytes], binding_metadata: Optional[Dict[str,
234238 Raises:
235239 ValueError: data is not bytes or str.
236240 """
237- super ().__init__ (())
241+ super (BindingRequest , self ).__init__ (())
238242 self .data = data # type: ignore
239- self ._binding_metadata = binding_metadata or {}
243+ self ._binding_metadata = binding_metadata
240244
241245 @property
242246 def data (self ) -> bytes :
@@ -257,12 +261,14 @@ def binding_metadata(self):
257261 """Gets the metadata for output binding."""
258262 return self ._binding_metadata
259263
264+
260265class TransactionOperationType (Enum ):
261266 """Represents the type of operation for a Dapr Transaction State Api Call"""
262267
263268 upsert = 'upsert'
264269 delete = 'delete'
265270
271+
266272class TransactionalStateOperation :
267273 """An upsert or delete operation for a state transaction, 'upsert' by default.
268274
@@ -279,6 +285,7 @@ def __init__(
279285 data : Optional [Union [bytes , str ]] = None ,
280286 etag : Optional [str ] = None ,
281287 operation_type : TransactionOperationType = TransactionOperationType .upsert ,
288+ metadata : Optional [Dict [str , str ]] = None ,
282289 ):
283290 """Initializes TransactionalStateOperation item from
284291 :obj:`runtime_v1.TransactionalStateOperation`.
@@ -299,6 +306,7 @@ def __init__(
299306 self ._data = data # type: ignore
300307 self ._etag = etag
301308 self ._operation_type = operation_type
309+ self ._metadata = metadata
302310
303311 @property
304312 def key (self ) -> str :
@@ -320,6 +328,12 @@ def operation_type(self) -> TransactionOperationType:
320328 """Gets etag."""
321329 return self ._operation_type
322330
331+ @property
332+ def metadata (self ) -> Dict [str , str ]:
333+ """Gets metadata."""
334+ return {} if self ._metadata is None else self ._metadata
335+
336+
323337class EncryptRequestIterator (DaprRequest ):
324338 """An iterator for cryptography encrypt API requests.
325339
@@ -366,6 +380,7 @@ def __next__(self):
366380 self .seq += 1
367381 return request_proto
368382
383+
369384class DecryptRequestIterator (DaprRequest ):
370385 """An iterator for cryptography decrypt API requests.
371386
0 commit comments