diff options
| author | Jason R. Coombs <jaraco@jaraco.com> | 2017-11-10 13:31:12 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-11-10 13:31:12 -0500 |
| commit | 3b239d381cefd04fa8f2561270fc36c81ff20116 (patch) | |
| tree | 0be4c697632f9493f9839de1376e9bf07908ed3a /cherrypy/process | |
| parent | cf9e8d5d377e486991e28b0ebe1f6ad2564c54f5 (diff) | |
| parent | b07f8ca918197aecd7336888e249a876eee55ad4 (diff) | |
| download | cherrypy-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.py | 19 |
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) |
