Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added util package, which provides a general get()
- Loading branch information
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
def gw_get(object_dict, name=None, plugin=None): | ||
""" | ||
Getter function to retrieve objects from a given object dictionary. | ||
Used mainly to provide get() inside patterns. | ||
:param object_dict: objects, which must have 'name' and 'plugin' as attribute | ||
:type object_dict: dictionary | ||
:param name: name of the object | ||
:type name: str | ||
:param plugin: plugin name, which registers the object | ||
:return: None, single object or dict of objects | ||
""" | ||
if plugin is not None: | ||
if name is None: | ||
object_list = {} | ||
for key in object_dict.keys(): | ||
if object_dict[key].plugin == plugin: | ||
object_list[key] = object_dict[key] | ||
return object_list | ||
else: | ||
if name in object_dict.keys(): | ||
if object_dict[name].plugin == plugin: | ||
return object_dict[name] | ||
else: | ||
return None | ||
else: | ||
return None | ||
else: | ||
if name is None: | ||
return object_dict | ||
else: | ||
if name in object_dict.keys(): | ||
return object_dict[name] | ||
else: | ||
return None |