File: cve_role.py

package info (click to toggle)
python-django 1%3A1.10.7-2%2Bdeb9u9
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 46,768 kB
  • sloc: python: 210,877; javascript: 18,032; xml: 201; makefile: 198; sh: 145
file content (27 lines) | stat: -rw-r--r-- 877 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
"""
An interpreted text role to link docs to CVE issues. To use: :cve:`XXXXX`
"""
from docutils import nodes, utils
from docutils.parsers.rst import roles


def cve_role(name, rawtext, text, lineno, inliner, options=None, content=None):
    if options is None:
        options = {}

    url_pattern = inliner.document.settings.env.app.config.cve_url
    if url_pattern is None:
        msg = inliner.reporter.warning("cve not configured: please configure cve_url in conf.py")
        prb = inliner.problematic(rawtext, rawtext, msg)
        return [prb], [msg]

    url = url_pattern % text
    roles.set_classes(options)
    node = nodes.reference(rawtext, utils.unescape('CVE-%s' % text), refuri=url, **options)
    return [node], []


def setup(app):
    app.add_config_value('cve_url', None, 'env')
    app.add_role('cve', cve_role)
    return {'parallel_read_safe': True}