~ibmcharmers/charms/trusty/ibm-dsm-enterprise/devel

« back to all changes in this revision

Viewing changes to .tox/py35/lib/python3.5/site-packages/flake8/formatting/default.py

  • Committer: anita nayak
  • Date: 2016-12-08 14:10:42 UTC
  • Revision ID: anitanayak@in.ibm.com-20161208141042-jyicg7udd6liy6s3
Initial Check in for IBM DSM for trusty

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"""Default formatting class for Flake8."""
 
2
from flake8.formatting import base
 
3
 
 
4
 
 
5
class SimpleFormatter(base.BaseFormatter):
 
6
    """Simple abstraction for Default and Pylint formatter commonality.
 
7
 
 
8
    Sub-classes of this need to define an ``error_format`` attribute in order
 
9
    to succeed. The ``format`` method relies on that attribute and expects the
 
10
    ``error_format`` string to use the old-style formatting strings with named
 
11
    parameters:
 
12
 
 
13
    * code
 
14
    * text
 
15
    * path
 
16
    * row
 
17
    * col
 
18
 
 
19
    """
 
20
 
 
21
    error_format = None
 
22
 
 
23
    def format(self, error):
 
24
        """Format and write error out.
 
25
 
 
26
        If an output filename is specified, write formatted errors to that
 
27
        file. Otherwise, print the formatted error to standard out.
 
28
        """
 
29
        return self.error_format % {
 
30
            "code": error.code,
 
31
            "text": error.text,
 
32
            "path": error.filename,
 
33
            "row": error.line_number,
 
34
            "col": error.column_number,
 
35
        }
 
36
 
 
37
 
 
38
class Default(SimpleFormatter):
 
39
    """Default formatter for Flake8.
 
40
 
 
41
    This also handles backwards compatibility for people specifying a custom
 
42
    format string.
 
43
    """
 
44
 
 
45
    error_format = '%(path)s:%(row)d:%(col)d: %(code)s %(text)s'
 
46
 
 
47
    def after_init(self):
 
48
        """Check for a custom format string."""
 
49
        if self.options.format.lower() != 'default':
 
50
            self.error_format = self.options.format
 
51
 
 
52
 
 
53
class Pylint(SimpleFormatter):
 
54
    """Pylint formatter for Flake8."""
 
55
 
 
56
    error_format = '%(path)s:%(row)d: [%(code)s] %(text)s'
 
57
 
 
58
 
 
59
class FilenameOnly(SimpleFormatter):
 
60
    """Only print filenames, e.g., flake8 -q."""
 
61
 
 
62
    error_format = '%(path)s'
 
63
 
 
64
    def after_init(self):
 
65
        """Initialize our set of filenames."""
 
66
        self.filenames_already_printed = set()
 
67
 
 
68
    def show_source(self, error):
 
69
        """Do not include the source code."""
 
70
        pass
 
71
 
 
72
    def format(self, error):
 
73
        """Ensure we only print each error once."""
 
74
        if error.filename not in self.filenames_already_printed:
 
75
            self.filenames_already_printed.add(error.filename)
 
76
            return super(FilenameOnly, self).format(error)
 
77
 
 
78
 
 
79
class Nothing(base.BaseFormatter):
 
80
    """Print absolutely nothing."""
 
81
 
 
82
    def format(self, error):
 
83
        """Do nothing."""
 
84
        pass
 
85
 
 
86
    def show_source(self, error):
 
87
        """Do not print the source."""
 
88
        pass