This file is indexed.

/usr/lib/python2.7/dist-packages/PyMca/QSource.py is in pymca 4.7.4+dfsg-1build1.

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
#/*##########################################################################
# Copyright (C) 2004-2013 European Synchrotron Radiation Facility
#
# This file is part of the PyMca X-ray Fluorescence Toolkit developed at
# the ESRF by the Software group.
#
# This toolkit 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.
#
# PyMca 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
# PyMca; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# PyMca follows the dual licensing model of Riverbank's PyQt and cannot be
# used as a free plugin for a non-free program.
#
# Please contact the ESRF industrial unit (industry@esrf.fr) if this license
# is a problem for you.
#############################################################################*/
import sys
from PyMca import PyMcaQt as qt
QTVERSION = qt.qVersion()
DEBUG = 0
SOURCE_EVENT = qt.QEvent.User

if QTVERSION < '4.0.0':
    class SourceEvent(qt.QCustomEvent):
        def __init__(self, ddict=None):
            if ddict is None:
                ddict = {}
            qt.QCustomEvent.__init__(self, SOURCE_EVENT)
            self.dict = ddict
else:
    class SourceEvent(qt.QEvent):
        def __init__(self, ddict=None):
            if ddict is None:
                ddict = {}
            self.dict = ddict
            qt.QEvent.__init__(self, SOURCE_EVENT)

import time
try:
    import thread
except ImportError:
    import _thread as thread
import weakref

class QSource(qt.QObject):
    def __init__(self):
        qt.QObject.__init__(self, None) #no parent

        self.surveyDict = {}
        self.selections = {}
        self._pollTime = 0.7 #700 ms
        self.pollerThreadId = None
       
    def setPollTime(self, pollTime):
        """Set polling time (in milliseconds)"""
        self._pollTime = max(pollTime * 0.001, 0.001)

        return self._pollTime * 1000


    def getPollTime(self):
        return self._pollTime * 1000

    
    def addToPoller(self, dataObject):
        """Set polling for data object"""
        sourceName = dataObject.info['SourceName']

        if sourceName != self.sourceName:
            raise KeyError("Trying to survey key %s on wrong source %s" % (self.sourceName,dataObject.info['SourceName']))
      
        #that is general to any source        
        key        = dataObject.info['Key']
        reference        = id(dataObject)

        def dataObjectDestroyed(ref, dataObjectKey=key, dataObjectRef=reference):
            if DEBUG: 
                print('data object destroyed, key was %s' % dataObjectKey)
                print('data object destroyed, ref was 0x%x' % dataObjectRef)
                print("self.surveyDict[key] = ",self.surveyDict[key])

            n = len(self.surveyDict[dataObjectKey])
            if n > 0:
                n = range(n)
                n.reverse()
                for i in n:
                    if not len(dir(self.surveyDict[dataObjectKey][i])):
                        del self.surveyDict[dataObjectKey][i]

            if len(self.surveyDict[dataObjectKey]) == 0:
                del self.surveyDict[dataObjectKey]
                
            if DEBUG:
                print("SURVEY DICT AFTER DELETION = ", self.surveyDict)            
            return
            
        # create a weak reference to the dataObject and we call it dataObjectRef
        dataObjectRef=weakref.proxy(dataObject, dataObjectDestroyed)

        try:
            if dataObjectRef not in self.surveyDict[key]:
                self.surveyDict[key].append(dataObjectRef)
                self.selections[key].append((id(dataObjectRef), dataObjectRef.info))
        except KeyError:
            self.surveyDict[key] = [dataObjectRef]
            self.selections[key] = [(id(dataObjectRef), dataObjectRef.info)]
        except ReferenceError:
            if DEBUG:
                print("NOT ADDED TO THE POLL dataObject = ", dataObject)
            return

        if DEBUG:
            print("SURVEY DICT AFTER ADDITION = ", self.surveyDict)
        
        if self.pollerThreadId is None:
            # start a new polling thread
            #print "starting new thread"
            self.pollerThreadId = thread.start_new_thread(self.__run, ())


    def __run(self):
        #print "RUN"
        while len(self.surveyDict) > 0:
            #for key in self.surveyDict is dangerous
            # runtime error: dictionnary changed during iteration
            # a mutex is needed
            if DEBUG:
                print("In loop")
            dummy = list(self.surveyDict.keys())
            eventsToPost = {}
            #for key in self.surveyDict:
            for key in dummy:
                if key not in eventsToPost: 
                    eventsToPost[key] = []
                if self.isUpdated(self.sourceName, key):
                    if DEBUG:
                        print(self.sourceName,key,"is updated")
                    try:
                        if len(self.surveyDict[key]):
                            #there are still instances of dataObjects
                            event = SourceEvent()
                            event.dict['Key']   = key
                            event.dict['event'] = 'updated'
                            event.dict['id']    = self.surveyDict[key]
                            scanselection = False
                            if 'scanselection' in self.surveyDict[key][0].info:
                                scanselection = \
                                  self.surveyDict[key][0].info['scanselection']
                            if (key == 'SCAN_D') or scanselection:
                                event.dict['scanselection'] = True
                            else:
                                event.dict['scanselection'] = False
                            try:
                                if QTVERSION < '4.0.0':
                                    qt.qApp.processEvents()
                                    qt.qApp.lock()
                                    # Should one make a list of events to prevent
                                    # posting the same event twice?
                                    qt.QApplication.postEvent(self, event)
                                else:
                                    eventsToPost[key].append(event)
                            finally:
                                if QTVERSION < '4.0.0':
                                    qt.qApp.unlock()
                        else:
                            del self.surveyDict[key]
                            del self.selections[key] 
                    except KeyError:
                        if DEBUG:
                            print("key error in loop")
                        pass
            if QTVERSION > '4.0.0':
                for key in eventsToPost:
                    for event in eventsToPost[key]:
                        qt.QApplication.postEvent(self, event)
                qt.qApp.processEvents()
            time.sleep(self._pollTime)
            if DEBUG:
                print("woke up")
            
        self.pollerThreadId = None
        self.selections = {}