[Python Aio] Change aio Metadata inheritance (#36214)

Fix: https://github.com/grpc/grpc/issues/26498
<!--

If you know who should review your pull request, please assign it to that
person, otherwise the pull request would get assigned randomly.

If your pull request is for a specific language, please add the appropriate
lang label.

-->

Closes #36214

COPYBARA_INTEGRATE_REVIEW=https://github.com/grpc/grpc/pull/36214 from XuanWang-Amos:fix_aio_Metadata_class 90329a2bdf
PiperOrigin-RevId: 622898840
pull/35579/head
Xuan Wang 8 months ago committed by Copybara-Service
parent ddb785674c
commit 6cbc7ad63d
  1. 21
      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>.

Loading…
Cancel
Save