Skip to content

Instantly share code, notes, and snippets.

@amercader
Created November 8, 2010 10:59
Show Gist options
  • Save amercader/667581 to your computer and use it in GitHub Desktop.
Save amercader/667581 to your computer and use it in GitHub Desktop.
"""Default page handler.
"""
from PyISAPIe import Env
from hashlib import md5
import imp
from Error import HandleNotFound
Handlers = {}
def Request(Path):
Script = Env.SCRIPT_NAME
Key = Name = '__'+md5(Script).hexdigest().upper()
Handler = Handlers.get(Key, None)
if not Handler:
try:
Handlers[Key] = imp.load_source(Key, Env.SCRIPT_TRANSLATED).Request
except Exception, Val:
# trigger a passthrough to the next ISAPI handler -
# ONLY WORKS FOR WILDCARD APPLICATION MAPPINGS
#return True
# or just fail, preferable for an application map
if type(Val).__name__ == "IOError":
HandleNotFound(Path)
else:
raise ImportError, "[Loading '%s'] %s" % (Env.SCRIPT_TRANSLATED, str(Val))
return Handlers[Key]()
Map = [
{
'Controllers' :
{
'Printer' :
{
'^/printing/info.json$' : 'info',
'^/printing/create.json$' : 'create',
'^/printing/print.pdf$' : 'doPrint',
'^/printing/([\S]+(?<!print)).pdf$' : 'get',
}
}
},
# Forward all other requests to the default handler.
{'(.*)' : 'Default.Request'},
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment