This file is indexed.

/usr/lib/python2.7/dist-packages/trytond/model/fields/one2one.py is in tryton-server 3.4.0-3+deb8u3.

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
#This file is part of Tryton.  The COPYRIGHT file at the top level of
#this repository contains the full copyright notices and license terms.
from types import NoneType

from trytond.model.fields.field import Field
from trytond.model.fields.many2many import Many2Many
from trytond.pool import Pool


class One2One(Many2Many):
    '''
    Define one2one field (``int``).
    '''
    _type = 'one2one'

    def get(self, ids, model, name, values=None):
        '''
        Return target record.

        :param ids: a list of ids
        :param model: a string with the name of the model
        :param name: a string with the name of the field
        :param values: a dictionary with the read values
        :return: a dictionary with ids as key and target id as value
        '''
        res = super(One2One, self).get(ids, model, name, values=values)
        for i, vals in res.iteritems():
            res[i] = vals[0] if vals else False
        return res

    def set(self, Model, name, ids, value, *args):
        '''
        Set the values.
        '''
        pool = Pool()
        Relation = pool.get(self.relation_name)
        to_delete = []
        to_create = []
        args = iter((ids, value) + args)
        for ids, value in zip(args, args):
            relations = Relation.search([
                    (self.origin, 'in', ids),
                    ])
            to_delete.extend(relations)
            if value:
                to_create = []
                for record_id in ids:
                    to_create.append({
                            self.origin: record_id,
                            self.target: value,
                            })
        if to_delete:
            Relation.delete(to_delete)
        if to_create:
            Relation.create(to_create)

    def __set__(self, inst, value):
        Target = self.get_target()
        if isinstance(value, dict):
            value = Target(*value)
        elif isinstance(value, (int, long)):
            value = Target(value)
        assert isinstance(value, (Target, NoneType))
        Field.__set__(self, inst, value)