Mercurial > xib
comparison irclib.py @ 196:4011838e098e
[irclib] handle ServerNotConnectedError in part() and quit(), we now keep track of channels we're in and rejoin them after a disconnection
Signed-off-by: Charly COSTE <changaco@changaco.net>
author | Charly COSTE <changaco@changaco.net> |
---|---|
date | Sun, 21 Feb 2010 16:56:22 +0100 |
parents | 102f895347ff |
children | 6388579c701d |
comparison
equal
deleted
inserted
replaced
195:e4ceefab8ba5 | 196:4011838e098e |
---|---|
523 | 523 |
524 if self.socket != 'closed': | 524 if self.socket != 'closed': |
525 self.used_by = 1 | 525 self.used_by = 1 |
526 if charsets or not self.irclibobj.charsets.has_key(self._server_str()): | 526 if charsets or not self.irclibobj.charsets.has_key(self._server_str()): |
527 self.irclibobj.charsets[self._server_str()] = charsets | 527 self.irclibobj.charsets[self._server_str()] = charsets |
528 self.channels = [] | |
529 self.channels_keys = {} | |
528 self.irc_id = None | 530 self.irc_id = None |
529 self.previous_buffer = "" | 531 self.previous_buffer = "" |
530 self.handlers = {} | 532 self.handlers = {} |
531 self.real_server_name = "" | 533 self.real_server_name = "" |
532 self.real_nickname = self.nickname | 534 self.real_nickname = self.nickname |
577 if self.password: | 579 if self.password: |
578 self.pass_(self.password) | 580 self.pass_(self.password) |
579 if self.nick(self.nickname): | 581 if self.nick(self.nickname): |
580 self.user(self.username, self.ircname) | 582 self.user(self.username, self.ircname) |
581 | 583 |
584 # Rejoin channels | |
585 if len(self.channels) > 0: | |
586 for channel in self.channels: | |
587 if self.channels_keys.has_key(channel): | |
588 key = self.channels_keys[channel] | |
589 else: | |
590 key = '' | |
591 self.join(channel, key=key) | |
592 | |
582 self.lock.release() | 593 self.lock.release() |
583 return self | 594 return self |
584 | 595 |
585 | 596 |
586 def _call_nick_callbacks(self, error, arguments=[]): | 597 def _call_nick_callbacks(self, error, arguments=[]): |
864 | 875 |
865 def join(self, channel, key=""): | 876 def join(self, channel, key=""): |
866 """Send a JOIN command.""" | 877 """Send a JOIN command.""" |
867 if channel in self.left_channels: | 878 if channel in self.left_channels: |
868 self.left_channels.remove(channel) | 879 self.left_channels.remove(channel) |
880 if not channel in self.channels: | |
881 self.channels.append(channel) | |
882 if key and not self.channels_keys.has_key(channel): | |
883 self.channels_keys[channel] = key | |
869 self.send_raw("JOIN %s%s" % (channel, (key and (" " + key)))) | 884 self.send_raw("JOIN %s%s" % (channel, (key and (" " + key)))) |
870 | 885 |
871 def kick(self, channel, nick, comment=""): | 886 def kick(self, channel, nick, comment=""): |
872 """Send a KICK command.""" | 887 """Send a KICK command.""" |
873 self.send_raw("KICK %s %s%s" % (channel, nick, (comment and (" :" + comment)))) | 888 self.send_raw("KICK %s %s%s" % (channel, nick, (comment and (" :" + comment)))) |
927 self.send_raw("NOTICE %s :%s" % (target, text)) | 942 self.send_raw("NOTICE %s :%s" % (target, text)) |
928 | 943 |
929 def oper(self, nick, password): | 944 def oper(self, nick, password): |
930 """Send an OPER command.""" | 945 """Send an OPER command.""" |
931 self.send_raw("OPER %s %s" % (nick, password)) | 946 self.send_raw("OPER %s %s" % (nick, password)) |
947 | |
948 def _remove_channel(self, channel): | |
949 if channel in self.channels: | |
950 self.channels.remove(channel) | |
951 if not channel in self.left_channels: | |
952 self.left_channels.append(channel) | |
932 | 953 |
933 def part(self, channels, message=""): | 954 def part(self, channels, message=""): |
934 """Send a PART command.""" | 955 """Send a PART command.""" |
935 if isinstance(channels, basestring): | 956 try: |
936 self.left_channels.append(channels) | 957 if isinstance(channels, basestring): |
937 self.send_raw("PART " + channels + (message and (" " + message))) | 958 self._remove_channel(channels) |
938 else: | 959 self.send_raw("PART " + channels + (message and (" " + message))) |
939 for channel in channels: | 960 else: |
940 self.left_channels.append(channel) | 961 for channel in channels: |
941 self.send_raw("PART " + ",".join(channels) + (message and (" " + message))) | 962 self._remove_channel(channel) |
963 self.send_raw("PART " + ",".join(channels) + (message and (" " + message))) | |
964 except ServerNotConnectedError: | |
965 self.disconnect(volontary=True) | |
966 self.connect() | |
942 | 967 |
943 def pass_(self, password): | 968 def pass_(self, password): |
944 """Send a PASS command.""" | 969 """Send a PASS command.""" |
945 self.send_raw("PASS " + password) | 970 self.send_raw("PASS " + password) |
946 | 971 |
972 | 997 |
973 def quit(self, message=""): | 998 def quit(self, message=""): |
974 """Send a QUIT command.""" | 999 """Send a QUIT command.""" |
975 # Note that many IRC servers don't use your QUIT message | 1000 # Note that many IRC servers don't use your QUIT message |
976 # unless you've been connected for at least 5 minutes! | 1001 # unless you've been connected for at least 5 minutes! |
977 self.send_raw("QUIT" + (message and (" :" + message))) | 1002 try: |
1003 self.send_raw("QUIT" + (message and (" :" + message))) | |
1004 except ServerNotConnectedError: | |
1005 pass | |
978 | 1006 |
979 def send_raw(self, string): | 1007 def send_raw(self, string): |
980 """Send raw string to the server. | 1008 """Send raw string to the server. |
981 | 1009 |
982 The string will be padded with appropriate CR LF. | 1010 The string will be padded with appropriate CR LF. |