Commits

keltus  committed dec9108

* irclib.py: Reverted changes in irclib that don't really belong in the core lib
* irclib.py: Add support for ssl
* irclib.py: Add support for ipv6
* python-irclib now requires python 2.3 and above (for ssl and ipv6)

  • Participants
  • Parent commits d41ce02
  • Tags version_0_4_7

Comments (0)

Files changed (5)

+2008-08-29  Keltus <keltus@users.sourceforge.net>
+    * irclib.py: Reverted changes in irclib that don't really belong in the core lib
+    * irclib.py: Add support for ssl
+    * irclib.py: Add support for ipv6
+	* python-irclib now requires python 2.3 and above (for ssl and ipv6)
+
 2006-03-09  Keltus <keltus@users.sourceforge.net>
 	* README: Minor update
 
 
 Requirements:
 
-  * Python 1.6 or newer.
+  * Python 2.2 or newer.
 
 Installation:
 
                          self.server_list[0][1],
                          self._nickname,
                          password,
-                         ircname=self._realname)
+                         ircname=self._realname, ssl=True)
         except ServerConnectionError:
             pass
 
 import sys
 import time
 import types
-import threading
 
-VERSION = 0, 4, 6
+VERSION = 0, 4, 7
 DEBUG = 0
 
 # TODO
 
 _rfc_1459_command_regexp = re.compile("^(:(?P<prefix>[^ ]+) +)?(?P<command>[^ ]+)( *(?P<argument> .+))?")
 
-class IRCmultithread(IRC):
-    def server(self):
-        """Creates and returns a ServerConnection object."""
-        
-        c = ServerConnectionThread(self)
-        self.connections.append(c)
-        
-        return c
-
 class Connection:
     """Base class for IRC connections.
 
         Connection.__init__(self, irclibobj)
         self.connected = 0  # Not connected yet.
         self.socket = None
+        self.ssl = None
 
     def connect(self, server, port, nickname, password=None, username=None,
-                ircname=None, localaddress="", localport=0, serverid="unspec"):
+                ircname=None, localaddress="", localport=0, ssl=False, ipv6=False):
         """Connect/reconnect to a server.
 
         Arguments:
             localaddress -- Bind the connection to a specific local IP address.
 
             localport -- Bind the connection to a specific local port.
-            
-            serverid -- A little mechanism to keep track of multiple connections in a program
+
+            ssl -- Enable support for ssl.
+
+            ipv6 -- Enable support for ipv6.
 
         This function can be called to reconnect a closed connection.
 
         self.password = password
         self.localaddress = localaddress
         self.localport = localport
-        self.serverid = serverid
         self.localhost = socket.gethostname()
-        self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+        if ipv6:
+            self.socket = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
+        else:
+            self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
         try:
             self.socket.bind((self.localaddress, self.localport))
             self.socket.connect((self.server, self.port))
+            if ssl:
+                self.ssl = socket.ssl(self.socket)
         except socket.error, x:
             self.socket.close()
             self.socket = None
         """[Internal]"""
 
         try:
-            new_data = self.socket.recv(2**14)
+            if self.ssl:
+                new_data = self.ssl.read(2**14)
+            else:
+                new_data = self.socket.recv(2**14)
         except socket.error, x:
             # The server hung up.
             self.disconnect("Connection reset by peer")
         # unless you've been connected for at least 5 minutes!
         self.send_raw("QUIT" + (message and (" :" + message)))
 
-    def sajoin(self, target, channel):
-        """ Send a SAJOIN command. """
-        self.send_raw("SAJOIN %s %s" % (target, channel))
-        
-    def sapart(self, target, channel):
-        """ Send a SAPART command. """
-        self.send_raw("SAPART %s %s" % (target, channel))
-    
-    def sethost(self, hostname):
-        """ Send a SETHOST command. """
-        self.send_raw("SETHOST %s" % hostname)
-    
-    def privmsgtosource(self, event, message):
-        """ Send a PRIVMSG to where the message came from """
-        privmsg_origin(self, event, message)
-
-    def sconnect(self, target, port="", server=""):
-        """Send an SCONNECT command."""
-        self.send_raw("CONNECT %s%s%s" % (target,
-                                          port and (" " + port),
-                                          server and (" " + server)))
-
     def send_raw(self, string):
         """Send raw string to the server.
 
         if self.socket is None:
             raise ServerNotConnectedError, "Not connected."
         try:
-            self.socket.send(string + "\r\n")
+            if self.ssl:
+                self.ssl.write(string + "\r\n")
+            else:
+                self.socket.send(string + "\r\n")
             if DEBUG:
                 print "TO SERVER:", string
         except socket.error, x:
                                          max and (" " + max),
                                          server and (" " + server)))
 
-class ServerConnectionThread(threading.Thread, ServerConnection):
-    def __init__(self, irclibobj):
-        threading.Thread.__init__(self)
-        ServerConnection.__init__(self, irclibobj)
-        self.isThread = True
-        
-    def setargs(self, server, port, nickname, password=None, username=None,
-                ircname = None, localaddress="", localport=0, serverid="unspec"):
-        self.t_server = server
-        self.t_port = port
-        self.t_nickname = nickname
-        self.t_password = password
-        self.t_username = username
-        self.t_ircname = ircname
-        self.t_localaddress = localaddress
-        self.t_localport = localport
-        self.t_serverid = serverid
-    def run(self):
-        self.connect(self.t_server, self.t_port, self.t_nickname, self.t_password, self.t_username, self.t_ircname, self.t_localaddress, self.t_localport, self.t_serverid)
-
 class DCCConnectionError(IRCError):
     pass
 
         self.dcc_connections.remove(c)
 
     def connect(self, server, port, nickname, password=None, username=None,
-                ircname=None, localaddress="", localport=0):
+                ircname=None, localaddress="", localport=0, ssl=False, ipv6=False):
         """Connect/reconnect to a server.
 
         Arguments:
 
             localport -- Bind the connection to a specific local port.
 
+            ssl -- Enable support for ssl.
+
+            ipv6 -- Enable support for ipv6.
+
         This function can be called to reconnect a closed connection.
         """
         self.connection.connect(server, port, nickname,
                                 password, username, ircname,
-                                localaddress, localport)
+                                localaddress, localport, ssl, ipv6)
 
     def dcc_connect(self, address, port, dcctype="chat"):
         """Connect to a DCC peer.
         s = s[:-1]
     return s
 
-def nm(s):
-    """ Returns a 3-tuple
-    ( a, b, c) where a = nick, b = username,
-    c = hostname """
-    
-    a = s.split("!")[0]
-    b = s.split("!")[1].split("@")[0]
-    c = s.split("@")[1]
-    return (a,b,c)
-
 def nm_to_n(s):
     """Get the nick part of a nickmask.
 
     s = s.split("!")[1]
     return s.split("@")[0]
 
-def privmsg_origin(connection, event, message):
-    """ Given the connection and event,
-    will send message to where the message
-    originated from.
-    """
-    if is_channel(event.target()):
-        target = event.target()
-    else:
-        target = nm_to_n(event.source())
-    connection.privmsg(target, message)
-
 def parse_nick_modes(mode_string):
     """Parse a nick mode string.
 

File python-irclib.spec.in

 /usr/lib/python*/site-packages/*
 
 %changelog
+* Sat Aug 29 2008 Keltus <keltus@users.sourceforge.net> 0.4.7-1
+- upgraded to 0.4.7
+
 * Sat Dec 24 2005 Keltus <keltus@users.sourceforge.net> 0.4.6-1
 - upgraded to 0.4.6