Jason R. Coombs avatar Jason R. Coombs committed f8669ba

Removed getters from Event class

Comments (0)

Files changed (7)

+5.0
+===
+
+Another backward-incompatible change. In irc 5.0, many of the unnecessary
+getter functions have been removed and replaced with simple attributes. In
+particular:
+
+ - Event.eventtype() -> Event.type
+ - Event.source() -> Event.source
+ - Event.target() -> Event.target
+ - Event.arguments() -> Event.arguments
+
+Also, the parameter name when constructing an event was renamed from
+`eventtype` to simply `type`.
+
 4.0
 ===
 
                                         self._connected_checker)
 
     def _on_join(self, c, e):
-        ch = e.target()
-        nick = e.source().nick
+        ch = e.target
+        nick = e.source.nick
         if nick == c.get_nickname():
             self.channels[ch] = Channel()
         self.channels[ch].add_user(nick)
 
     def _on_kick(self, c, e):
-        nick = e.arguments()[0]
-        channel = e.target()
+        nick = e.arguments[0]
+        channel = e.target
 
         if nick == c.get_nickname():
             del self.channels[channel]
             self.channels[channel].remove_user(nick)
 
     def _on_mode(self, c, e):
-        modes = irc.modes.parse_channel_modes(" ".join(e.arguments()))
-        t = e.target()
+        modes = irc.modes.parse_channel_modes(" ".join(e.arguments))
+        t = e.target
         if irc.client.is_channel(t):
             ch = self.channels[t]
             for mode in modes:
             pass
 
     def _on_namreply(self, c, e):
-        # e.arguments()[0] == "@" for secret channels,
+        # e.arguments[0] == "@" for secret channels,
         #                     "*" for private channels,
         #                     "=" for others (public channels)
-        # e.arguments()[1] == channel
-        # e.arguments()[2] == nick list
+        # e.arguments[1] == channel
+        # e.arguments[2] == nick list
 
-        ch = e.arguments()[1]
-        for nick in e.arguments()[2].split():
+        ch = e.arguments[1]
+        for nick in e.arguments[2].split():
             if nick[0] == "@":
                 nick = nick[1:]
                 self.channels[ch].set_mode("o", nick)
             self.channels[ch].add_user(nick)
 
     def _on_nick(self, c, e):
-        before = e.source().nick
-        after = e.target()
+        before = e.source.nick
+        after = e.target
         for ch in self.channels.values():
             if ch.has_user(before):
                 ch.change_nick(before, after)
 
     def _on_part(self, c, e):
-        nick = e.source().nick
-        channel = e.target()
+        nick = e.source.nick
+        channel = e.target
 
         if nick == c.get_nickname():
             del self.channels[channel]
             self.channels[channel].remove_user(nick)
 
     def _on_quit(self, c, e):
-        nick = e.source().nick
+        nick = e.source.nick
         for ch in self.channels.values():
             if ch.has_user(nick):
                 ch.remove_user(nick)
         Replies to VERSION and PING requests and relays DCC requests
         to the on_dccchat method.
         """
-        nick = e.source().nick
-        if e.arguments()[0] == "VERSION":
+        nick = e.source.nick
+        if e.arguments[0] == "VERSION":
             c.ctcp_reply(nick, "VERSION " + self.get_version())
-        elif e.arguments()[0] == "PING":
-            if len(e.arguments()) > 1:
-                c.ctcp_reply(nick, "PING " + e.arguments()[1])
-        elif e.arguments()[0] == "DCC" and e.arguments()[1].split(" ", 1)[0] == "CHAT":
+        elif e.arguments[0] == "PING":
+            if len(e.arguments) > 1:
+                c.ctcp_reply(nick, "PING " + e.arguments[1])
+        elif e.arguments[0] == "DCC" and e.arguments[1].split(" ", 1)[0] == "CHAT":
             self.on_dccchat(c, e)
 
     def on_dccchat(self, c, e):
         """[Internal]"""
         with self.mutex:
             h = self.handlers
-            th = sorted(h.get("all_events", []) + h.get(event.eventtype(), []))
+            th = sorted(h.get("all_events", []) + h.get(event.type, []))
             for handler in th:
                 if handler[1](connection, event) == "NO MORE":
                     return
     def _handle_event(self, event):
         """[Internal]"""
         self.irclibobj._handle_event(self, event)
-        if event.eventtype() in self.handlers:
-            for fn in self.handlers[event.eventtype()]:
+        if event.type in self.handlers:
+            for fn in self.handlers[event.type]:
                 fn(self, event)
 
     def is_connected(self):
 
     def _dispatcher(self, c, e):
         """[Internal]"""
-        log.debug("_dispatcher: %s", e.eventtype())
+        log.debug("_dispatcher: %s", e.type)
 
-        m = "on_" + e.eventtype()
+        m = "on_" + e.type
         if hasattr(self, m):
             getattr(self, m)(c, e)
 
 
 
 class Event(object):
-    """Class representing an IRC event."""
-    def __init__(self, eventtype, source, target, arguments=None):
-        """Constructor of Event objects.
+    "An IRC event."
+    def __init__(self, type, source, target, arguments=None):
+        """
+        Constructor of Event objects.
 
         Arguments:
 
-            eventtype -- A string describing the event.
+            type -- A string describing the event.
 
             source -- The originator of the event (a nick mask or a server).
 
             target -- The target of the event (a nick or a channel).
 
-            arguments -- Any event specific arguments.
+            arguments -- Any event-specific arguments.
         """
