Restructure to make selecting servers easier master
authorW. Trevor King <wking@tremily.us>
Sun, 14 Apr 2013 21:03:24 +0000 (17:03 -0400)
committerW. Trevor King <wking@tremily.us>
Sun, 14 Apr 2013 21:03:24 +0000 (17:03 -0400)
Don't *require* that IRC() already know about your server, just add
some nicknames for ease of use.  Now it's easy to point IRC() at any
qwebirc client you like.

README
ipythonirc/__init__.py
setup.py

diff --git a/README b/README
index ced19428bf23e5ac306e917130fcbfcf41b1feff..eddb83a162276d7d95d876059cb281727d598909 100644 (file)
--- a/README
+++ b/README
@@ -1,6 +1,11 @@
-ipython-irc: An IRC iframe using webchat.freenode.net_
+ipython-irc: An IRC iframe that connects to qwebirc_ instances.
 
 
-Connect to freenode_ from IPython!
+`Many IRC networks`_ run public qwebirc instances.  For example:
+
+* Freenode_
+* EFNet_
+
+Connect to them from IPython_!
 
 Installation
 ============
 
 Installation
 ============
@@ -66,8 +71,10 @@ wking@tremily.us
 Copyright 2013
 
 
 Copyright 2013
 
 
-.. _webchat.freenode.net: http://webchat.freenode.net/
-.. _freenode: http://freenode.net/
+.. _qwebirc: http://qwebirc.org/
+.. _Many IRC networks: http://qwebirc.org/about
+.. _Freenode: http://webchat.freenode.net/
+.. _EFNet: http://chat.efnet.org:9090/
 .. _layman: http://layman.sourceforge.net/
 .. _wtk overlay: http://blog.tremily.us/posts/Gentoo_overlay/
 .. _Debian: http://www.debian.org/
 .. _layman: http://layman.sourceforge.net/
 .. _wtk overlay: http://blog.tremily.us/posts/Gentoo_overlay/
 .. _Debian: http://www.debian.org/
index 5b1e82084d17ddbe3c82a5e91d05eb5abad442bd..6f809058a414e63306a0e7a01ee156e8289807eb 100644 (file)
@@ -39,20 +39,40 @@ class IRC (object):
     Use with::
 
       IRC(nick='you', channels=('#ipython', ...)).show()
     Use with::
 
       IRC(nick='you', channels=('#ipython', ...)).show()
+
+    You can give the server explicitly::
+
+      IRC(server='http://webchat.freenode.net/', ...)
+
+    or use some common nicknames::
+
+      IRC(server='freenode', ...)
+      IRC(server='efnet', ...)
     """
     """
-    def __init__(self, server='chat.freenode.net', nick=None,
+    base_urls = {  # convenient nicknames for common networks
+        'freenode': 'http://webchat.freenode.net/',
+        'efnet': 'http://chat.efnet.org:9090/',
+        }
+
+    def __init__(self, server='http://webchat.freenode.net/', nick=None,
                  channels=('#ipython','#rogue'), width=647, height=400):
         self.server = server
         self.nick = nick
         self.channels = channels
         self.width = width
         self.height = height
                  channels=('#ipython','#rogue'), width=647, height=400):
         self.server = server
         self.nick = nick
         self.channels = channels
         self.width = width
         self.height = height
-        if self.server not in [
-                'chat.freenode.net',
-                ]:
-            raise NotImplementedError(self.server)
 
 
-    def _html(self):
+    def _get_server(self):
+        server = self.server
+        if not server.startswith('http://'):
+            base = self.base_urls.get(server, None)
+            if not base:
+                raise NotImplementedError(
+                    '{!r} not supported.  We *do* support {}'.format(
+                        self.server, self.base_urls))
+        return server
+
+    def _get_data(self):
         data = {}
         for attr in ['nick', 'channels']:
             value = getattr(self, attr)
         data = {}
         for attr in ['nick', 'channels']:
             value = getattr(self, attr)
@@ -62,10 +82,15 @@ class IRC (object):
                 data[attr] = value
             else:
                 data['prompt'] = 1
                 data[attr] = value
             else:
                 data['prompt'] = 1
-        url = '{}?{}'.format(
-            'http://webchat.freenode.net',
-            _urllib_parse.urlencode(data)
-            )
+        return data
+
+    def _get_url(self):
+        return '{}?{}'.format(
+            self._get_server(),
+            _urllib_parse.urlencode(self._get_data()))
+
+    def _html(self):
+        url = self._get_url()
         return '<iframe src="{}" width="{}" height="{}"></iframe>'.format(
             url, self.width, self.height)
 
         return '<iframe src="{}" width="{}" height="{}"></iframe>'.format(
             url, self.width, self.height)
 
index 251c137380d40b2f1dfa967531fdcfdcee345a3c..f2ca87083b524f8810244985101d63083fae30d4 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -15,7 +15,7 @@
 # You should have received a copy of the GNU General Public License along with
 # ipython-irc.  If not, see <http://www.gnu.org/licenses/>.
 
 # You should have received a copy of the GNU General Public License along with
 # ipython-irc.  If not, see <http://www.gnu.org/licenses/>.
 
-"An IRC iframe using webchat.freenode.net"
+"An IRC iframe that connects to qwebirc instances"
 
 from distutils.core import setup
 
 
 from distutils.core import setup