X-Git-Url: http://git.dolda2000.com/gitweb/?a=blobdiff_plain;f=python3%2Fscgi-wsgi3;fp=python3%2Fscgi-wsgi3;h=9befb255c6a5a2d2b5353f4753007fd0d94f2e72;hb=173e0e9efec5ae690cc157fe238113fcd814895e;hp=0000000000000000000000000000000000000000;hpb=188cd02daf85ef68a832deab4fcbf0daaf2d4573;p=ashd.git diff --git a/python3/scgi-wsgi3 b/python3/scgi-wsgi3 new file mode 100755 index 0000000..9befb25 --- /dev/null +++ b/python3/scgi-wsgi3 @@ -0,0 +1,58 @@ +#!/usr/bin/python3 + +import sys, os, getopt +import socket +import ashd.scgi + +def usage(out): + out.write("usage: scgi-wsgi [-hA] [-p MODPATH] [-T [HOST:]PORT] HANDLER-MODULE [ARGS...]\n") + +sk = None +modwsgi_compat = False +opts, args = getopt.getopt(sys.argv[1:], "+hAp:T:") +for o, a in opts: + if o == "-h": + usage(sys.stdout) + sys.exit(0) + elif o == "-p": + sys.path.insert(0, a) + elif o == "-T": + sk = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + p = a.rfind(":") + if p < 0: + bindhost = "localhost" + bindport = int(a) + else: + bindhost = a[:p] + bindport = int(a[p + 1:]) + sk.bind((bindhost, bindport)) + sk.listen(32) + elif o == "-A": + modwsgi_compat = True +if len(args) < 1: + usage(sys.stderr) + sys.exit(1) + +if sk is None: + # This is suboptimal, since the socket on stdin is not necessarily + # AF_UNIX, but Python does not seem to offer any way around it, + # that I can find. + sk = socket.fromfd(0, socket.AF_UNIX, socket.SOCK_STREAM) + +try: + handlermod = __import__(args[0], fromlist = ["dummy"]) +except ImportError as exc: + sys.stderr.write("scgi-wsgi: handler %s not found: %s\n" % (args[0], exc.args[0])) + sys.exit(1) +if not modwsgi_compat: + if not hasattr(handlermod, "wmain"): + sys.stderr.write("scgi-wsgi: handler %s has no `wmain' function\n" % args[0]) + sys.exit(1) + handler = handlermod.wmain(*args[1:]) +else: + if not hasattr(handlermod, "application"): + sys.stderr.write("scgi-wsgi: handler %s has no `application' object\n" % args[0]) + sys.exit(1) + handler = handlermod.application + +ashd.scgi.servescgi(sk, ashd.scgi.wrapwsgi(handler))