Development of an internal social media platform with personalised dashboards for students
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

interfaces.py 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. # Copyright (c) 2009-2010, 2012-2013 LOGILAB S.A. (Paris, FRANCE) <contact@logilab.fr>
  2. # Copyright (c) 2013-2014 Google, Inc.
  3. # Copyright (c) 2014 Michal Nowikowski <godfryd@gmail.com>
  4. # Copyright (c) 2014 Arun Persaud <arun@nubati.net>
  5. # Copyright (c) 2015-2017 Claudiu Popa <pcmanticore@gmail.com>
  6. # Copyright (c) 2015 Florian Bruhin <me@the-compiler.org>
  7. # Copyright (c) 2015 Ionel Cristian Maries <contact@ionelmc.ro>
  8. # Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  9. # For details: https://github.com/PyCQA/pylint/blob/master/COPYING
  10. """Interfaces for Pylint objects"""
  11. from collections import namedtuple
  12. Confidence = namedtuple('Confidence', ['name', 'description'])
  13. # Warning Certainties
  14. HIGH = Confidence('HIGH', 'No false positive possible.')
  15. INFERENCE = Confidence('INFERENCE', 'Warning based on inference result.')
  16. INFERENCE_FAILURE = Confidence('INFERENCE_FAILURE',
  17. 'Warning based on inference with failures.')
  18. UNDEFINED = Confidence('UNDEFINED',
  19. 'Warning without any associated confidence level.')
  20. CONFIDENCE_LEVELS = [HIGH, INFERENCE, INFERENCE_FAILURE, UNDEFINED]
  21. class Interface(object):
  22. """Base class for interfaces."""
  23. @classmethod
  24. def is_implemented_by(cls, instance):
  25. return implements(instance, cls)
  26. def implements(obj, interface):
  27. """Return true if the give object (maybe an instance or class) implements
  28. the interface.
  29. """
  30. kimplements = getattr(obj, '__implements__', ())
  31. if not isinstance(kimplements, (list, tuple)):
  32. kimplements = (kimplements,)
  33. for implementedinterface in kimplements:
  34. if issubclass(implementedinterface, interface):
  35. return True
  36. return False
  37. class IChecker(Interface):
  38. """This is an base interface, not designed to be used elsewhere than for
  39. sub interfaces definition.
  40. """
  41. def open(self):
  42. """called before visiting project (i.e set of modules)"""
  43. def close(self):
  44. """called after visiting project (i.e set of modules)"""
  45. class IRawChecker(IChecker):
  46. """interface for checker which need to parse the raw file
  47. """
  48. def process_module(self, astroid):
  49. """ process a module
  50. the module's content is accessible via astroid.stream
  51. """
  52. class ITokenChecker(IChecker):
  53. """Interface for checkers that need access to the token list."""
  54. def process_tokens(self, tokens):
  55. """Process a module.
  56. tokens is a list of all source code tokens in the file.
  57. """
  58. class IAstroidChecker(IChecker):
  59. """ interface for checker which prefers receive events according to
  60. statement type
  61. """
  62. class IReporter(Interface):
  63. """ reporter collect messages and display results encapsulated in a layout
  64. """
  65. def handle_message(self, msg):
  66. """Handle the given message object."""
  67. def display_reports(self, layout):
  68. """display results encapsulated in the layout tree
  69. """
  70. __all__ = ('IRawChecker', 'IAstroidChecker', 'ITokenChecker', 'IReporter')