aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/python/grpcio/grpc/aio/_metadata.py21
1 files changed, 19 insertions, 2 deletions
diff --git a/src/python/grpcio/grpc/aio/_metadata.py b/src/python/grpcio/grpc/aio/_metadata.py
index 230cb0df78..6303c17529 100644
--- a/src/python/grpcio/grpc/aio/_metadata.py
+++ b/src/python/grpcio/grpc/aio/_metadata.py
@@ -14,13 +14,13 @@
"""Implementation of the metadata abstraction for gRPC Asyncio Python."""
from collections import OrderedDict
from collections import abc
-from typing import Any, Iterator, List, Tuple, Union
+from typing import Any, Iterator, List, Optional, Tuple, Union
MetadataKey = str
MetadataValue = Union[str, bytes]
-class Metadata(abc.Mapping):
+class Metadata(abc.Collection):
"""Metadata abstraction for the asynchronous calls and interceptors.
The metadata is a mapping from str -> List[str]
@@ -89,6 +89,23 @@ class Metadata(abc.Mapping):
for value in values:
yield (key, value)
+ def keys(self) -> abc.KeysView:
+ return abc.KeysView(self)
+
+ def values(self) -> abc.ValuesView:
+ return abc.ValuesView(self)
+
+ def items(self) -> abc.ItemsView:
+ return abc.ItemsView(self)
+
+ def get(
+ self, key: MetadataKey, default: MetadataValue = None
+ ) -> Optional[MetadataValue]:
+ try:
+ return self[key]
+ except KeyError:
+ return default
+
def get_all(self, key: MetadataKey) -> List[MetadataValue]:
"""For compatibility with other Metadata abstraction objects (like in Java),
this would return all items under the desired <key>.