From 5345dcaf7afbc811d75d4826652144268dd7a863 Mon Sep 17 00:00:00 2001 From: Fredrik Tolf Date: Sun, 5 Jan 2014 22:31:44 +0100 Subject: [PATCH] python: Gather handler names better. --- python3/ashd/serve.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/python3/ashd/serve.py b/python3/ashd/serve.py index 15e2903..9aae12c 100644 --- a/python3/ashd/serve.py +++ b/python3/ashd/serve.py @@ -88,6 +88,8 @@ class handler(object): return {} class single(handler): + cname = "single" + def handle(self, req): try: env = req.mkenv() @@ -107,6 +109,8 @@ class single(handler): req.close() class freethread(handler): + cname = "free" + def __init__(self, *, max=None, timeout=None, **kw): super().__init__(**kw) self.current = set() @@ -179,6 +183,8 @@ class freethread(handler): th.join() class resplex(handler): + cname = "rplex" + def __init__(self, *, max=None, **kw): super().__init__(**kw) self.current = set() @@ -326,9 +332,10 @@ class resplex(handler): os.close(self.cnpipe[1]) self.rthread.join() -names = {"single": single, - "free": freethread, - "rplex": resplex} +names = {cls.cname: cls for cls in globals().values() if + isinstance(cls, type) and + issubclass(cls, handler) and + hasattr(cls, "cname")} def parsehspec(spec): if ":" not in spec: -- 2.11.0