Thursday, June 25, 2009

pyamf on IIS using pyisapie

I opened a pyamf ticket on the pyamf site on how to use pyAMF on IIS with pyISAPIe. Authentication is also possible:


"""
Global ISAPI request handler for use with PathFinder.
"""
from Http.WSGI import RunWSGI
from Http import Env
from md5 import md5
import imp
import os

from pyamf.remoting.gateway.wsgi import WSGIGateway as WSGIGateway

def testLogin():
return True;

def auth(uid, pwd):
"""
Authenticate the user.
"""
if uid == 'zzzzzzzzzzzzzzzz=' and pwd == 'zzzzzzzzzzzzzzzz=':
return True
return False

services = {
'testLogin' : testLogin
}

#
# URL prefixes to map to the roots of each application.
#
Apps = {
"/pf/gateway/" : lambda P: RunWSGI(WSGIGateway(services,authenticator=auth))
}

#
# The main request handler.
#
def Request():
# Might be better to do some caching here?
Name = Env.SCRIPT_NAME

# Apps might be better off as a tuple-of-tuples,
# but for the sake of representation I leave it
# as a dict.
for App, Handler in Apps.items():
if Name.startswith(App):
return Handler(Name)

# Cause 500 error: there should be a 404 handler, eh?
#
raise Exception, "Handler not found."

No comments: