Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Static Public Attributes
suspicious.CheckSuspiciousMarkupBuilder Class Reference
Inheritance diagram for suspicious.CheckSuspiciousMarkupBuilder:
Inheritance graph
[legend]
Collaboration diagram for suspicious.CheckSuspiciousMarkupBuilder:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def init
def get_outdated_docs
def get_target_uri
def prepare_writing
def write_doc
def finish
def check_issue
def is_ignored
def report_issue
def write_log_entry
def load_rules

Public Attributes

 log_file_name
 any_issue
 docname
 rules

Static Public Attributes

string name = 'suspicious'

Detailed Description

Checks for possibly invalid markup that may leak into the output.

Definition at line 79 of file suspicious.py.


Member Function Documentation

def suspicious.CheckSuspiciousMarkupBuilder.check_issue (   self,
  line,
  lineno,
  issue 
)

Definition at line 112 of file suspicious.py.

00112 
00113     def check_issue(self, line, lineno, issue):
00114         if not self.is_ignored(line, lineno, issue):
00115             self.report_issue(line, lineno, issue)

Here is the call graph for this function:

Definition at line 109 of file suspicious.py.

00109 
00110     def finish(self):
00111         return

Here is the caller graph for this function:

Definition at line 93 of file suspicious.py.

00093 
00094     def get_outdated_docs(self):
00095         return self.env.found_docs

def suspicious.CheckSuspiciousMarkupBuilder.get_target_uri (   self,
  docname,
  typ = None 
)

Definition at line 96 of file suspicious.py.

00096 
00097     def get_target_uri(self, docname, typ=None):
00098         return ''

Definition at line 85 of file suspicious.py.

00085 
00086     def init(self):
00087         # create output file
00088         self.log_file_name = os.path.join(self.outdir, 'suspicious.csv')
00089         open(self.log_file_name, 'w').close()
00090         # load database of previously ignored issues
00091         self.load_rules(os.path.join(os.path.dirname(__file__),
00092                                      'susp-ignored.csv'))

Here is the caller graph for this function:

def suspicious.CheckSuspiciousMarkupBuilder.is_ignored (   self,
  line,
  lineno,
  issue 
)
Determine whether this issue should be ignored.

Definition at line 116 of file suspicious.py.

00116 
00117     def is_ignored(self, line, lineno, issue):
00118         """Determine whether this issue should be ignored."""
00119         docname = self.docname
00120         for rule in self.rules:
00121             if rule.docname != docname: continue
00122             if rule.issue != issue: continue
00123             # Both lines must match *exactly*. This is rather strict,
00124             # and probably should be improved.
00125             # Doing fuzzy matches with levenshtein distance could work,
00126             # but that means bringing other libraries...
00127             # Ok, relax that requirement: just check if the rule fragment
00128             # is contained in the document line
00129             if rule.line not in line: continue
00130             # Check both line numbers. If they're "near"
00131             # this rule matches. (lineno=None means "don't care")
00132             if (rule.lineno is not None) and \
00133                 abs(rule.lineno - lineno) > 5: continue
00134             # if it came this far, the rule matched
00135             return True
00136         return False

Here is the caller graph for this function:

Load database of previously ignored issues.

A csv file, with exactly the same format as suspicious.csv
Fields: document name (normalized), line number, issue, surrounding text

Definition at line 167 of file suspicious.py.

00167 
00168     def load_rules(self, filename):
00169         """Load database of previously ignored issues.
00170 
00171         A csv file, with exactly the same format as suspicious.csv
00172         Fields: document name (normalized), line number, issue, surrounding text
00173         """
00174         self.info("loading ignore rules... ", nonl=1)
00175         self.rules = rules = []
00176         try:
00177             if py3:
00178                 f = open(filename, 'r')
00179             else:
00180                 f = open(filename, 'rb')
00181         except IOError:
00182             return
00183         for i, row in enumerate(csv.reader(f)):
00184             if len(row) != 4:
00185                 raise ValueError(
00186                     "wrong format in %s, line %d: %s" % (filename, i+1, row))
00187             docname, lineno, issue, text = row
00188             if lineno:
00189                 lineno = int(lineno)
00190             else:
00191                 lineno = None
00192             if not py3:
00193                 docname = docname.decode('utf-8')
00194                 issue = issue.decode('utf-8')
00195                 text = text.decode('utf-8')
00196             rule = Rule(docname, lineno, issue, text)
00197             rules.append(rule)
00198         f.close()
00199         self.info('done, %d rules loaded' % len(self.rules))
00200 

Here is the call graph for this function:

Definition at line 99 of file suspicious.py.

00099 
00100     def prepare_writing(self, docnames):
00101         pass

def suspicious.CheckSuspiciousMarkupBuilder.report_issue (   self,
  text,
  lineno,
  issue 
)

Definition at line 137 of file suspicious.py.

00137 
00138     def report_issue(self, text, lineno, issue):
00139         if not self.any_issue: self.info()
00140         self.any_issue = True
00141         self.write_log_entry(lineno, issue, text)
00142         if py3:
00143             self.warn('[%s:%d] "%s" found in "%-.120s"' %
00144                       (self.docname, lineno, issue, text))
00145         else:
00146             self.warn('[%s:%d] "%s" found in "%-.120s"' % (
00147                 self.docname.encode(sys.getdefaultencoding(),'replace'),
00148                 lineno,
00149                 issue.encode(sys.getdefaultencoding(),'replace'),
00150                 text.strip().encode(sys.getdefaultencoding(),'replace')))
00151         self.app.statuscode = 1

Here is the call graph for this function:

Here is the caller graph for this function:

def suspicious.CheckSuspiciousMarkupBuilder.write_doc (   self,
  docname,
  doctree 
)

Definition at line 102 of file suspicious.py.

00102 
00103     def write_doc(self, docname, doctree):
00104         # set when any issue is encountered in this document
00105         self.any_issue = False
00106         self.docname = docname
00107         visitor = SuspiciousVisitor(doctree, self)
00108         doctree.walk(visitor)

def suspicious.CheckSuspiciousMarkupBuilder.write_log_entry (   self,
  lineno,
  issue,
  text 
)

Definition at line 152 of file suspicious.py.

00152 
00153     def write_log_entry(self, lineno, issue, text):
00154         if py3:
00155             f = open(self.log_file_name, 'a')
00156             writer = csv.writer(f, dialect)
00157             writer.writerow([self.docname, lineno, issue, text.strip()])
00158             f.close()
00159         else:
00160             f = open(self.log_file_name, 'ab')
00161             writer = csv.writer(f, dialect)
00162             writer.writerow([self.docname.encode('utf-8'),
00163                              lineno,
00164                              issue.encode('utf-8'),
00165                              text.strip().encode('utf-8')])
00166             f.close()

Here is the caller graph for this function:


Member Data Documentation

Definition at line 104 of file suspicious.py.

Definition at line 105 of file suspicious.py.

Definition at line 87 of file suspicious.py.

Definition at line 83 of file suspicious.py.

Definition at line 174 of file suspicious.py.


The documentation for this class was generated from the following file: