summaryrefslogtreecommitdiff
path: root/cherrypy/process
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2017-11-10 13:31:12 -0500
committerGitHub <noreply@github.com>2017-11-10 13:31:12 -0500
commit3b239d381cefd04fa8f2561270fc36c81ff20116 (patch)
tree0be4c697632f9493f9839de1376e9bf07908ed3a /cherrypy/process
parentcf9e8d5d377e486991e28b0ebe1f6ad2564c54f5 (diff)
parentb07f8ca918197aecd7336888e249a876eee55ad4 (diff)
downloadcherrypy-git-3b239d381cefd04fa8f2561270fc36c81ff20116.tar.gz
Merge pull request #1656 from cherrypy/feature/single-subscribe
Use single subscribe method for decorator or direct invocation
Diffstat (limited to 'cherrypy/process')
-rw-r--r--cherrypy/process/wspbus.py19
1 files changed, 13 insertions, 6 deletions
diff --git a/cherrypy/process/wspbus.py b/cherrypy/process/wspbus.py
index d3984bb2..2fe4159b 100644
--- a/cherrypy/process/wspbus.py
+++ b/cherrypy/process/wspbus.py
@@ -185,8 +185,19 @@ class Bus(object):
)
self._priorities = {}
- def subscribe(self, channel, callback, priority=None):
- """Add the given callback at the given channel (if not present)."""
+ def subscribe(self, channel, callback=None, priority=None):
+ """Add the given callback at the given channel (if not present).
+
+ If callback is None, return a partial suitable for decorating
+ the callback.
+ """
+ if callback is None:
+ return functools.partial(
+ self.subscribe,
+ channel,
+ priority=priority,
+ )
+
ch_listeners = self.listeners.setdefault(channel, set())
ch_listeners.add(callback)
@@ -194,10 +205,6 @@ class Bus(object):
priority = getattr(callback, 'priority', 50)
self._priorities[(channel, callback)] = priority
- def subscribed(self, *args, **kwargs):
- """Generate decorator for self.subscribe."""
- return functools.partial(self.subscribe, *args, **kwargs)
-
def unsubscribe(self, channel, callback):
"""Discard the given callback (if present)."""
listeners = self.listeners.get(channel)