home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_1962 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  3.1 KB  |  76 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. from isapi import isapicon, threaded_extension
  5. from isapi.simple import SimpleFilter
  6. import sys
  7. import traceback
  8. import urllib
  9. if hasattr(sys, 'isapidllhandle'):
  10.     import win32traceutil
  11.  
  12. proxy = 'http://www.python.org'
  13. virtualdir = '/python'
  14.  
  15. class Extension(threaded_extension.ThreadPoolExtension):
  16.     
  17.     def Dispatch(self, ecb):
  18.         url = ecb.GetServerVariable('URL')
  19.         if url.startswith(virtualdir):
  20.             new_url = proxy + url[len(virtualdir):]
  21.             print 'Opening', new_url
  22.             fp = urllib.urlopen(new_url)
  23.             headers = fp.info()
  24.             ecb.SendResponseHeaders('200 OK', str(headers) + '\r\n', False)
  25.             ecb.WriteClient(fp.read())
  26.             ecb.DoneWithSession()
  27.             print "Returned data from '%s'!" % (new_url,)
  28.         else:
  29.             print "Not proxying '%s'" % (url,)
  30.  
  31.  
  32.  
  33. class Filter(SimpleFilter):
  34.     filter_flags = isapicon.SF_NOTIFY_PREPROC_HEADERS | isapicon.SF_NOTIFY_ORDER_DEFAULT
  35.     
  36.     def HttpFilterProc(self, fc):
  37.         nt = fc.NotificationType
  38.         if nt != isapicon.SF_NOTIFY_PREPROC_HEADERS:
  39.             return isapicon.SF_STATUS_REQ_NEXT_NOTIFICATION
  40.         pp = fc.GetData()
  41.         url = pp.GetHeader('url')
  42.         prefix = virtualdir
  43.         if not url.startswith(prefix):
  44.             new_url = prefix + url
  45.             print "New proxied URL is '%s'" % (new_url,)
  46.             pp.SetHeader('url', new_url)
  47.             if fc.FilterContext is None:
  48.                 fc.FilterContext = 0
  49.             
  50.             fc.FilterContext += 1
  51.             print 'This is request number', fc.FilterContext, 'on this connection'
  52.             return isapicon.SF_STATUS_REQ_HANDLED_NOTIFICATION
  53.         print "Filter ignoring URL '%s'" % (url,)
  54.  
  55.  
  56.  
  57. def __FilterFactory__():
  58.     return Filter()
  59.  
  60.  
  61. def __ExtensionFactory__():
  62.     return Extension()
  63.  
  64. if __name__ == '__main__':
  65.     from isapi.install import *
  66.     params = ISAPIParameters()
  67.     params.Filters = [
  68.         FilterParameters(Name = 'PythonRedirector', Description = Filter.__doc__)]
  69.     sm = [
  70.         ScriptMapParams(Extension = '*', Flags = 0)]
  71.     vd = VirtualDirParameters(Name = virtualdir[1:], Description = Extension.__doc__, ScriptMaps = sm, ScriptMapUpdate = 'replace')
  72.     params.VirtualDirs = [
  73.         vd]
  74.     HandleCommandLine(params)
  75.  
  76.