This file is indexed.

/usr/lib/python2.7/dist-packages/pyhoca/wxgui/notify.py is in pyhoca-gui 0.5.0.7-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
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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
# -*- coding: utf-8 -*-

# Copyright (C) 2010-2016 by Mike Gabriel <mike.gabriel@das-netzwerkteam.de>
# Copyright (C) 2010-2016 by Dick Kniep <dick.kniep@lindix.nl>
#
# PyHoca GUI is free software; you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# PyHoca GUI 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program; if not, write to the
# Free Software Foundation, Inc.,
# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.

import wx
from x2go import X2GOCLIENT_OS
from x2go import log
if X2GOCLIENT_OS in ('Linux', 'Mac'):
    try:
        # try the GTK3 way for notification support first...
        from gi.repository import Notify as _Notify
    except ImportError:
        # GTK3 notifications are unavailable,
        # hopefully pynotify / GTK2-based notifications are available then...
        import pynotify as _Notify
import exceptions
import basepath

import x2go.utils as utils

class NotSupportedException(exceptions.StandardError): pass
class PyHocaNotificationException(exceptions.StandardError): pass

class libnotify_NotifierPopup(object):
    """\
    L{PyHocaGUI} notification utilizing C{libnotify}, used on Linux/Unix OS.

    """
    title = {}
    text = {}
    icon = {}
    timeout = {}

    def __init__(self, _PyHocaGUI):
        """\
        Notifier popup (constructor).

        @param _PyHocaGUI: main application instance
        @type _PyHocaGUI: C{obj}

        """
        self._PyHocaGUI = _PyHocaGUI
        self._pyhoca_logger = self._PyHocaGUI._pyhoca_logger

        if not _Notify.init("PyHocaGUI"):
            raise NotSupportedException

    def prepare(self, context, title=None, text=None, icon=None, timeout=None):
        """\
        Prepare a notification that gets sent to C{libnotify} later (by the L{send()} method).

        Use C{context} as a unique identifier. When sending the notification later, C{context}
        will unequivocally map to the notification content that shall get sent.

        @param context: a unique identifier for this notification preparation
        @type context: C{str}
        @param title: notification title
        @type title: C{str}
        @param text: notification text
        @type text: C{str}
        @param icon: icon name for an icon that appears with the notification
        @type icon: C{str}
        @param timeout: let notification disappear after C{<timeout>} milliseconds
        @type timeout: C{int}

        """
        if title is not None:
            self.title[context] = title
        if text is not None:
            self.text[context] = text
        if icon is not None:
            self.icon[context] = icon
        if timeout is not None:
            self.timeout[context] = timeout

    def send(self, title=None, text=None, context=None, icon=None, timeout=8000):
        """\
        Send notifications directly (or use a prepared notification).

        @param title: notification title
        @type title: C{str}
        @param text: notification text
        @type text: C{str}
        @param context: an identifier that refers to a prepared notification
        @type context: C{str}
        @param icon: icon name for an icon that appears with the notification
        @type icon: C{str}
        @param timeout: let notification disappear after C{<timeout>} milliseconds
        @type timeout: C{int}

        @raise PyHocaNotificationException: if notification failed

        """
        if context is not None:
            try:
                title = self.title[context]
                del self.title[context]
            except KeyError:
                pass
            try:
                text = self.text[context]
                del self.text[context]
            except KeyError:
                pass
            try:
                icon = self.icon[context]
                del self.icon[context]
            except KeyError:
                pass
            try:
                timeout = self.timeout[context]
                del self.timeout[context]
            except KeyError:
                pass

        _icons_location = basepath.icons_basepath
        if icon:
            icon = 'file://%s/PyHoca/32x32/%s.png' % (_icons_location, icon)

        if title and text:
            self._pyhoca_logger('[%s] %s' % (title.encode(utils.get_encoding()), text.encode(utils.get_encoding())), loglevel=log.loglevel_NOTICE)

        try:
            if not self._PyHocaGUI.disable_notifications and title and text:
                try:
                    n = _Notify.Notification.new(title, text, icon)
                    n.set_urgency(_Notify.Urgency.NORMAL)
                except AttributeError:
                    # handle pynotify / GTK2-based notifications
                    n = _Notify.Notification(title, text, icon)
                    n.set_urgency(_Notify.URGENCY_NORMAL)
                n.set_timeout(timeout)
                n.show()
        except:
            pass

    def Close(self):
        """\
        Provide a C{Close()} method which does nothing.

        """
        pass

    def Destroy(self):
        """\
        Provide a C{Destroy()} method which does nothing.

        """
        pass


