This file is indexed.

/usr/share/python-odf/examples/datatable.py is in python-odf-doc 1.3.6-2.

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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (C) 2007 Søren Roug, European Environment Agency
#
# This is free software.  You may redistribute it under the terms
# of the Apache license and the GNU General Public License Version
# 2 or at your option any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public
# License along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
#
# Contributor(s):
#

from odf import  table, text

def valuetype(val):
    valuetype="string"
    if isinstance(val,str): valuetype="string"
    if isinstance(val,int): valuetype="float"
    if isinstance(val,float): valuetype="float"
    if isinstance(val,bool): valuetype="boolean"
    return valuetype

class DataTable(object):

    def __init__(self, values=()):
        self.values = values
        self.datasourcehaslabels = "none"

    def _set_values(self, value):
        if isinstance(value, list) or isinstance(value, tuple):
            self.__dict__['values'] = value
            firstrow = value[0]
            if isinstance(firstrow, list) or isinstance(firstrow, tuple):
                self.numcols = len(firstrow)
            else:
                self.numcols = 1
        else:
            raise ValueError, "Value must be list or tuple"

    def __setattr__(self, name, value):
        if name == 'values':
            self._set_values(value)
        else:
            self.__dict__[name] = value

    def __call__(self):
        datatable = table.Table(name="local-table")
        if self.datasourcehaslabels in ('row','both'):
            t = table.TableHeaderColumns()
            t.addElement(table.TableColumn())
            datatable.addElement(t)

        t = table.TableColumns()
        if self.datasourcehaslabels in ('row','both'):
            t.addElement(table.TableColumn(numbercolumnsrepeated=str(self.numcols-1)))
        else:
            t.addElement(table.TableColumn(numbercolumnsrepeated=str(self.numcols)))
        datatable.addElement(t)

        if self.datasourcehaslabels in ('column','both'):
            t = table.TableHeaderRows()
            datatable.addElement(t)
            tr = table.TableRow()
            t.addElement(tr)
            content = self.values[0]
            for val in content:
                tc = table.TableCell(valuetype=valuetype(val))
                tr.addElement(tc)
                tc.addElement(text.P(text=str(val)))

        t = table.TableRows()
        datatable.addElement(t)
        rownum = 0
        for content in self.values:
            if rownum == 0 and self.datasourcehaslabels in ('column','both'):
                rownum += 1
                continue
            tr = table.TableRow()
            t.addElement(tr)
            for val in content:
                tc = table.TableCell(valuetype=valuetype(val), value=val)
                tr.addElement(tc)
                tc.addElement(text.P(text=str(val)))
            rownum += 1
        return datatable