-        self._eventtype = eventtype
-        self._source = source
-        self._target = target
-        if arguments:
-            self._arguments = arguments
-        else:
-            self._arguments = []
-
-    def eventtype(self):
-        """Get the event type."""
-        return self._eventtype
-
-    def source(self):
-        """Get the event source."""
-        return self._source
-
-    def target(self):
-        """Get the event target."""
-        return self._target
-
-    def arguments(self):
-        """Get the event arguments."""
-        return self._arguments
+        self.type = type
+        self.source = source
+        self.target = target
+        if arguments is None:
+            arguments = []
+        self.arguments = arguments
 
 _LOW_LEVEL_QUOTE = "\020"
 _CTCP_LEVEL_QUOTE = "\134"
 
 def _ping_ponger(connection, event):
     "A global handler for the 'ping' event"
-    connection.pong(event.target())
+    connection.pong(event.target)
 
 # for backward compatibility
 parse_nick_modes = modes.parse_nick_modes

scripts/dccreceive.py

         self.received_bytes = 0
 
     def on_ctcp(self, connection, event):
-        args = event.arguments()[1].split()
+        args = event.arguments[1].split()
         if args[0] != "SEND":
             return
         self.filename = os.path.basename(args[1])
         self.dcc = self.dcc_connect(peeraddress, peerport, "raw")
 
     def on_dccmsg(self, connection, event):
-        data = event.arguments()[0]
+        data = event.arguments[0]
         self.file.write(data)
         self.received_bytes = self.received_bytes + len(data)
         self.dcc.privmsg(struct.pack("!I", self.received_bytes))

scripts/dccsend.py

         self.connection.quit()
 
     def on_dccmsg(self, connection, event):
-        acked = struct.unpack("!I", event.arguments()[0])[0]
+        acked = struct.unpack("!I", event.arguments[0])[0]
         if acked == self.filesize:
             self.dcc.disconnect()
             self.connection.quit()
         sys.exit(0)
 
     def on_nosuchnick(self, connection, event):
-        print "No such nickname:", event.arguments()[0]
+        print "No such nickname:", event.arguments[0]
         self.connection.quit()
 
     def send_chunk(self):

scripts/servermap.py

 def on_links(connection, event):
     global links
 
-    links.append((event.arguments()[0],
-                  event.arguments()[1],
-                  event.arguments()[2]))
+    links.append((event.arguments[0],
+                  event.arguments[1],
+                  event.arguments[2]))
 
 def on_endoflinks(connection, event):
     global links

scripts/testbot.py

         c.join(self.channel)
 
     def on_privmsg(self, c, e):
-        self.do_command(e, e.arguments()[0])
+        self.do_command(e, e.arguments[0])
 
     def on_pubmsg(self, c, e):
-        a = e.arguments()[0].split(":", 1)
+        a = e.arguments[0].split(":", 1)
         if len(a) > 1 and irc_lower(a[0]) == irc_lower(self.connection.get_nickname()):
             self.do_command(e, a[1].strip())
         return
 
     def on_dccmsg(self, c, e):
-        c.privmsg("You said: " + e.arguments()[0])
+        c.privmsg("You said: " + e.arguments[0])
 
     def on_dccchat(self, c, e):
-        if len(e.arguments()) != 2:
+        if len(e.arguments) != 2:
             return
-        args = e.arguments()[1].split()
+        args = e.arguments[1].split()
         if len(args) == 4:
             try:
                 address = ip_numstr_to_quad(args[2])
             self.dcc_connect(address, port)
 
     def do_command(self, e, cmd):
-        nick = e.source().nick
+        nick = e.source.nick
         c = self.connection
 
         if cmd == "disconnect":
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.