home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_1957 < prev    next >
Encoding:
Text File  |  2004-10-06  |  4.2 KB  |  93 lines

  1. <!-- NOTE: This HTML is displayed inside the CHM file - hence some hrefs
  2.      will only work in that environment
  3. -->
  4. <HTML>
  5. <BODY>
  6. <TITLE>Introduction to Python ISAPI support</TITLE>
  7.  
  8. <h2>Introduction to Python ISAPI support</h2>
  9.  
  10. <h3>See also</h3>
  11. <ul>
  12.     <li><a href="/isapi_modules.html">The isapi related modules</a>
  13.     </li>
  14.     <li><a href="/isapi_objects.html">The isapi related objects</a>
  15.     </li>
  16. </ul>
  17. <p><i>Note: if you are viewing this documentation directly from disk, 
  18. most links in this document will fail - you can also find this document in the
  19. CHM file that comes with pywin32, where the links will work</i>
  20.  
  21. <h3>Introduction</h3>
  22. This documents Python support for hosting ISAPI exensions and filters inside
  23. Microsoft Internet Information Server (IIS). It assumes a basic understanding 
  24. of the ISAPI filter and extension mechanism.
  25. <p>
  26. In summary, to implement a filter or extension, you provide a Python module
  27. which defines a Filter and/or Extension class.  Once your class has been
  28. loaded, IIS/ISAPI will, via an extension DLL, call methods on your class.
  29. <p>
  30. A filter and a class instance need only provide 3 methods - for filters they
  31. are called <code>GetFilterVersion</code>, <code>HttpFilterProc</code> and
  32. <code>TerminateFilter</code>.  For extensions they
  33. are named <code>GetExtensionVersion</code>, <code>HttpExtensionProc</code> and
  34. <code>TerminateExtension</code>.  If you are familiar with writing ISAPI 
  35. extensions in C/C++, these names and their purpose will be familiar.
  36. <p>
  37. Most of the work is done in the <code>HttpFilterProc</code> and 
  38. <code>HttpExtensionProc</code> methods.  These both take a single
  39. parameter - an <a href="/HTTP_FILTER_CONTEXT.html">HTTP_FILTER_CONTEXT</a> and 
  40. <a href="/EXTENSION_CONTROL_BLOCK.html">EXTENSION_CONTROL_BLOCK</a>
  41. object respectively.
  42. <p>
  43. In addition to these components, there is an 'isapi' package, containing
  44. support facilities (base-classes, exceptions, etc) which can be leveraged
  45. by the extension.
  46.  
  47. <h4>Base classes</h4>
  48. There are a number of base classes provided to make writing extensions a little
  49. simpler.  Of particular note is <code>isapi.threaded_extension.ThreadPoolExtension</code>.
  50. This implements a thread-pool and informs IIS that the request is progressing 
  51. in the background.  Your sub-class need only provide a <code>Dispatch</code> 
  52. method, which is called on one of the worker threads rather than the thread
  53. that the request came in on.
  54. <p>
  55. There is base-class for a filter in <code>isapi.simple</code>, but there is no
  56. equivilent threaded filter - filters work under a different model, where
  57. background processing is not possible.
  58. <h4>Samples</h4>
  59. Please see the <code>isapi/samples</code> directory for some sample filters 
  60. and extensions.
  61.  
  62. <H3>Implementation</H3>
  63. A Python ISAPI filter extension consists of 2 main components:
  64. <UL>
  65. <LI>A DLL used by ISAPI to interface with Python.</LI>
  66. <LI>A Python script used by that DLL to implement the filter or extension 
  67. functionality</LI>
  68. </UL>
  69.  
  70. <h4>Extension DLL</h4>
  71. The DLL is usually managed automatically by the isapi.install module.  As the
  72. Python script for the extension is installed, a generic DLL provided with 
  73. the isapi package is installed next to the script, and IIS configured to
  74. use this DLL.
  75. <p>
  76. The name of the DLL always has the same base name as the Python script, but
  77. with a leading underscore (_), and an extension of .dll.  For example, the 
  78. sample "redirector.py" will, when installed, have "_redirector.dll" created
  79. in the same directory.
  80. <p/>
  81. The Python script may provide 2 entry points - methods named __FilterFactory__ 
  82. and __ExtensionFactory__, both taking no arguments and returning a filter or
  83. extension object.
  84.  
  85. <h3>Using py2exe and the isapi package</h3>
  86. You can instruct py2exe to create a 'frozen' Python ISAPI filter/extension.
  87. In this case, py2exe will create a package with everything you need in one
  88. directory, and the Python source file embedded in the .zip file.
  89. <p>
  90. In general, you will want to build a seperate installation executable along 
  91. with the ISAPI extension.  This executable will be built from the same script.
  92. See the ISAPI sample in the py2exe distribution.
  93.