class showballoon_NotifierPopup(object):
    """\
    L{PyHocaGUI} notification utilizing C{wx.TaskBarIcon.ShowBalloon()}, used on Windows OS.

    """
    title = {}
    text = {}
    icon = {}
    timeout = {}

    def __init__(self, _about):
        """\
        Notifier popup (constructor).

        @param _about: main application window
        @type _about: C{obj}

        """
        self._PyHocaGUI = _about._PyHocaGUI
        self._pyhoca_logger = self._PyHocaGUI._pyhoca_logger

    def prepare(self, context, title=None, text=None, icon=None, timeout=None):
        """\
        Prepare a notification that gets sent to C{libnotify} later (by the L{send()} method).

        Use C{context} as a unique identifier. When sending the notification later, C{context}
        will unequivocally map to the notification content that shall get sent.

        @param context: a unique identifier for this notification preparation
        @type context: C{str}
        @param title: notification title
        @type title: C{str}
        @param text: notification text
        @type text: C{str}
        @param icon: icon name for an icon that appears with the notification
        @type icon: C{str}
        @param timeout: let notification disappear after C{<timeout>} milliseconds
        @type timeout: C{int}

        """
        if title is not None:
            self.title[context] = title
        if text is not None:
            self.text[context] = text
        if icon is not None:
            self.icon[context] = icon
        if timeout is not None:
            self.timeout[context] = timeout

    def send(self, title=None, text=None, context=None, icon=None, timeout=8000):
        """\
        Send notifications directly (or use a prepared notification).

        @param title: notification title
        @type title: C{str}
        @param text: notification text
        @type text: C{str}
        @param context: an identifier that refers to a prepared notification
        @type context: C{str}
        @param icon: icon name for an icon that appears with the notification
        @type icon: C{str}
        @param timeout: let notification disappear after C{<timeout>} milliseconds
        @type timeout: C{int}

        """
        if context is not None:
            try:
                title = self.title[context]
                del self.title[context]
            except KeyError:
                pass
            try:
                text = self.text[context]
                del self.text[context]
            except KeyError:
                pass
            try:
                icon = self.icon[context]
                del self.icon[context]
            except KeyError:
                pass
            try:
                timeout = self.timeout[context]
                del self.timeout[context]
            except KeyError:
                pass

        # libnotify timeouts are given in millisecs, on Windows we use seconds...
        timeout = timeout / 1000

        _icon_map_wx = {
            'audio_error': wx.ICON_ERROR,
            'auth_success': wx.ICON_INFORMATION,
            'auth_failed': wx.ICON_WARNING,
            'auth_error': wx.ICON_ERROR,
            'auth_disconnect': wx.ICON_INFORMATION,
            'profile_add': wx.ICON_INFORMATION,
            'profile_delete': wx.ICON_INFORMATION,
            'profile_edit': wx.ICON_INFORMATION,
            'profile_save': wx.ICON_INFORMATION,
            'profile_error': wx.ICON_ERROR,
            'session_cleanall': wx.ICON_INFORMATION,
            'session_error': wx.ICON_ERROR,
            'session_pause': wx.ICON_INFORMATION,
            'session_printing': wx.ICON_INFORMATION,
            'session_resume': wx.ICON_INFORMATION,
            'session_start': wx.ICON_INFORMATION,
            'session_terminate': wx.ICON_INFORMATION,
            'session_warning': wx.ICON_WARNING,
        }
        if icon in _icon_map_wx.keys():
           icon = _icon_map_wx[icon]
        else:
           icon = wx.ICON_INFORMATION

        try:
            if not self._PyHocaGUI.disable_notifications and title and text:
                # you will need wxPython >= 2.9 for this
                self._PyHocaGUI.taskbar.ShowBalloon(
                    title,
                    text,
                    timeout*1000,
                    icon,
                )
        except:
            pass

        if title and text:
            # on Windows some error messages are already encoded, some are not, depending from which module they come
            try: _title = title.encode(utils.get_encoding())
            except: _title = title
            try: _text = text.encode(utils.get_encoding())
            except: _text = text

            try: self._pyhoca_logger('['+_title+'] '+_text, loglevel=log.loglevel_NOTICE)
            except UnicodeDecodeError: self._pyhoca_logger('Unicode error occurred while rendering a log message...', loglevel=log.loglevel_WARN)

    def Close(self):
        """\
        Provide a C{Close()} method which does nothing.

        """
        pass

    def Destroy(self):
        """\
        Provide a C{Destroy()} method which does nothing.

        """
        pass


