python: Emulate the previous `-l' option to ashd-wsgi3.
[ashd.git] / python3 / ashd-wsgi3
index 79dda81..2a8815b 100755 (executable)
@@ -8,12 +8,12 @@ except:
     pdm = None
 
 def usage(out):
-    out.write("usage: ashd-wsgi3 [-hAL] [-m PDM-SPEC] [-p MODPATH] [-l REQLIMIT] HANDLER-MODULE [ARGS...]\n")
+    out.write("usage: ashd-wsgi3 [-hAL] [-m PDM-SPEC] [-p MODPATH] [-l REQLIMIT] [-t REQUEST-HANDLER[:PAR[=VAL](,PAR[=VAL])...]] HANDLER-MODULE [ARGS...]\n")
 
-reqlimit = 0
+hspec = "free", {}
 modwsgi_compat = False
 setlog = True
-opts, args = getopt.getopt(sys.argv[1:], "+hALp:l:m:")
+opts, args = getopt.getopt(sys.argv[1:], "+hALp:t:l:m:")
 for o, a in opts:
     if o == "-h":
         usage(sys.stdout)
@@ -25,7 +25,9 @@ for o, a in opts:
     elif o == "-A":
         modwsgi_compat = True
     elif o == "-l":
-        reqlimit = int(a)
+        hspec = "free", {"max": int(a), "abort": 10}
+    elif o == "-t":
+        hspec = ashd.serve.parsehspec(a)
     elif o == "-m":
         if pdm is not None:
             pdm.srv.listen(a)
@@ -145,19 +147,12 @@ def mkenv(req):
     env["wsgi.run_once"] = False
     return env
 
-if reqlimit != 0:
-    guard = ashd.serve.abortlimiter(reqlimit).call
-else:
-    guard = lambda fun: fun()
-
 def recode(thing):
     if isinstance(thing, collections.ByteString):
         return thing
     else:
         return str(thing).encode("latin-1")
 
-reqhandler = ashd.serve.freethread()
-
 class request(ashd.serve.wsgirequest):
     def __init__(self, *, bkreq, **kw):
         super().__init__(**kw)
@@ -192,5 +187,18 @@ class request(ashd.serve.wsgirequest):
 def handle(req):
     reqhandler.handle(request(bkreq=req, handler=reqhandler))
 
-ashd.util.serveloop(handle)
-reqhandler.close()
+if hspec[0] not in ashd.serve.names:
+    sys.stderr.write("ashd-wsgi3: no such request handler: %s\n" % hspec[0])
+    sys.exit(1)
+hclass = ashd.serve.names[hspec[0]]
+try:
+    hargs = hclass.parseargs(**hspec[1])
+except ValueError as exc:
+    sys.stderr.write("ashd-wsgi3: %s\n" % exc)
+    sys.exit(1)
+
+reqhandler = hclass(**hargs)
+try:
+    ashd.util.serveloop(handle)
+finally:
+    reqhandler.close()