Network/IRC/IrcWidget.py

branch
Py2 comp.
changeset 2531
a5034da7e61a
parent 2525
8b507a9a2d40
child 2532
f9500e2d2a8d
equal deleted inserted replaced
2530:1a4fb0fc46e2 2531:a5034da7e61a
477 477
478 def __readyRead(self): 478 def __readyRead(self):
479 """ 479 """
480 Private slot to read data from the socket. 480 Private slot to read data from the socket.
481 """ 481 """
482 self.__buffer += str(self.__socket.readAll(), 482 if self.__socket:
483 Preferences.getSystem("IOEncoding"), 483 self.__buffer += str(self.__socket.readAll(),
484 'replace') 484 Preferences.getSystem("IOEncoding"),
485 if self.__buffer.endswith("\r\n"): 485 'replace')
486 for line in self.__buffer.splitlines(): 486 if self.__buffer.endswith("\r\n"):
487 line = line.strip() 487 for line in self.__buffer.splitlines():
488 if line: 488 line = line.strip()
489 logging.debug("<IRC> " + line) 489 if line:
490 handled = False 490 logging.debug("<IRC> " + line)
491 # step 1: give channels a chance to handle the message 491 handled = False
492 for channel in self.__channelList: 492 # step 1: give channels a chance to handle the message
493 handled = channel.handleMessage(line) 493 for channel in self.__channelList:
494 if handled: 494 handled = channel.handleMessage(line)
495 break 495 if handled:
496 else: 496 break
497 # step 2: try to process the message ourselves
498 for patternRe, patternFunc in self.__patterns:
499 match = patternRe.match(line)
500 if match is not None:
501 if patternFunc(match):
502 break
503 else: 497 else:
504 # Oops, the message wasn't handled 498 # step 2: try to process the message ourselves
505 self.networkWidget.addErrorMessage( 499 for patternRe, patternFunc in self.__patterns:
506 self.trUtf8("Message Error"), 500 match = patternRe.match(line)
507 self.trUtf8("Unknown message received from server:" 501 if match is not None:
508 "<br/>{0}").format(line)) 502 if patternFunc(match):
509 503 break
510 self.__updateUsersCount() 504 else:
511 self.__buffer = "" 505 # Oops, the message wasn't handled
506 self.networkWidget.addErrorMessage(
507 self.trUtf8("Message Error"),
508 self.trUtf8("Unknown message received from server:"
509 "<br/>{0}").format(line))
510
511 self.__updateUsersCount()
512 self.__buffer = ""
512 513
513 def __handleNamedMessage(self, match): 514 def __handleNamedMessage(self, match):
514 """ 515 """
515 Private method to handle a server message containing a message name. 516 Private method to handle a server message containing a message name.
516 517

eric ide

mercurial