class notificationmessage_NotifierPopup(object):
    """\
    L{PyHocaGUI} notification utilizing C{wx.NotificationMessage()}, used on Windows OS.

    Note: C{wx.NotificationMessage()} has only been added to wxPython in version 2.9.x.

    """
    title = {}
    text = {}
    icon = {}
    timeout = {}

    def __init__(self, _about):
        """\
        Notifier popup (constructor).

        @param _about: main application window
        @type _about: C{obj}

        """
        self._PyHocaGUI = _about._PyHocaGUI
        self._pyhoca_logger = self._PyHocaGUI._pyhoca_logger

    def prepare(self, context, title=None, text=None, icon=None, timeout=None):
        """\
        Prepare a notification that gets sent to C{libnotify} later (by the L{send()} method).

        Use C{context} as a unique identifier. When sending the notification later, C{context}
        will unequivocally map to the notification content that shall get sent.

        @param context: a unique identifier for this notification preparation
        @type context: C{str}
        @param title: notification title
        @type title: C{str}
        @param text: notification text
        @type text: C{str}
        @param icon: icon name for an icon that appears with the notification
        @type icon: C{str}
        @param timeout: let notification disappear after C{<timeout>} milliseconds
        @type timeout: C{int}

        """
        if title is not None:
            self.title[context] = title
        if text is not None:
            self.text[context] = text
        if icon is not None:
            self.icon[context] = icon
        if timeout is not None:
            self.timeout[context] = timeout

    def send(self, title=None, text=None, context=None, icon=None, timeout=8000):
        """\
        Send notifications directly (or use a prepared notification).

        @param title: notification title
        @type title: C{str}
        @param text: notification text
        @type text: C{str}
        @param context: an identifier that refers to a prepared notification
        @type context: C{str}
        @param icon: icon name for an icon that appears with the notification
        @type icon: C{str}
        @param timeout: let notification disappear after C{<timeout>} milliseconds
        @type timeout: C{int}

        """
        if context is not None:
            try:
                title = self.title[context]
                del self.title[context]
            except KeyError:
                pass
            try:
                text = self.text[context]
                del self.text[context]
            except KeyError:
                pass
            try:
                icon = self.icon[context]
                del self.icon[context]
            except KeyError:
                pass
            try:
                timeout = self.timeout[context]
                del self.timeout[context]
            except KeyError:
                pass

        # libnotify timeouts are given in millisecs, on Windows we use seconds...
        timeout = timeout / 1000

        _icon_map_wx = {
            'audio_error': wx.ICON_ERROR,
            'auth_success': wx.ICON_INFORMATION,
            'auth_failed': wx.ICON_WARNING,
            'auth_error': wx.ICON_ERROR,
            'auth_disconnect': wx.ICON_INFORMATION,
            'profile_add': wx.ICON_INFORMATION,
            'profile_delete': wx.ICON_INFORMATION,
            'profile_edit': wx.ICON_INFORMATION,
            'profile_save': wx.ICON_INFORMATION,
            'profile_error': wx.ICON_ERROR,
            'session_cleanall': wx.ICON_INFORMATION,
            'session_error': wx.ICON_ERROR,
            'session_pause': wx.ICON_INFORMATION,
            'session_printing': wx.ICON_INFORMATION,
            'session_resume': wx.ICON_INFORMATION,
            'session_start': wx.ICON_INFORMATION,
            'session_terminate': wx.ICON_INFORMATION,
            'session_warning': wx.ICON_WARNING,
        }
        if icon in _icon_map_wx.keys():
           icon = _icon_map_wx[icon]
        else:
           icon = wx.ICON_INFORMATION

        try:
            if not self._PyHocaGUI.disable_notifications and title and text:
                # you will need wxPython >= 2.9 for this
                _notification_msg = wx.NotificationMessage()
                _notification_msg.SetTitle(title)
                _notification_msg.SetMessage(text)
                _notification_msg.SetParent(self._PyHocaGUI.about)
                _notification_msg.SetFlags(icon)
                _notification_msg.Show(timeout=timeout)
        except:
            # if we are running wxPython 2.8, we ignore missing
            # wx.NotificationMessage class
            pass

        if title and text:
            # on Windows some error messages are already encoded, some are not, depending from which module they come
            try: _title = title.encode(utils.get_encoding())
            except: _title = title
            try: _text = text.encode(utils.get_encoding())
            except: _text = text

            try: self._pyhoca_logger('['+_title+'] '+_text, loglevel=log.loglevel_NOTICE)
            except UnicodeDecodeError: self._pyhoca_logger('Unicode error occurred while rendering a log message...', loglevel=log.loglevel_WARN)

    def Close(self):
        """\
        Provide a C{Close()} method which does nothing.

        """
        pass

    def Destroy(self):
        """\
        Provide a C{Destroy()} method which does nothing.

        """
        pass