This file is indexed.

/usr/lib/python3/dist-packages/pymoc/io/ascii.py is in python3-pymoc 0.4.2-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
# Copyright (C) 2014 Science and Technology Facilities Council.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, 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, see <http://www.gnu.org/licenses/>.

from __future__ import unicode_literals


def write_moc_ascii(moc, filename=None, file=None):
    """Write a MOC to an ASCII file.

    Either a filename, or an open file object can be specified.
    """

    orders = []

    for (order, cells) in moc:
        ranges = []
        rmin = rmax = None

        for cell in sorted(cells):
            if rmin is None:
                rmin = rmax = cell
            elif rmax == cell - 1:
                rmax = cell
            else:
                ranges.append(_format_range(rmin, rmax))
                rmin = rmax = cell

        ranges.append(_format_range(rmin, rmax))

        orders.append('{0}'.format(order) + '/' + ','.join(ranges))

    if file is not None:
        _write_ascii(orders, file)
    else:
        with open(filename, 'w') as f:
            _write_ascii(orders, f)


def read_moc_ascii(moc, filename=None, file=None):
    """Read from an ASCII file into a MOC.

    Either a filename, or an open file object can be specified.
    """

    if file is not None:
        orders = _read_ascii(file)
    else:
        with open(filename, 'r') as f:
            orders = _read_ascii(f)

    for text in orders:
        cells = []
        (order, ranges) = text.split('/')
        for r in ranges.split(','):
            try:
                cells.append(int(r))
            except ValueError as e:
                (rmin, rmax) = r.split('-')
                cells.extend(range(int(rmin), int(rmax) + 1))

        moc.add(order, cells)


def _write_ascii(orders, f):
    f.write(' '.join(orders))


def _read_ascii(f):
    text = f.read()

    return text.strip().split(' ')


def _format_range(rmin, rmax):
    if rmin == rmax:
        return '{0}'.format(rmin)
    elif rmax == rmin + 1:
        return '{0},{1}'.format(rmin, rmax)
    else:
        return '{0}-{1}'.format(rmin, rmax)