simple.py 2.4 KB

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