home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.6)
-
- from isapi import isapicon, threaded_extension
- from isapi.simple import SimpleFilter
- import sys
- import traceback
- import urllib
- if hasattr(sys, 'isapidllhandle'):
- import win32traceutil
-
- proxy = 'http://www.python.org'
- virtualdir = '/python'
-
- class Extension(threaded_extension.ThreadPoolExtension):
-
- def Dispatch(self, ecb):
- url = ecb.GetServerVariable('URL')
- if url.startswith(virtualdir):
- new_url = proxy + url[len(virtualdir):]
- print 'Opening', new_url
- fp = urllib.urlopen(new_url)
- headers = fp.info()
- ecb.SendResponseHeaders('200 OK', str(headers) + '\r\n', False)
- ecb.WriteClient(fp.read())
- ecb.DoneWithSession()
- print "Returned data from '%s'!" % (new_url,)
- else:
- print "Not proxying '%s'" % (url,)
-
-
-
- class Filter(SimpleFilter):
- filter_flags = isapicon.SF_NOTIFY_PREPROC_HEADERS | isapicon.SF_NOTIFY_ORDER_DEFAULT
-
- def HttpFilterProc(self, fc):
- nt = fc.NotificationType
- if nt != isapicon.SF_NOTIFY_PREPROC_HEADERS:
- return isapicon.SF_STATUS_REQ_NEXT_NOTIFICATION
- pp = fc.GetData()
- url = pp.GetHeader('url')
- prefix = virtualdir
- if not url.startswith(prefix):
- new_url = prefix + url
- print "New proxied URL is '%s'" % (new_url,)
- pp.SetHeader('url', new_url)
- if fc.FilterContext is None:
- fc.FilterContext = 0
-
- fc.FilterContext += 1
- print 'This is request number', fc.FilterContext, 'on this connection'
- return isapicon.SF_STATUS_REQ_HANDLED_NOTIFICATION
- print "Filter ignoring URL '%s'" % (url,)
-
-
-
- def __FilterFactory__():
- return Filter()
-
-
- def __ExtensionFactory__():
- return Extension()
-
- if __name__ == '__main__':
- from isapi.install import *
- params = ISAPIParameters()
- params.Filters = [
- FilterParameters(Name = 'PythonRedirector', Description = Filter.__doc__)]
- sm = [
- ScriptMapParams(Extension = '*', Flags = 0)]
- vd = VirtualDirParameters(Name = virtualdir[1:], Description = Extension.__doc__, ScriptMaps = sm, ScriptMapUpdate = 'replace')
- params.VirtualDirs = [
- vd]
- HandleCommandLine(params)
-
-