3 import sys, os, getopt, logging
8 out.write("usage: scgi-wsgi [-hAL] [-p MODPATH] [-T [HOST:]PORT] HANDLER-MODULE [ARGS...]\n")
11 modwsgi_compat = False
13 opts, args = getopt.getopt(sys.argv[1:], "+hALp:T:")
23 sk = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
24 sk.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
27 bindhost = "localhost"
31 bindport = int(a[p + 1:])
32 sk.bind((bindhost, bindport))
40 logging.basicConfig(format="scgi-wsgi(%(name)s): %(levelname)s: %(message)s")
43 # This is suboptimal, since the socket on stdin is not necessarily
44 # AF_UNIX, but Python does not seem to offer any way around it,
46 sk = socket.fromfd(0, socket.AF_UNIX, socket.SOCK_STREAM)
49 handlermod = __import__(args[0], fromlist = ["dummy"])
50 except ImportError, exc:
51 sys.stderr.write("scgi-wsgi: handler %s not found: %s\n" % (args[0], exc.message))
53 if not modwsgi_compat:
54 if not hasattr(handlermod, "wmain"):
55 sys.stderr.write("scgi-wsgi: handler %s has no `wmain' function\n" % args[0])
57 handler = handlermod.wmain(*args[1:])
59 if not hasattr(handlermod, "application"):
60 sys.stderr.write("scgi-wsgi: handler %s has no `application' object\n" % args[0])
62 handler = handlermod.application
64 ashd.scgi.servescgi(sk, ashd.scgi.wrapwsgi(handler))