1 import os, threading, types
5 def __init__(self, mod, mtime):
6 self.lock = threading.Lock()
12 cachelock = threading.Lock()
28 entry = modcache[path]
29 if sb.st_mtime <= entry.mtime:
37 code = compile(text, path, "exec")
38 mod = types.ModuleType(mangle(path))
40 exec code in mod.__dict__
41 entry = cachedmod(mod, sb.st_mtime)
42 modcache[path] = entry
47 def chain(path, env, startreq):
53 if hasattr(mod, "entry"):
56 if hasattr(mod.mod, "wmain"):
57 entry = mod.mod.wmain()
58 elif hasattr(mod.mod, "application"):
59 entry = mod.mod.application
64 return entry(env, startreq)
65 return wsgiutil.simpleerror(env, startreq, 500, "Internal Error", "Invalid WSGI handler.")
68 def addext(ext, handler):
69 p = handler.rindex('.')
71 hname = handler[p + 1:]
72 mod = __import__(mname, fromlist = ["dummy"])
73 exts[ext] = getattr(mod, hname)
75 def application(env, startreq):
76 if not "SCRIPT_FILENAME" in env:
77 return wsgiutil.simpleerror(env, startreq, 500, "Internal Error", "The server is erroneously configured.")
78 path = env["SCRIPT_FILENAME"]
79 base = os.path.basename(path)
81 if p < 0 or not os.access(path, os.R_OK):
82 return wsgiutil.simpleerror(env, startreq, 500, "Internal Error", "The server is erroneously configured.")
85 return wsgiutil.simpleerror(env, startreq, 500, "Internal Error", "The server is erroneously configured.")
86 return(exts[ext](path, env, startreq))
92 addext(arg[1:p], arg[p + 1:])