Mercurial > xib
comparison irclib.py @ 56:b048c4c03b00
Fixed encoding issues
Signed-off-by: Charly COSTE <changaco@changaco.net>
author | Charly COSTE <changaco@changaco.net> |
---|---|
date | Thu, 27 Aug 2009 22:31:47 +0200 |
parents | 9f72353e4064 |
children | ebd4278e472f |
comparison
equal
deleted
inserted
replaced
55:c09f9523fe2e | 56:b048c4c03b00 |
---|---|
429 | 429 |
430 self.lock.acquire() | 430 self.lock.acquire() |
431 | 431 |
432 if self.connected == True: | 432 if self.connected == True: |
433 self.used_by += 1 | 433 self.used_by += 1 |
434 self.irclibobj.bot.error('===> Debug: using existing IRC connection for '+str(self)+', this connection is now used by '+str(self.used_by)+' bridges', debug=True) | 434 self.irclibobj.bot.error('===> Debug: using existing IRC connection for '+self.__str__()+', this connection is now used by '+str(self.used_by)+' bridges', debug=True) |
435 self.nick(self.real_nickname, callback=nick_callback) | 435 self.nick(self.real_nickname, callback=nick_callback) |
436 self.lock.release() | 436 self.lock.release() |
437 return self | 437 return self |
438 | 438 |
439 | 439 |
447 self.password = password | 447 self.password = password |
448 self.localaddress = localaddress | 448 self.localaddress = localaddress |
449 self.localport = localport | 449 self.localport = localport |
450 self.localhost = socket.gethostname() | 450 self.localhost = socket.gethostname() |
451 | 451 |
452 self.irclibobj.bot.error('===> Debug: opening new IRC connection for '+str(self), debug=True) | 452 self.irclibobj.bot.error('===> Debug: opening new IRC connection for '+self.__str__(), debug=True) |
453 | 453 |
454 if ipv6: | 454 if ipv6: |
455 self.socket = socket.socket(socket.AF_INET6, socket.SOCK_STREAM) | 455 self.socket = socket.socket(socket.AF_INET6, socket.SOCK_STREAM) |
456 else: | 456 else: |
457 self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | 457 self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
469 self.irclibobj.fn_to_add_socket(self.socket) | 469 self.irclibobj.fn_to_add_socket(self.socket) |
470 | 470 |
471 # Log on... | 471 # Log on... |
472 if self.password: | 472 if self.password: |
473 self.pass_(self.password) | 473 self.pass_(self.password) |
474 self.nick(self.nickname, callback=nick_callback) | 474 if self.nick(self.nickname, callback=nick_callback) == True: |
475 self.user(self.username, self.ircname) | 475 self.user(self.username, self.ircname) |
476 self.lock.release() | 476 self.lock.release() |
477 return self | 477 return self |
478 | 478 |
479 | 479 |
480 def _call_nick_callbacks(self, error, arguments=[]): | 480 def _call_nick_callbacks(self, error, arguments=[]): |
482 for f in self.nick_callbacks: | 482 for f in self.nick_callbacks: |
483 i += 1 | 483 i += 1 |
484 f(error, arguments=arguments) | 484 f(error, arguments=arguments) |
485 self.nick_callbacks = [] | 485 self.nick_callbacks = [] |
486 if i == 0: | 486 if i == 0: |
487 self.irclibobj.bot.error('=> Debug: no nick callback for "'+str(self)+'"', debug=True) | 487 self.irclibobj.bot.error('=> Debug: no nick callback for "'+self.__str__()+'"', debug=True) |
488 else: | 488 else: |
489 self.irclibobj.bot.error('=> Debug: called '+str(i)+' callback(s) for "'+str(self)+'"', debug=True) | 489 self.irclibobj.bot.error('=> Debug: called '+str(i)+' callback(s) for "'+self.__str__()+'"', debug=True) |
490 | 490 |
491 | 491 |
492 def add_nick_callback(self, callback): | 492 def add_nick_callback(self, callback): |
493 self.nick_callbacks.append(callback) | 493 self.nick_callbacks.append(callback) |
494 | 494 |
777 """Send a NICK command.""" | 777 """Send a NICK command.""" |
778 if callback != None: | 778 if callback != None: |
779 self.add_nick_callback(callback) | 779 self.add_nick_callback(callback) |
780 if ' ' in newnick: | 780 if ' ' in newnick: |
781 self._call_nick_callbacks('erroneusnickname') | 781 self._call_nick_callbacks('erroneusnickname') |
782 return | 782 return False |
783 try: | |
784 str(newnick) | |
785 except: | |
786 self._call_nick_callbacks('erroneusnickname') | |
787 return False | |
783 self.send_raw("NICK " + newnick) | 788 self.send_raw("NICK " + newnick) |
789 return True | |
784 | 790 |
785 def notice(self, target, text): | 791 def notice(self, target, text): |
786 """Send a NOTICE command.""" | 792 """Send a NOTICE command.""" |
787 # Should limit len(text) here! | 793 # Should limit len(text) here! |
788 self.send_raw("NOTICE %s :%s" % (target, text)) | 794 self.send_raw("NOTICE %s :%s" % (target, text)) |
831 def send_raw(self, string): | 837 def send_raw(self, string): |
832 """Send raw string to the server. | 838 """Send raw string to the server. |
833 | 839 |
834 The string will be padded with appropriate CR LF. | 840 The string will be padded with appropriate CR LF. |
835 """ | 841 """ |
836 from encoding import * | |
837 if self.socket is None: | 842 if self.socket is None: |
838 raise ServerNotConnectedError, "Not connected." | 843 raise ServerNotConnectedError, "Not connected." |
839 try: | 844 try: |
840 if self.ssl: | 845 if self.ssl: |
841 self.ssl.write(auto_encode(string) + "\r\n") | 846 self.ssl.write(string.encode('utf-8') + "\r\n") |
842 else: | 847 else: |
843 self.socket.send(auto_encode(string) + "\r\n") | 848 self.socket.send(string.encode('utf-8') + "\r\n") |
844 if DEBUG: | 849 if DEBUG: |
845 print "TO SERVER:", string | 850 print "TO SERVER:", string |
846 except socket.error, x: | 851 except socket.error, x: |
847 # Ouch! | 852 # Ouch! |
848 self.disconnect("Connection reset by peer.") | 853 self.disconnect("Connection reset by peer.") |