This file is indexed.

/usr/lib/python2.7/dist-packages/gozerbot/wait.py is in gozerbot 0.99.1-5.

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
# gozerbot/wait.py
#
#

""" wait for ircevent based on ircevent.CMND """

__copyright__ = 'this file is in the public domain'

# gozerbot imports
from utils.log import rlog
from utils.locking import lockdec
import threads.thr as thr

# basic imports
import time, thread

# locks
waitlock = thread.allocate_lock()
locked = lockdec(waitlock)

class Wait(object):

    """ lists of ircevents to wait for """

    def __init__(self):
        self.waitlist = []
        self.ticket = 0

    def register(self, cmnd, catch, queue, timeout=15):

        """ register wait for cmnd. """

        rlog(1, 'wait', 'registering for cmnd ' + cmnd)
        self.ticket += 1
        self.waitlist.insert(0, (cmnd, catch, queue, self.ticket))
        if timeout:
            # start timeout thread
            thr.start_new_thread(self.dotimeout, (timeout, self.ticket))
        return self.ticket

    def check(self, ievent):

        """ check if there are wait items for ievent .. check if 'catch' 
            matches on ievent.postfix if so put ievent on queue. """

        cmnd = ievent.cmnd
        for item in self.waitlist:
            if item[0] == cmnd:
                if cmnd == "JOIN":
	            catch = ievent.txt + ievent.postfix
                else:
                    catch = ievent.nick + ievent.postfix
                if item[1] in catch:
                    ievent.ticket = item[3]
                    item[2].put_nowait(ievent)
                    self.delete(ievent.ticket)
                    rlog(1, 'wait', 'got response for %s' % item[0])
                    ievent.isresponse = True

    def dotimeout(self, timeout, ticket):

        """ start timeout thread for wait with ticket nr. """

        rlog(1, 'wait', 'starting timeouthread for %s' % str(ticket))
        time.sleep(float(timeout))
        self.delete(ticket)

    @locked
    def delete(self, ticket):

        """ delete wait item with ticket nr. """

        for itemnr in range(len(self.waitlist)-1, -1, -1):
            if self.waitlist[itemnr][3] == ticket:
                self.waitlist[itemnr][2].put_nowait(None)
                del self.waitlist[itemnr]
                rlog(1, 'wait', 'deleted ' + str(ticket))
                return 1

class Privwait(Wait):

    """ wait for privmsg .. catch is on nick """

    def register(self, catch, queue, timeout=15):

        """ register wait for privmsg. """

        rlog(1, 'privwait', 'registering for ' + catch)
        return Wait.register(self, 'PRIVMSG', catch, queue, timeout)

    def check(self, ievent):

        """ check if there are wait items for ievent. """

        for item in self.waitlist:
            if item[0] == 'PRIVMSG':
                if ievent.userhost == item[1]:
                    ievent.ticket = item[3]
                    item[2].put_nowait(ievent)
                    self.delete(ievent.ticket)
                    rlog(1, 'privwait', 'got response for %s' % item[0])
                    ievent.isresponse = True

class Jabberwait(Wait):

    """ wait object for jabber messages. """

    def register(self, catch, queue, timeout=15):

        """ register wait for privmsg. """

        rlog(1, 'jabberwait', 'registering for %s' % catch)
        self.ticket += 1
        self.waitlist.append((catch, queue, self.ticket))
        if timeout:
            thr.start_new_thread(self.dotimeout, (timeout, self.ticket))
        return self.ticket

    def check(self, msg):

        """ check if <msg> is waited for. """

        for teller in range(len(self.waitlist)-1, -1, -1):
            i = self.waitlist[teller]
            if i[0] == msg.userhost:
                msg.ticket = i[2]
                i[1].put_nowait(msg)
                self.delete(msg.ticket)
                rlog(10, 'jabberwait', 'got response for %s' % i[0])
                msg.isresponse = 1

    @locked
    def delete(self, ticket):

        """ delete wait item with ticket nr. """

        for itemnr in range(len(self.waitlist)-1, -1, -1):
            item = self.waitlist[itemnr]
            if item[2] == ticket:
                item[1].put_nowait(None)
                try:
                    del self.waitlist[itemnr]
                    rlog(1, 'jabberwait', 'deleted ' + str(ticket))
                except IndexError:
                    pass
                return 1

class Jabbererrorwait(Jabberwait):

    """ wait for jabber errors. """

    def check(self, msg):

        """ check if <msg> is waited for. """

        if not msg.getType() == 'error':
            return

        errorcode = msg.getErrorCode()

        for teller in range(len(self.waitlist)-1, -1, -1):
            i = self.waitlist[teller]
            if i[0] == 'ALL' or i[0] == errorcode:
                msg.error = msg.getError()
                msg.ticket = i[2]
                i[1].put_nowait(msg)
                self.delete(msg.ticket)
                rlog(10,'jabbererrorwait','got error response for %s' % i[0])