interfaces.py 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. # This program is free software; you can redistribute it and/or modify it under
  2. # the terms of the GNU General Public License as published by the Free Software
  3. # Foundation; either version 2 of the License, or (at your option) any later
  4. # version.
  5. #
  6. # This program is distributed in the hope that it will be useful, but WITHOUT
  7. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  8. # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
  9. #
  10. # You should have received a copy of the GNU General Public License along with
  11. # this program; if not, write to the Free Software Foundation, Inc.,
  12. # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  13. """ Copyright (c) 2002-2003 LOGILAB S.A. (Paris, FRANCE).
  14. http://www.logilab.fr/ -- mailto:contact@logilab.fr
  15. Interfaces for PyLint objects
  16. """
  17. __revision__ = "$Id: interfaces.py,v 1.9 2004-04-24 12:14:53 syt Exp $"
  18. from logilab.common.interface import Interface
  19. class IChecker(Interface):
  20. """This is an base interface, not designed to be used elsewhere than for
  21. sub interfaces definition.
  22. """
  23. def open(self):
  24. """called before visiting project (i.e set of modules)"""
  25. def close(self):
  26. """called after visiting project (i.e set of modules)"""
  27. ## def open_module(self):
  28. ## """called before visiting a module"""
  29. ## def close_module(self):
  30. ## """called after visiting a module"""
  31. class IRawChecker(IChecker):
  32. """interface for checker which need to parse the raw file
  33. """
  34. def process_module(self, astng):
  35. """ process a module
  36. the module's content is accessible via astng.file_stream
  37. """
  38. class IASTNGChecker(IChecker):
  39. """ interface for checker which prefers receive events according to
  40. statement type
  41. """
  42. class ILinter(Interface):
  43. """interface for the linter class
  44. the linter class will generate events to its registered checkers.
  45. Each checker may interact with the linter instance using this API
  46. """
  47. def register_checker(self, checker):
  48. """register a new checker class
  49. checker is a class implementing IrawChecker or / and IASTNGChecker
  50. """
  51. def add_message(self, msg_id, line=None, node=None, args=None):
  52. """add the message corresponding to the given id.
  53. If provided, msg is expanded using args
  54. astng checkers should provide the node argument,
  55. raw checkers should provide the line argument.
  56. """
  57. class IReporter(Interface):
  58. """ reporter collect messages and display results encapsulated in a layout
  59. """
  60. def add_message(self, msg_id, location, msg):
  61. """add a message of a given type
  62. msg_id is a message identifier
  63. location is a 3-uple (module, object, line)
  64. msg is the actual message
  65. """
  66. def display_results(self, layout):
  67. """display results encapsulated in the layout tree
  68. """
  69. __all__ = ('IRawChecker', 'IStatable', 'ILinter', 'IReporter')