This file is indexed.

/usr/lib/python2.7/dist-packages/apptools/template/impl/value_data_name_item.py is in python-apptools 4.3.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
 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
#-------------------------------------------------------------------------------
#
#  A concrete implementation of the ITemplateDataNameItem interface that looks
#  for a specified named value in its input context or optionally in any of its
#  sub-contexts and outputs a context containing only those values that match
#  the specified name.
#
#  Written by: David C. Morrill
#
#  Date: 07/29/2007
#
#  (c) Copyright 2007 by Enthought, Inc.
#
#-------------------------------------------------------------------------------

""" A concrete implementation of the ITemplateDataNameItem interface that looks
    for a specified named value in its input context or optionally in any of its
    sub-contexts and outputs a context containing only those values that match
    the specified name.
"""

#-------------------------------------------------------------------------------
#  Imports:
#-------------------------------------------------------------------------------

from traits.api \
    import Bool

from apptools.template.template_traits \
    import TStr, TBool

from apptools.template.template_choice \
    import TemplateChoice

from apptools.template.itemplate_data_context \
    import ITemplateDataContext

from any_data_name_item \
    import AnyDataNameItem

from helper \
    import parse_name, path_for

#-------------------------------------------------------------------------------
#  Constants:
#-------------------------------------------------------------------------------

# Value used to reset to the factory settings:
ResetChoice = '--<Reset>--'

#-------------------------------------------------------------------------------
#  'ValueDataNameItem' class:
#-------------------------------------------------------------------------------

class ValueDataNameItem ( AnyDataNameItem ):
    """ A concrete implementation of the ITemplateDataNameItem interface that
        looks for a specified named value in its input context or optionally in
        any of its sub-contexts and outputs a context containing only those
        values that match the specified name.
    """

    #-- Public Traits ----------------------------------------------------------

    # The name of the value to be matched:
    name = TStr

    # (Override) Should included sub-contexts be flattened into a single
    # context?
    flatten = True

    #-- Private Traits ---------------------------------------------------------

    # The current name of the value to be matched:
    current_name = TStr

    # The current name's last component:
    current_name_last = TStr

    # Should all possible choices be included?
    all_choices = Bool( True )

    #-- AnyDataNameItem Property Implementation Overrides ----------------------

    def _get_data_name_item_choice ( self ):
        return TemplateChoice( choice_value = self.current_name )

    def _set_data_name_item_choice ( self, choice ):
        if choice.choice_value == ResetChoice:
            self.current_recursive = self.recursive
            self.current_name      = self.name
            self.all_choices       = True
        else:
            self.current_recursive = False
            self.current_name      = choice.choice_value
            self.all_choices       = False

    def _get_data_name_item_choices ( self ):
        context = self.input_data_context
        if context is None:
            return []

        if not self.all_choices:
            output_context = self.output_data_context
            if output_context is not None:
                return [ TemplateChoice( choice_value = name )
                          for name in output_context.data_context_values ]

        return ([ TemplateChoice( choice_value = ResetChoice ) ] +
                self._get_choices( context ))

    def _get_current_input_data_context ( self ):
        context = self.input_data_context
        for name in parse_name( self.current_name )[:-1]:
            if name not in context.data_contexts:
                return None

            context = context.get_data_context( name )

        return context

    #-- Abstract Method Implementations ----------------------------------------

    def filter ( self, name, value ):
        """ Returns **True** if the specified context data *name* and *value*
            should be included in the output context; and **False** otherwise.
        """
        return (name == self.current_name_last)

    #-- Trait Event Handlers ---------------------------------------------------

    def _name_changed ( self, name ):
        """ Handles the 'name' trait being changed.
        """
        self.current_name = name

    def _current_name_changed ( self, name ):
        self.current_name_last = parse_name( name )[-1]
        self.inputs_changed()

    #-- Private Methods --------------------------------------------------------

    def _get_choices ( self, context, path = '' ):
        """ Returns the list of available user settings choices for the
            specified context.
        """
        choices = [ TemplateChoice( choice_value = path_for( path, name ) )
                    for name in context.data_context_values ]

        if self.recursive:
            # Now process all of the context's sub-contexts:
            gdc = context.get_data_context
            for name in context.data_contexts:
                choices.extend( self._get_choices( gdc( name ), path_for( path,
                                    context.data_context_name ) ) )

        return choices