Created
November 8, 2010 10:59
-
-
Save amercader/667581 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""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]() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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