diff --git a/masque/library/library.py b/masque/library/library.py index f2151d2..7fc5a86 100644 --- a/masque/library/library.py +++ b/masque/library/library.py @@ -84,6 +84,11 @@ class Library: def __getitem__(self, key: str) -> 'Pattern': return self.get_primary(key) + def __iter__(self) -> Iterator[str]: + return self.keys() + + def __contains__(self, key: str) -> bool: + return key in self.primary def get_primary(self, key: str) -> 'Pattern': if self.enable_cache and key in self.cache: @@ -127,6 +132,15 @@ class Library: raise LibraryError(f'Broken reference to {key} (tag {tag})') return pat + def keys(self) -> Iterator[str]: + return self.primary.keys() + + def values(self) -> Iterator['Pattern']: + return (self[key] for key in self.keys()) + + def items(self) -> Iterator[Tuple[str, 'Pattern']]: + return ((key, self[key]) for key in self.keys()) + def __repr__(self) -> str: return ''