This file is indexed.

/usr/lib/python2.7/dist-packages/sardana/spock/inputhandler.py is in python-sardana 1.6.1-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
157
158
159
160
161
162
163
164
165
166
#!/usr/bin/env python

##############################################################################
##
## This file is part of Sardana
##
## http://www.sardana-controls.org/
##
## Copyright 2011 CELLS / ALBA Synchrotron, Bellaterra, Spain
##
## Sardana is free software: you can redistribute it and/or modify
## it under the terms of the GNU Lesser General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## Sardana 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 Lesser General Public License for more details.
##
## You should have received a copy of the GNU Lesser General Public License
## along with Sardana.  If not, see <http://www.gnu.org/licenses/>.
##
##############################################################################

"""Spock submodule. It contains an input handler"""

__all__ = ['SpockInputHandler', 'InputHandler']

__docformat__ = 'restructuredtext'

import sys
from multiprocessing import Process, Pipe

from taurus.core import TaurusManager
from taurus.core.util.singleton import Singleton
from taurus.external.qt import Qt
from taurus.qt.qtgui.dialog import TaurusMessageBox, TaurusInputDialog

from sardana.taurus.core.tango.sardana.macroserver import BaseInputHandler

from sardana.spock import genutils


class SpockInputHandler(BaseInputHandler):

    def __init__(self):
        # don't call super __init__ on purpose
        self._input = genutils.spock_input

    def input(self, input_data=None):
        if input_data is None:
            input_data = {}
        prompt = input_data.get('prompt')
        if 'data_type' in input_data:
            if input_data['data_type'] != 'String':
                print("Accepted input:  %s" % input_data['data_type'])
        ret = dict(input=None, cancel=False)
        try:
            if prompt is None:
                ret['input'] = self._input()
            else:
                ret['input'] = self._input(prompt)
        except:
            ret['cancel'] = True
        return ret

    def input_timeout(self, input_data):
        print "SpockInputHandler input timeout"


class MessageHandler(Qt.QObject):

    def __init__(self, conn, parent=None):
        Qt.QObject.__init__(self, parent)
        self._conn = conn
        self._dialog = None
        self.connect(self, Qt.SIGNAL("messageArrived"), self.on_message)
        
    def handle_message(self, input_data):
        self.emit(Qt.SIGNAL("messageArrived"), input_data)
    
    def on_message(self, input_data):
        msg_type = input_data['type']
        if msg_type == 'input':
            if 'macro_name' in input_data and 'title' not in input_data:
                input_data['title'] = input_data['macro_name']
            self._dialog = dialog = TaurusInputDialog(input_data=input_data)
            dialog.activateWindow()
            dialog.exec_()
            ok = dialog.result()
            value = dialog.value()
            ret = dict(input=None, cancel=False)
            if ok:
                ret['input'] = value
            else:
                ret['cancel'] = True
            self._conn.send(ret)
        elif msg_type == 'timeout':
            dialog = self._dialog
            if dialog:
                dialog.close()


class InputHandler(Singleton, BaseInputHandler):
    
    def __init__(self):
        # don't call super __init__ on purpose
        pass
            
    def init(self, *args, **kwargs):
        self._conn, child_conn = Pipe()
        self._proc = proc = Process(target=self.safe_run,
            name="SpockInputHandler", args=(child_conn,))
        proc.daemon = True
        proc.start()
    
    def input(self, input_data=None):
        # parent process
        data_type = input_data.get('data_type', 'String')
        if isinstance(data_type, (str, unicode)):
            ms = genutils.get_macro_server()
            interfaces = ms.getInterfaces()
            if data_type in interfaces:
                input_data['data_type'] = [ elem.name for elem in interfaces[data_type].values() ]
        self._conn.send(input_data)
        ret = self._conn.recv()
        return ret

    def input_timeout(self, input_data):
        # parent process
        self._conn.send(input_data)
        
    def safe_run(self, conn):
        # child process
        try:
            return self.run(conn)
        except Exception, e:
            msgbox = TaurusMessageBox(*sys.exc_info())
            conn.send((e, False))
            msgbox.exec_()
    
    def run(self, conn):
        # child process
        self._conn = conn
        app = Qt.QApplication.instance()
        if app is None:
            app = Qt.QApplication([])
        app.setQuitOnLastWindowClosed(False)
        self._msg_handler = MessageHandler(conn)
        TaurusManager().addJob(self.run_forever, None)
        app.exec_()
        conn.close()
        print "Quit input handler"
                
    def run_forever(self):
        # child process
        message, conn = True, self._conn
        while message:
            message = conn.recv()
            if not message:
                continue
            self._msg_handler.handle_message(message)
        app = Qt.QApplication.instance()
        if app:
            app.quit()