From 8c4ceea4cd9b35f67cc18c440a14e559d85bbfd9 Mon Sep 17 00:00:00 2001 From: Griatch Date: Sat, 3 Mar 2018 16:24:17 +0100 Subject: [PATCH] Use readonly-search for prototypes --- evennia/utils/olc/olc_storage.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/evennia/utils/olc/olc_storage.py b/evennia/utils/olc/olc_storage.py index 7c4adad5c4..113d0296cb 100644 --- a/evennia/utils/olc/olc_storage.py +++ b/evennia/utils/olc/olc_storage.py @@ -159,7 +159,7 @@ def search_readonly_prototype(key=None, tags=None): prototype metadata, """ - matches = [] + matches = {} if tags: # use tags to limit selection tagset = set(tags) @@ -171,11 +171,12 @@ def search_readonly_prototype(key=None, tags=None): if key: if key in matches: # exact match - return matches[key] + return [matches[key]] else: # fuzzy matching return [metaproto for pkey, metaproto in matches.items() if key in pkey] - return matches + else: + return [match for match in matches.values()] def search_prototype(key=None, tags=None): @@ -223,10 +224,7 @@ def get_prototype_list(caller, key=None, tags=None, show_non_use=False, show_non """ # handle read-only prototypes separately - if key and key in _READONLY_PROTOTYPES: - readonly_prototypes = _READONLY_PROTOTYPES[key] - else: - readonly_prototypes = _READONLY_PROTOTYPES.values() + readonly_prototypes = search_readonly_prototype(key, tags) # get use-permissions of readonly attributes (edit is always False) readonly_prototypes = [ @@ -239,9 +237,6 @@ def get_prototype_list(caller, key=None, tags=None, show_non_use=False, show_non # next, handle db-stored prototypes prototypes = search_persistent_prototype(key, tags) - if not prototypes: - return None - # gather access permissions as (key, desc, tags, can_use, can_edit) prototypes = [(prototype.key, prototype.desc, "{}/{}".format('Y' if prototype.access(caller, "use") else 'N', @@ -251,6 +246,9 @@ def get_prototype_list(caller, key=None, tags=None, show_non_use=False, show_non prototypes = prototypes + readonly_prototypes + if not prototypes: + return None + if not show_non_use: prototypes = [tup for tup in sorted(prototypes, key=lambda o: o[0]) if tup[2]] if not show_non_edit: