aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/EventManager.py7
-rw-r--r--src/Utils.py32
2 files changed, 39 insertions, 0 deletions
diff --git a/src/EventManager.py b/src/EventManager.py
index b8a5ecfb..720fe0a1 100644
--- a/src/EventManager.py
+++ b/src/EventManager.py
@@ -1,4 +1,5 @@
import itertools, time, traceback
+from src import Utils
PRIORITY_URGENT = 0
PRIORITY_HIGH = 1
@@ -29,9 +30,15 @@ class EventCallback(object):
self.function = function
self.priority = priority
self.kwargs = kwargs
+ self.docstring = Utils.parse_docstring(function.__doc__)
+
def call(self, event):
return self.function(event)
+ def get_kwarg(self, name, default=None):
+ item = self.kwargs.get(name, default)
+ return item or self.docstring.items.get(name, default)
+
class MultipleEventHook(object):
def __init__(self):
self._event_hooks = set([])
diff --git a/src/Utils.py b/src/Utils.py
index b5fa8452..e87330c2 100644
--- a/src/Utils.py
+++ b/src/Utils.py
@@ -313,3 +313,35 @@ def get_hashflags(filename):
value = line_split[1]
hashflags[hashflag] = value
return hashflags.items()
+
+class Docstring(object):
+ def __init__(self, description, items):
+ self.description = description
+ self.items = items
+
+def parse_docstring(s):
+ description = ""
+ last_item = None
+ items = {}
+ if s:
+ for line in s.split("\n"):
+ line = line.strip()
+
+ if line:
+ if line[0] == ":":
+ line_split = line.split(": ", 1)
+
+ value = None
+ if len(line_split) > 1:
+ value = line_split[1]
+
+ last_item = line_split[0][1:].lower()
+ items[last_item] = value
+ else:
+ if last_item:
+ items[last_item] += " %s" % line
+ else:
+ if description:
+ description += " "
+ description += line
+ return Docstring(description, items)