This file is indexed.

/usr/share/pyshared/bimdp/inspection/slideshow.py is in python-mdp 3.3-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
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
"""
Module for HTML trace slideshows.

The individual slides are the HTML files generated via the trace_inspection
module (the body of the HTML files is extracted and makes up a slide).
"""

from __future__ import with_statement

import os

from mdp.utils import HTMLSlideShow, SectionHTMLSlideShow


class ExecuteHTMLSlideShow(HTMLSlideShow):

    def __init__(self, filenames, node_ids, delay=500, delay_delta=100,
                  loop=False, **kwargs):
        """Return the complete HTML code for the slideshow.

        filenames -- Sequence of strings, containing the path for each slide.
        node_ids -- Sequence of the active node ids for each slide.
        """
        kwargs.update(vars())
        # create a list of the possible node ids
        unique_node_ids = list(set(node_ids))
        kwargs["unique_node_ids"] = unique_node_ids
        del kwargs["self"]
        super(ExecuteHTMLSlideShow, self).__init__(**kwargs)

    _SLIDESHOW_CSS_FILENAME = "trace_slideshow.css"

    @classmethod
    def slideshow_css(cls):
        css_filename = os.path.join(os.path.split(__file__)[0],
                                    cls._SLIDESHOW_CSS_FILENAME)
        with open(css_filename, 'r') as css_file:
            css = css_file.read()
        return css

    js_loadslide_template = r'''

    // maps slide index to active node id
    var slide_node_ids = $node_ids;
    // list of all node ids that are available
    var unique_node_ids = $unique_node_ids;

    $<js_loadhtml_template>

    that.loadSlide = function () {
        loadPage(slideselect[current_slide].value);
    }

    // is called by loadPage after the loading has happened
    function makeNodesClickable() {
        var i;
        for (i = 0; i < unique_node_ids.length; i += 1) {
            try {
                document.getElementById(unique_node_ids[i]).
                    addEventListener("click", nodeClickCallback, false);
            }
            catch (e) {
                // means that the requested node is added in a later training
                // phase and is therefore not yet in the DOM
            }
        }
    }

    function nodeClickCallback() {
        // TODO: use event.srcElement for IE (event.target for W3C)
        var node_id = this.id;
        // search for next occurance of this node id
        var i;
        for (i = current_slide + 1; i < slide_node_ids.length; i += 1) {
            if (slide_node_ids[i] === node_id) {
                current_slide = i;
                that.updateSlide();
                return;
            }
        }
        // alert("Node is not reached after this slide.");
    }

'''

    js_loadhtml_template = r'''
    /**
     * Code to load the body content from HTMl files and inject it.
     * inspired by http://www.xul.fr/ajax/responseHTML-attribute.html
     */

    // Extract body content from html content.
    function getBody(content) {
        var lowContent = content.toLowerCase();  // eliminate case sensitivity
        // deal with attributes
        var i_start = lowContent.indexOf("<body");
        if (i_start === -1) {
            return "";
        }
        i_start = lowContent.indexOf(">", i_start);
        if (i_start === -1) {
            return "";
        }
        var i_end = lowContent.lastIndexOf("</body>");
        if (i_end === -1) {
            i_end = lowContent.lastIndexOf("</html>");
        }
        // if no HTML then just grab everything till end.
        if (i_end === -1) {
            i_end = content.length;
        }
        return content.slice(i_start + 1, i_end);
    }

    // Return a XMLHttpRequest object (browser independent).
    function getXHR()
    {
        var request = false;
            try {
                request = new ActiveXObject('Msxml2.XMLHTTP');
            }
            catch (err2) {
                try {
                    request = new ActiveXObject('Microsoft.XMLHTTP');
                }
                catch (err3) {
                    try {
                        request = new XMLHttpRequest();
                    }
                    catch (err1) {
                        request = false;
                    }
                }
            }
        return request;
    }

    // Load an HTML page and inject the content.
    function loadPage(url) {
        var target = document.getElementById("html_display");
        var xhr = getXHR();
        xhr.onreadystatechange = function() {
            if(xhr.readyState == 4) {
                target.innerHTML = getBody(xhr.responseText);
                makeNodesClickable();
            }
        }
        xhr.open("GET", url, true);
        xhr.send(null);
    }
    '''

    # Note: We do not use an id prefix, since there is only one slideshow.
    html_bottom_template = r'''
<div id="html_display"></div>
'''


class SectExecuteHTMLSlideShow(SectionHTMLSlideShow, ExecuteHTMLSlideShow):
    """Execute slideshow with support for sections."""
    pass


class TrainHTMLSlideShow(SectionHTMLSlideShow, ExecuteHTMLSlideShow):

    def __init__(self, filenames, node_ids, index_table, **kwargs):
        """Return the complete HTML code for the slideshow.

        filenames -- Sequence of strings, containing the path for each slide.
        node_ids -- Sequence of the active node ids for each slide.
        index_table -- Nested lists with the index data generated by
            inspect_biflow_training (last slide indexed by node, phase, train
            and stop).
        """
        slideshow_id = self._get_random_id()
        n_nodes = len(index_table)
        n_phases = max([len(phase_indices)
                        for phase_indices in index_table])
        # create the table and mapping between slide index and phase and node
        train_id = 0  # id indexing phase, node and train or stop
        start_index = 0  # first slide index for the current phase
        end_index = 0  # last slide index for the current phase
        section_ids = []
        train_table = [[None for _ in range(n_nodes + 1)]
                       for _ in range(n_phases + 1)]
        # create labels for table
        train_table[0] = ['&nbsp;'] + ['node %d' % (i+1)
                                       for i in range(n_nodes)]
        for i_phase in range(n_phases):
            train_table[i_phase+1][0] = 'phase %d' % (i_phase + 1)
        for i_node in range(n_nodes):
            for i_phase in range(len(index_table[i_node])):
                end_index = index_table[i_node][i_phase][0]
                # train link stuff
                html_string = ('<span class="inactive_section" ' +
                        'id="%s_section_id_%d" ' % (slideshow_id, train_id) +
                        'onClick="%s.setSlide(%d);">train</span>' %
                            (slideshow_id, start_index) +
                        '&nbsp;')
                section_ids += [train_id,] * (end_index - start_index + 1)
                train_id += 1
                # stop link stuff
                start_index = end_index + 1
                end_index = index_table[i_node][i_phase][1]
                if start_index > end_index:
                    # this can happen due to an exception during training
                    start_index = end_index
                else:
                    html_string += ('<span class="inactive_section" ' +
                        'id="%s_section_id_%d" ' % (slideshow_id, train_id) +
                        'onClick="%s.setSlide(%d);">stop</span>' %
                            (slideshow_id, start_index))
                train_table[i_phase+1][i_node+1] = html_string
                section_ids += [train_id,] * (end_index - start_index + 1)
                train_id += 1
                start_index = end_index + 1
        kwargs["control_table"] = train_table
        kwargs["section_ids"] = section_ids
        kwargs["filenames"] = filenames
        kwargs.update(vars())
        del kwargs["self"]
        del kwargs["index_table"]
        super(TrainHTMLSlideShow, self).__init__(**kwargs)

    html_top_template = r'''
<table class="slideshow">
${{
for row in control_table:
    self.write('<tr>\n')
    for cell in row:
        self.write('<td> %s </td>\n' % cell)
    self.write('</tr>\n')
}}
</table>
<br>
'''

    html_controls_template = r'''
${{super(SectionHTMLSlideShow, self).html_controls_template(vars())}}
'''