gvsig-scripting / org.gvsig.scripting / trunk / org.gvsig.scripting / org.gvsig.scripting.app / org.gvsig.scripting.app.mainplugin / src / main / resources-plugin / scripting / lib / pylint / interfaces.py @ 745
History | View | Annotate | Download (3.28 KB)
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 |
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
13 |
"""Interfaces for Pylint objects"""
|
14 |
from collections import namedtuple |
15 |
|
16 |
Confidence = namedtuple('Confidence', ['name', 'description']) |
17 |
# Warning Certainties
|
18 |
HIGH = Confidence('HIGH', 'No false positive possible.') |
19 |
INFERENCE = Confidence('INFERENCE', 'Warning based on inference result.') |
20 |
INFERENCE_FAILURE = Confidence('INFERENCE_FAILURE',
|
21 |
'Warning based on inference with failures.')
|
22 |
UNDEFINED = Confidence('UNDEFINED',
|
23 |
'Warning without any associated confidence level.')
|
24 |
|
25 |
CONFIDENCE_LEVELS = [HIGH, INFERENCE, INFERENCE_FAILURE, UNDEFINED] |
26 |
|
27 |
|
28 |
class Interface(object): |
29 |
"""Base class for interfaces."""
|
30 |
@classmethod
|
31 |
def is_implemented_by(cls, instance): |
32 |
return implements(instance, cls)
|
33 |
|
34 |
|
35 |
def implements(obj, interface): |
36 |
"""Return true if the give object (maybe an instance or class) implements
|
37 |
the interface.
|
38 |
"""
|
39 |
kimplements = getattr(obj, '__implements__', ()) |
40 |
if not isinstance(kimplements, (list, tuple)): |
41 |
kimplements = (kimplements,) |
42 |
for implementedinterface in kimplements: |
43 |
if issubclass(implementedinterface, interface): |
44 |
return True |
45 |
return False |
46 |
|
47 |
|
48 |
class IChecker(Interface): |
49 |
"""This is an base interface, not designed to be used elsewhere than for
|
50 |
sub interfaces definition.
|
51 |
"""
|
52 |
|
53 |
def open(self): |
54 |
"""called before visiting project (i.e set of modules)"""
|
55 |
|
56 |
def close(self): |
57 |
"""called after visiting project (i.e set of modules)"""
|
58 |
|
59 |
|
60 |
class IRawChecker(IChecker): |
61 |
"""interface for checker which need to parse the raw file
|
62 |
"""
|
63 |
|
64 |
def process_module(self, astroid): |
65 |
""" process a module
|
66 |
|
67 |
the module's content is accessible via astroid.stream
|
68 |
"""
|
69 |
|
70 |
|
71 |
class ITokenChecker(IChecker): |
72 |
"""Interface for checkers that need access to the token list."""
|
73 |
def process_tokens(self, tokens): |
74 |
"""Process a module.
|
75 |
|
76 |
tokens is a list of all source code tokens in the file.
|
77 |
"""
|
78 |
|
79 |
|
80 |
class IAstroidChecker(IChecker): |
81 |
""" interface for checker which prefers receive events according to
|
82 |
statement type
|
83 |
"""
|
84 |
|
85 |
|
86 |
class IReporter(Interface): |
87 |
""" reporter collect messages and display results encapsulated in a layout
|
88 |
"""
|
89 |
def add_message(self, msg_id, location, msg): |
90 |
"""add a message of a given type
|
91 |
|
92 |
msg_id is a message identifier
|
93 |
location is a 3-uple (module, object, line)
|
94 |
msg is the actual message
|
95 |
"""
|
96 |
|
97 |
def display_reports(self, layout): |
98 |
"""display results encapsulated in the layout tree
|
99 |
"""
|
100 |
|
101 |
|
102 |
__all__ = ('IRawChecker', 'IAstroidChecker', 'ITokenChecker', 'IReporter') |