This file is indexed.

/usr/lib/python3/dist-packages/cloud_sptheme/ext/perpage.py is in python3-cloud-sptheme 1.8.0-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

 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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
"""cloud_sptheme.ext.perpage -- override sphinx config per-page

* perpage_html_logo -- glob map (ala html_sidebars), used to change sidebar logo per-page

.. todo::
    document this extension
"""
#=============================================================================
# imports
#=============================================================================
# core
import os.path
import re
import logging; log = logging.getLogger(__name__)
# site
from sphinx.util.matching import patmatch
#pkg
from cloud_sptheme import __version__
# local
#=============================================================================
# helpers
#=============================================================================
def _rank_pattern(pattern):
    """return sorting key for prioritizing which glob pattern should match"""
    # TODO: add more ways to distinguish patterns if both have wildcards
    return not any(char in pattern for char in '*?[')

def bestmatch(patmap, source, default=None, param="source"):
    """return best match given a dictionary mapping glob pattersn -> values"""
    best = None
    best_rank = None
    for pattern in patmap:
        if not patmatch(pattern, source):
            continue
        cur_rank = _rank_pattern(pattern)
        if best is None or cur_rank < best_rank:
            best = pattern
            best_rank = cur_rank
        elif cur_rank == best_rank:
            raise KeyError("%s %r matches too many patterns: %r and %r" %
                           (param, source, best, pattern))
    if best is None:
        return default
    else:
        return patmap[best]

#=============================================================================
# sphinx hooks
#=============================================================================
def perpage_html_logo(app, pagename, templatename, ctx, event_arg):
    """helper to override sidebar logo per-page"""
    patmap = getattr(app.config, "perpage_html_logo", {})
    logo = bestmatch(patmap, pagename, ctx.get("logo"), param="pagename")
    if logo is None:
        ctx.pop("logo", None)
    else:
        ctx['logo'] = logo

# NOTE: this works, just don't have a use for it yet
##def perpage_html_theme_options(app, pagename, templatename, ctx, event_arg):
##    patmap = getattr(app.config, "perpage_html_theme_options")
##    if not patmap:
##        return
##    values = bestmatch(patmap, pagename, None, param="pagename")
##    if values:
##        for key, value in values.items():
##            # TODO: validate 'key' is valid theme option
##            ctx['theme_' + key] = value

#=============================================================================
# sphinx init
#=============================================================================
def setup(app):
    app.add_config_value('perpage_html_logo', None, 'env')
    ##app.add_config_value('perpage_html_theme_options', None, 'env')
    app.connect('html-page-context', perpage_html_logo)
    ##app.connect('html-page-context', perpage_html_theme_options)

    # identifies the version of our extension
    return {'version': __version__}

#=============================================================================
# eof
#=============================================================================