예제 #1
0
    def _serve_settings(self):
        ''' Serve the settings page '''
        db = View.get().db
        settings = db.load_settings()
        s = []

        for name, value in settings.items():
            if isinstance(value, list):
                s.append('<tr><td>%s</td><td><i>%s</i></td></tr>' %
                         (html.escape(name), html.escape(json.dumps(value))))
            else:
                s.append('<tr><td>%s</td><td><i>%s</i></td></tr>' %
                         (html.escape(name), html.escape(str(value))))

        self._write_template('settings.html', {'settings': '\n\t'.join(s)})
예제 #2
0
    def _serve_report(self, id, kinds_filter):
        ''' Serve a specific report for a file '''
        id = int(id)
        view_report = View.get().report

        try:
            file = view_report.files[id]
        except IndexError:
            self._serve_not_found()
            return

        try:
            with io.open(file.path, 'r', encoding='utf-8',
                         errors='ignore') as f:
                code = f.read()
        except (OSError, IOError):
            self._serve_error("No such file: %s" % file.path)
            return

        fmt = Formatter(file)
        lexer = CppLexer(stripnl=False)
        code = highlight(code, lexer, fmt)
        check_kinds_filter = self._check_kinds_filter(param=kinds_filter)
        self._write_template(
            'report.html', {
                'filepath': html.escape(report.format_path(file.path)),
                'check_kinds': json.dumps(self._check_kinds()),
                'check_kinds_filter': json.dumps(check_kinds_filter),
                'code': code,
                'functions': json.dumps(fmt.functions),
                'call_contexts': json.dumps(fmt.call_contexts),
                'checks': json.dumps(fmt.checks),
                'pygments_css': fmt.get_style_defs('.highlight')
            })
예제 #3
0
def dummy_highlight(data, lexer, formatter):
    lines = ((1, html.escape(line)) for line in data.split('\n'))
    code = ''
    for _, line in formatter.wrap(lines, None):
        code += line
    return code
예제 #4
0
 def _serve_error(self, message):
     ''' Server a 500 Internal Error page '''
     self._write_template('error.html', {'message': html.escape(message)},
                          status=500)
예제 #5
0
 def _serve_not_found(self):
     ''' Server a 404 Not Found page '''
     self._write_template('not_found.html',
                          {'path': html.escape(self.path)},
                          status=404)