This file is indexed.

/usr/share/doc/twisted-doc/examples/pbgtk2.py is in twisted-doc 11.1.0-1ubuntu2.

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
# Copyright (c) Twisted Matrix Laboratories.
# See LICENSE for details.


from __future__ import nested_scopes

from twisted.internet import gtk2reactor
gtk2reactor.install()

import gtk
from gtk import glade
from twisted import copyright
from twisted.internet import reactor, defer
from twisted.python import failure, log, util
from twisted.spread import pb
from twisted.cred.credentials import UsernamePassword
from twisted.internet import error as netError


class LoginDialog:
    def __init__(self, deferred):
        self.deferredResult = deferred

        gladefile = util.sibpath(__file__, "pbgtk2login.glade")
        self.glade = glade.XML(gladefile)

        self.glade.signal_autoconnect(self)

        self.setWidgetsFromGladefile()
        self._loginDialog.show()

    def setWidgetsFromGladefile(self):
        widgets = ("hostEntry", "portEntry", "userNameEntry", "passwordEntry",
                   "statusBar", "loginDialog")
        gw = self.glade.get_widget
        for widgetName in widgets:
            setattr(self, "_" + widgetName, gw(widgetName))

        self._statusContext = self._statusBar.get_context_id("Login dialog.")

    def on_loginDialog_response(self, widget, response):
        handlers = {gtk.RESPONSE_NONE: self.windowClosed,
                   gtk.RESPONSE_DELETE_EVENT: self.windowClosed,
                   gtk.RESPONSE_OK: self.doLogin,
                   gtk.RESPONSE_CANCEL: self.cancelled}
        handlers.get(response)()

    def on_loginDialog_close(self, widget, userdata=None):
        self.windowClosed()

    def cancelled(self):
        if not self.deferredResult.called:
            self.deferredResult.errback()
        self._loginDialog.destroy()

    def windowClosed(self, reason=None):
         if not self.deferredResult.called:
            self.deferredResult.errback()

    def doLogin(self):
        host = self._hostEntry.get_text()
        port = int(self._portEntry.get_text())
        userName = self._userNameEntry.get_text()
        password = self._passwordEntry.get_text()

        client_factory = pb.PBClientFactory()
        reactor.connectTCP(host, port, client_factory)
        creds = UsernamePassword(userName, password)
        client_factory.login(creds).addCallbacks(self._cbGotPerspective, self._ebFailedLogin)
        
        self.statusMsg("Contacting server...")

    def _cbGotPerspective(self, perspective):
        self.statusMsg("Connected to server.")
        self.deferredResult.callback(perspective)
        self._loginDialog.destroy()

    def _ebFailedLogin(self, reason):
        if isinstance(reason, failure.Failure):
            text = str(reason.value)
        else:
            text = str(reason)
            
        self.statusMsg(text)
        msg = gtk.MessageDialog(self._loginDialog,
                                gtk.DIALOG_DESTROY_WITH_PARENT,
                                gtk.MESSAGE_ERROR,
                                gtk.BUTTONS_CLOSE,
                                text)
        msg.show_all()
        msg.connect("response", lambda *a: msg.destroy())

    def statusMsg(self, text):
        self._statusBar.push(self._statusContext, text)


class EchoClient:
    def __init__(self, echoer):
        self.echoer = echoer
        w = gtk.Window(gtk.WINDOW_TOPLEVEL)
        vb = gtk.VBox(); b = gtk.Button("Echo:")
        self.entry = gtk.Entry(); self.outry = gtk.Entry()
        w.add(vb)
        map(vb.add, [b, self.entry, self.outry])
        b.connect('clicked', self.clicked)
        w.connect('destroy', self.stop)
        w.show_all()

    def clicked(self, b):
        txt = self.entry.get_text()
        self.entry.set_text("")
        self.echoer.callRemote('echo',txt).addCallback(self.outry.set_text)

    def stop(self, b):
        reactor.stop()

d = defer.Deferred()
LoginDialog(d)
d.addCallbacks(EchoClient,
               lambda _: reactor.stop())

reactor.run()