summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2018-08-17 13:12:15 -0400
committerJason R. Coombs <jaraco@jaraco.com>2018-08-17 13:12:15 -0400
commit70adb8def132f2b8cd53d1782dac8e37746381de (patch)
tree4fb448b7718c698a0b8a7064ea07613fb7c74900
parent97d35f1aff4d752f9d8d1b2aaeed08a21c1bb793 (diff)
downloadcherrypy-git-70adb8def132f2b8cd53d1782dac8e37746381de.tar.gz
Collapse duplicate behavior in engine_namespace_handler
-rw-r--r--cherrypy/_cpconfig.py15
1 files changed, 5 insertions, 10 deletions
diff --git a/cherrypy/_cpconfig.py b/cherrypy/_cpconfig.py
index 7e1a65c6..0c8ed6ce 100644
--- a/cherrypy/_cpconfig.py
+++ b/cherrypy/_cpconfig.py
@@ -270,16 +270,11 @@ def _engine_namespace_handler(k, v):
elif '.' in k:
plugin, attrname = k.split('.', 1)
plugin = getattr(engine, plugin)
- if attrname == 'on':
- if v and hasattr(getattr(plugin, 'subscribe', None), '__call__'):
- plugin.subscribe()
- return
- elif (
- (not v) and
- hasattr(getattr(plugin, 'unsubscribe', None), '__call__')
- ):
- plugin.unsubscribe()
- return
+ op = 'subscribe' if v else 'unsubscribe'
+ sub_unsub = getattr(plugin, op, None)
+ if attrname == 'on' and callable(sub_unsub):
+ sub_unsub()
+ return
setattr(plugin, attrname, v)
else:
setattr(engine, k, v)