Format: text/x-python
⬇ Download File (2.5 KB)
   1  """Simple base-classes for extensions and filters.
   2  
   3  None of the filter and extension functions are considered 'optional' by the
   4  framework.  These base-classes provide simple implementations for the
   5  Initialize and Terminate functions, allowing you to omit them,
   6  
   7  It is not necessary to use these base-classes - but if you don't, you
   8  must ensure each of the required methods are implemented.
   9  """
  10  
  11  from __future__ import annotations
  12  
  13  
  14  class SimpleExtension:
  15      "Base class for a simple ISAPI extension"
  16  
  17      def __init__(self):
  18          pass
  19  
  20      def GetExtensionVersion(self, vi):
  21          """Called by the ISAPI framework to get the extension version
  22  
  23          The default implementation uses the classes docstring to
  24          set the extension description."""
  25          # nod to our reload capability - vi is None when we are reloaded.
  26          if vi is not None:
  27              vi.ExtensionDesc = self.__doc__
  28  
  29      def HttpExtensionProc(self, control_block):
  30          """Called by the ISAPI framework for each extension request.
  31  
  32          sub-classes must provide an implementation for this method.
  33          """
  34          raise NotImplementedError("sub-classes should override HttpExtensionProc")
  35  
  36      def TerminateExtension(self, status):
  37          """Called by the ISAPI framework as the extension terminates."""
  38          pass
  39  
  40  
  41  class SimpleFilter:
  42      "Base class for a a simple ISAPI filter"
  43  
  44      filter_flags: int | None = None
  45  
  46      def __init__(self):
  47          pass
  48  
  49      def GetFilterVersion(self, fv):
  50          """Called by the ISAPI framework to get the extension version
  51  
  52          The default implementation uses the classes docstring to
  53          set the extension description, and uses the classes
  54          filter_flags attribute to set the ISAPI filter flags - you
  55          must specify filter_flags in your class.
  56          """
  57          if self.filter_flags is None:
  58              raise RuntimeError("You must specify the filter flags")
  59          # nod to our reload capability - fv is None when we are reloaded.
  60          if fv is not None:
  61              fv.Flags = self.filter_flags
  62              fv.FilterDesc = self.__doc__
  63  
  64      def HttpFilterProc(self, fc):
  65          """Called by the ISAPI framework for each filter request.
  66  
  67          sub-classes must provide an implementation for this method.
  68          """
  69          raise NotImplementedError("sub-classes should override HttpExtensionProc")
  70  
  71      def TerminateFilter(self, status):
  72          """Called by the ISAPI framework as the filter terminates."""
  73          pass
  74