From c55da4959b0450d2f47ff4e74e91cf3cf60cb5e7 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Sun, 14 Apr 2013 17:03:24 -0400 Subject: [PATCH] Restructure to make selecting servers easier 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 | 15 ++++++++++---- ipythonirc/__init__.py | 45 ++++++++++++++++++++++++++++++++---------- setup.py | 2 +- 3 files changed, 47 insertions(+), 15 deletions(-) diff --git a/README b/README index ced1942..eddb83a 100644 --- 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 ============ @@ -66,8 +71,10 @@ wking@tremily.us 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/ diff --git a/ipythonirc/__init__.py b/ipythonirc/__init__.py index 5b1e820..6f80905 100644 --- a/ipythonirc/__init__.py +++ b/ipythonirc/__init__.py @@ -39,20 +39,40 @@ class IRC (object): 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 - 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) @@ -62,10 +82,15 @@ class IRC (object): 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 ''.format( url, self.width, self.height) diff --git a/setup.py b/setup.py index 251c137..f2ca870 100644 --- 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 . -"An IRC iframe using webchat.freenode.net" +"An IRC iframe that connects to qwebirc instances" from distutils.core import setup -- 2.26.2