Network/IRC/IrcWidget.py

changeset 2527
867488bb56b0
parent 2469
20d2166280bb
child 2528
688c7ef0a5b0
equal deleted inserted replaced
2523:139f182b72f6 2527:867488bb56b0
471 471
472 def __readyRead(self): 472 def __readyRead(self):
473 """ 473 """
474 Private slot to read data from the socket. 474 Private slot to read data from the socket.
475 """ 475 """
476 self.__buffer += str(self.__socket.readAll(), 476 if self.__socket:
477 Preferences.getSystem("IOEncoding"), 477 self.__buffer += str(self.__socket.readAll(),
478 'replace') 478 Preferences.getSystem("IOEncoding"),
479 if self.__buffer.endswith("\r\n"): 479 'replace')
480 for line in self.__buffer.splitlines(): 480 if self.__buffer.endswith("\r\n"):
481 line = line.strip() 481 for line in self.__buffer.splitlines():
482 if line: 482 line = line.strip()
483 logging.debug("<IRC> " + line) 483 if line:
484 handled = False 484 logging.debug("<IRC> " + line)
485 # step 1: give channels a chance to handle the message 485 handled = False
486 for channel in self.__channelList: 486 # step 1: give channels a chance to handle the message
487 handled = channel.handleMessage(line) 487 for channel in self.__channelList:
488 if handled: 488 handled = channel.handleMessage(line)
489 break 489 if handled:
490 else: 490 break
491 # step 2: try to process the message ourselves
492 for patternRe, patternFunc in self.__patterns:
493 match = patternRe.match(line)
494 if match is not None:
495 if patternFunc(match):
496 break
497 else: 491 else:
498 # Oops, the message wasn't handled 492 # step 2: try to process the message ourselves
499 self.networkWidget.addErrorMessage( 493 for patternRe, patternFunc in self.__patterns:
500 self.trUtf8("Message Error"), 494 match = patternRe.match(line)
501 self.trUtf8("Unknown message received from server:" 495 if match is not None:
502 "<br/>{0}").format(line)) 496 if patternFunc(match):
503 497 break
504 self.__updateUsersCount() 498 else:
505 self.__buffer = "" 499 # Oops, the message wasn't handled
500 self.networkWidget.addErrorMessage(
501 self.trUtf8("Message Error"),
502 self.trUtf8("Unknown message received from server:"
503 "<br/>{0}").format(line))
504
505 self.__updateUsersCount()
506 self.__buffer = ""
506 507
507 def __handleNamedMessage(self, match): 508 def __handleNamedMessage(self, match):
508 """ 509 """
509 Private method to handle a server message containing a message name. 510 Private method to handle a server message containing a message name.
510 511

eric ide

mercurial