This file is indexed.

/usr/share/pybliographer/Pyblio/GnomeUI/Search.py is in pybliographer 1.2.14-3.

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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
# This file is part of pybliographer
# 
# Copyright (C) 1998-2004 Frederic GOBRY
# Email : gobry@pybliographer.org
# 	   
# 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 2 
# 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, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
# 
# 


""" This module implements the Search dialog """

import os

from gnome import ui
import gtk, gobject

import string, re, sys, traceback, copy

from Pyblio import Types, Search, Config, \
     Connector, TextUI, version

from Pyblio.GnomeUI import Utils


class SearchDialog (Connector.Publisher, Utils.GladeWindow):

    ''' The actual Search Dialog. This dialog is created once, and
    only hidden, not destroyed, to keep it always available in the
    same state.

    This dialog emits a "search-data" signal when a new search
    criterion is selected.
    
    '''

    gladeinfo = { 'name': 'search',
                  'file': 'search.glade',
                  'root': '_w_search'
                  }
    
    def __init__ (self, parent = None):

        Utils.GladeWindow.__init__ (self, parent)

        # the tree model contains a string that explains the query,
        # and a python object representing the actual query.
        
        self._model = gtk.TreeStore (str, gobject.TYPE_PYOBJECT)
        self._w_tree.set_model (self._model)

        # the view does not display the python column, of course.
        col = gtk.TreeViewColumn ('field', gtk.CellRendererText (), text = 0)
        self._w_tree.append_column (col)

        self._w_tree.expand_all ()
        
        # The root of the search tree is the full database
        self._model.append (None, (_("Full database"), None))


        # Monitor the selected items
        self._selection = self._w_tree.get_selection ()
        self._selection.connect ('changed', self.selection)
        
        # fill the combo containing the available fields
        self._w_field.set_popdown_strings ([' - any field - '] +
                                          list (Config.get
                                                ('gnome/searched').data) +
                                          [' - type - ', ' - key - '])

        # connect a menu to the right button
        self.menu = gtk.Menu ()
        self.delete_button = Utils.popup_add (self.menu, _("Delete"),
                                              self.search_delete)
        self.menu.show ()

        # We are set up.
        self.show ()
        return


    def show (self):
        ''' Invoked to show the interface again when it has been closed '''
        
        self._w_search.show ()
        return


    def close_cb (self, widget):
        ''' Invoked to hide the interface when clicking on "Close" '''

        self.size_save ()
        self._w_search.hide ()
        return
    

    def apply_cb (self, widget):

        ''' Construct the new query and add it to the query tree '''
        
        page = self._w_notebook.get_current_page ()

        name = None
        
        # Expert search
        if page == 1:
            
            user_global = {
                's'   :      TextUI._split_req,
                'has' :      TextUI.has,
                'any_has'  : TextUI.any_has,
                'has_key'  : TextUI.has_key,
                'has_type' : TextUI.has_type,
                'before' :   TextUI.before,
                'after' :    TextUI.after,
                }
            
            search = self._w_expert_text.get_text ().encode ('latin-1')
            
            try:
                exec ('tester = ' + search, user_global)
            except:
                etype, value, tb = sys.exc_info ()
		traceback.print_exception (etype, value, tb)

                d = gtk.MessageDialog (self._w_search,
                                       gtk.DIALOG_DESTROY_WITH_PARENT | gtk.DIALOG_MODAL,
                                       gtk.MESSAGE_ERROR, gtk.BUTTONS_OK,
                                       _("internal error during evaluation"))
                d.run ()
                d.destroy ()
                return

            test = user_global ['tester']

        # Simple Search
        elif page == 0:
            
            field = self._w_field_text.get_text ().lower ()
            match = self._w_pattern_text.get_text ()
            
            if match == '': return

            error = 0

            if field == ' - any field - ' or field == '':
                try:
                    test = Search.AnyTester (match.encode ('latin-1'))
                except re.error, err:
                    error = 1
                    
                name = 'any ~ ' + match

            elif field == ' - type - ':
                # get the type description
                the_type = Types.get_entry (string.lower (match), 0)

                if the_type is None:
                    err = ['No such Entry type']
                    error = 1
                else:
                    try:
                        test = Search.TypeTester (the_type)
                    except re.error, err:
                        error = 1

            elif field == ' - key - ':
                try:
                    test = Search.KeyTester (match)
                except re.error, err:
                    error = 1

            else:
                try:
                    test = Search.Tester (field, match)
                except re.error, err:
                    error = 1
                
            if error:
                d = gtk.MessageDialog (self._w_search,
                                       gtk.DIALOG_DESTROY_WITH_PARENT | gtk.DIALOG_MODAL,
                                       gtk.MESSAGE_ERROR, gtk.BUTTONS_OK,
                                       _("while compiling %s\nerror: %s") %
                                       (match, err [0]))
                d.run ()
                d.destroy ()
                return
            
        # No search
        else:
            return

        if name is None:
            name = str (test)

        # Get the path to the query being refined
        s, iter = self._selection.get_selected ()
        if iter is None: iter = s.get_iter ((0,))

        i = s.get_path (iter)

        # If we are refining a previous query, build the new query as
        # a logical and of the previous and new query.
        
        current = self._model [i] [1]
        if current: test = current & test

        # Add the new query in the tree and ensure it is visible and selected.
        iter = self._model.append (iter, (name, test))
        path = s.get_path (iter)
        
        self._w_tree.expand_row (path [:-1], True)
        self._selection.select_path (path)
        return

    
    def selection (self, *arg):

        ''' Called when the user clicks on a specific query '''
        
        s, i = self._selection.get_selected ()
        if i is None: return
        
        data = self._model [s.get_path (i)]

        self.issue ('search-data', * data)
        return

    
    def popup_menu (self, w, event, *arg):

        ''' Called when the user right-clicks in the query tree '''
        
        if (event.type != gtk.gdk.BUTTON_PRESS or
            event.button != 3): return
        
        self.menu.popup (None, None, None, event.button, event.time)

        # Only allow removal when a valid query is selected
        s, i = self._selection.get_selected ()
        self.delete_button.set_sensitive (i is not None and
                                          s [i][1] is not None)
        return
    

    def search_delete (self, *arg):
        
        ''' Called when the user deletes a query in the tree '''

        s, i = self._selection.get_selected ()
        if i is None: return

        # Do not allow removal of the root.
        if s [i][1] is None: return
        
        self._model.remove (i)
        return