How to use _metadata method in localstack

Best Python code snippet using localstack_python

_metadata.py

Source:_metadata.py Github

copy

Full Screen

1# Copyright 2020 gRPC authors.2#3# Licensed under the Apache License, Version 2.0 (the "License");4# you may not use this file except in compliance with the License.5# You may obtain a copy of the License at6#7# http://www.apache.org/licenses/LICENSE-2.08#9# Unless required by applicable law or agreed to in writing, software10# distributed under the License is distributed on an "AS IS" BASIS,11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12# See the License for the specific language governing permissions and13# limitations under the License.14"""Implementation of the metadata abstraction for gRPC Asyncio Python."""15from collections import OrderedDict16from collections import abc17from typing import Any, Iterator, List, Tuple, Union18MetadataKey = str19MetadataValue = Union[str, bytes]20class Metadata(abc.Mapping):21 """Metadata abstraction for the asynchronous calls and interceptors.22 The metadata is a mapping from str -> List[str]23 Traits24 * Multiple entries are allowed for the same key25 * The order of the values by key is preserved26 * Getting by an element by key, retrieves the first mapped value27 * Supports an immutable view of the data28 * Allows partial mutation on the data without recreating the new object from scratch.29 """30 def __init__(self, *args: Tuple[MetadataKey, MetadataValue]) -> None:31 self._metadata = OrderedDict()32 for md_key, md_value in args:33 self.add(md_key, md_value)34 @classmethod35 def from_tuple(cls, raw_metadata: tuple):36 if raw_metadata:37 return cls(*raw_metadata)38 return cls()39 def add(self, key: MetadataKey, value: MetadataValue) -> None:40 self._metadata.setdefault(key, [])41 self._metadata[key].append(value)42 def __len__(self) -> int:43 """Return the total number of elements that there are in the metadata,44 including multiple values for the same key.45 """46 return sum(map(len, self._metadata.values()))47 def __getitem__(self, key: MetadataKey) -> MetadataValue:48 """When calling <metadata>[<key>], the first element of all those49 mapped for <key> is returned.50 """51 try:52 return self._metadata[key][0]53 except (ValueError, IndexError) as e:54 raise KeyError("{0!r}".format(key)) from e55 def __setitem__(self, key: MetadataKey, value: MetadataValue) -> None:56 """Calling metadata[<key>] = <value>57 Maps <value> to the first instance of <key>.58 """59 if key not in self:60 self._metadata[key] = [value]61 else:62 current_values = self.get_all(key)63 self._metadata[key] = [value, *current_values[1:]]64 def __delitem__(self, key: MetadataKey) -> None:65 """``del metadata[<key>]`` deletes the first mapping for <key>."""66 current_values = self.get_all(key)67 if not current_values:68 raise KeyError(repr(key))69 self._metadata[key] = current_values[1:]70 def delete_all(self, key: MetadataKey) -> None:71 """Delete all mappings for <key>."""72 del self._metadata[key]73 def __iter__(self) -> Iterator[Tuple[MetadataKey, MetadataValue]]:74 for key, values in self._metadata.items():75 for value in values:76 yield (key, value)77 def get_all(self, key: MetadataKey) -> List[MetadataValue]:78 """For compatibility with other Metadata abstraction objects (like in Java),79 this would return all items under the desired <key>.80 """81 return self._metadata.get(key, [])82 def set_all(self, key: MetadataKey, values: List[MetadataValue]) -> None:83 self._metadata[key] = values84 def __contains__(self, key: MetadataKey) -> bool:85 return key in self._metadata86 def __eq__(self, other: Any) -> bool:87 if isinstance(other, self.__class__):88 return self._metadata == other._metadata89 if isinstance(other, tuple):90 return tuple(self) == other91 return NotImplemented # pytype: disable=bad-return-type92 def __add__(self, other: Any) -> 'Metadata':93 if isinstance(other, self.__class__):94 return Metadata(*(tuple(self) + tuple(other)))95 if isinstance(other, tuple):96 return Metadata(*(tuple(self) + other))97 return NotImplemented # pytype: disable=bad-return-type98 def __repr__(self) -> str:99 view = tuple(self)...

Full Screen

Full Screen

metadata.py

Source:metadata.py Github

copy

Full Screen

...19 self._metadata['name'] = os.path.basename(os.getcwd())20 self._metadata['project_name'] = self._metadata['name']21 return22 23 self._load_metadata()24 def get_current_project_name(self):25 dof_files = glob.glob('*.dof') 26 if dof_files:27 return os.path.splitext(dof_files[0])[0]28 return ''29 def _load_metadata(self):30 if self.metadata_type == '.json':31 self._load_json_metadata()32 elif self.metadata_type == '.dof':33 self._load_dof_metadata()34 def _load_dof_metadata(self):35 dof = configparser.ConfigParser()36 dof.read(self.metadata_file)37 major = dof.get('Version Info', 'MajorVer')38 minor = dof.get('Version Info', 'MinorVer')39 release = dof.get('Version Info', 'Release')40 self._metadata['name'] = os.path.splitext(self.metadata_file)[0]41 self._metadata['version'] = '{}.{}.{}'.format(major, minor, release)42 def _load_json_metadata(self):43 with open(self.metadata_file, 'r') as f:44 self._metadata = json.load(45 f,46 object_pairs_hook=collections.OrderedDict47 )48 def update_version(self, version):49 """ Updates package.json version info and Project.dof version info """50 self._metadata['version'] = version51 with open('package.json', 'w') as f:52 f.write(json.dumps(self._metadata, indent=2))53 if os.path.isfile(self.name + '.dof'):54 dof_file = DOFFile(self.name + '.dof')55 dof_file.update_version(version)56 @property...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful