[GMG-Devel] [PATCH 22/83] Add ListenerRegistry class to collect all the listeners.

Alon Levy alon at pobox.com
Tue Feb 25 14:58:05 EST 2014


From: Praveen Kumar <praveen97uma at gmail.com>

---
 mediagoblin/plugins/search/registry.py | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/mediagoblin/plugins/search/registry.py b/mediagoblin/plugins/search/registry.py
index 8aacc95..429fe00 100644
--- a/mediagoblin/plugins/search/registry.py
+++ b/mediagoblin/plugins/search/registry.py
@@ -35,3 +35,33 @@ class IndexRegistry(object):
         """
         identifier = db_object.__tablename__
         return IndexRegistry.get(identifier, not_found)
+
+
+class ListenerRegistry(object):
+    _registry = {}
+
+    @staticmethod
+    def register(listener_obj):
+        """
+        Registers a search.listeners.ORMEventsListener object.
+        """
+        identifier = listener_obj.model.__tablename__
+        ListenerRegistry._registry[identifier] = listener_obj
+    
+    @staticmethod
+    def indices():
+        """
+        Return all the listener objects registered.
+        """
+        return ListenerRegistry._registry
+
+    @staticmethod
+    def get(identifier, not_found=None):
+        """
+        Return an ORMEventsListener object identified by `identifier`.
+
+        Returns `not_found` if the listener object was not found.
+        in the regstered list of listeners.
+        """
+        listener = ListenerRegistry._registry.get(identifier, not_found)
+        return listener
-- 
1.8.5.3



More information about the devel mailing list