Back to index

python3.2  3.2.2
Classes | Functions | Variables
suspicious Namespace Reference

Classes

class  Rule
class  dialect
class  CheckSuspiciousMarkupBuilder
class  SuspiciousVisitor

Functions

def get_lineno
def extract_line

Variables

tuple detect_all
tuple py3 = sys.version_info>(3, 0)

Detailed Description

Try to detect suspicious constructs, resembling markup
that has leaked into the final output.

Suspicious lines are reported in a comma-separated-file,
``suspicious.csv``, located in the output directory.

The file is utf-8 encoded, and each line contains four fields:

 * document name (normalized)
 * line number in the source document
 * problematic text
 * complete line showing the problematic text in context

It is common to find many false positives. To avoid reporting them
again and again, they may be added to the ``ignored.csv`` file
(located in the configuration directory). The file has the same
format as ``suspicious.csv`` with a few differences:

  - each line defines a rule; if the rule matches, the issue
    is ignored.
  - line number may be empty (that is, nothing between the
    commas: ",,"). In this case, line numbers are ignored (the
    rule matches anywhere in the file).
  - the last field does not have to be a complete line; some
    surrounding text (never more than a line) is enough for
    context.

Rules are processed sequentially. A rule matches when:

 * document names are the same
 * problematic texts are the same
 * line numbers are close to each other (5 lines up or down)
 * the rule text is completely contained into the source line

The simplest way to create the ignored.csv file is by copying
undesired entries from suspicious.csv (possibly trimming the last
field.)

Copyright 2009 Gabriel A. Genellina

Function Documentation

def suspicious.extract_line (   text,
  index 
)
text may be a multiline string; extract
only the line containing the given character index.

>>> extract_line("abc\ndefgh\ni", 6)
>>> 'defgh'
>>> for i in (0, 2, 3, 4, 10):
...   print extract_line("abc\ndefgh\ni", i)
abc
abc
abc
defgh
defgh
i

Definition at line 210 of file suspicious.py.

00210 
00211 def extract_line(text, index):
00212     """text may be a multiline string; extract
00213     only the line containing the given character index.
00214 
00215     >>> extract_line("abc\ndefgh\ni", 6)
00216     >>> 'defgh'
00217     >>> for i in (0, 2, 3, 4, 10):
00218     ...   print extract_line("abc\ndefgh\ni", i)
00219     abc
00220     abc
00221     abc
00222     defgh
00223     defgh
00224     i
00225     """
00226     p = text.rfind('\n', 0, index) + 1
00227     q = text.find('\n', index)
00228     if q < 0:
00229         q = len(text)
00230     return text[p:q]
00231 

def suspicious.get_lineno (   node)
Obtain line number information for a node.

Definition at line 201 of file suspicious.py.

00201 
00202 def get_lineno(node):
00203     """Obtain line number information for a node."""
00204     lineno = None
00205     while lineno is None and node:
00206         node = node.parent
00207         lineno = node.line
00208     return lineno
00209 


Variable Documentation

Initial value:
00001 re.compile(r'''
00002     ::(?=[^=])|            # two :: (but NOT ::=)
00003     :[a-zA-Z][a-zA-Z0-9]+| # :foo
00004     `|                     # ` (seldom used by itself)
00005     (?<!\.)\.\.[ \t]*\w+:  # .. foo: (but NOT ... else:)
00006     ''', re.UNICODE | re.VERBOSE)

Definition at line 52 of file suspicious.py.

tuple suspicious.py3 = sys.version_info>(3, 0)

Definition at line 59 of file suspicious.py.