def handle_ievent(self, ievent): """ check for callbacks, call Irc method. """ try: Irc.handle_ievent(self, ievent) if ievent.cmnd == 'JOIN' or ievent.msg: if ievent.nick in self.nicks401: self.nicks401.remove(ievent.nick) if ievent.cmnd != "PRIVMSG": i = IrcEvent() i.copyin(ievent) i.bot = self i.sock = self.sock ievent.nocb = True self.doevent(i) except: handle_exception()
(errno, errstr) = ex except: errno = 0 errstr = str(ex) if errno == 35 or errno == 11: continue else: raise except Exception, ex: handle_exception() logging.warn('%s - closing dcc with %s' % (self.name, nick)) partyline.del_party(nick) return try: res = self.normalize(res) ievent = IrcEvent() ievent.printto = sock ievent.bottype = "irc" ievent.nick = nick ievent.userhost = userhost ievent.auth = userhost ievent.channel = channel or ievent.userhost ievent.origtxt = res ievent.txt = res ievent.cmnd = 'DCC' ievent.cbtype = 'DCC' ievent.bot = self ievent.sock = sock ievent.speed = 1 ievent.isdcc = True ievent.msg = True
(errno, errstr) = ex except: errno = 0 errstr = str(ex) if errno == 35 or errno == 11: continue else: raise except Exception, ex: handle_exception() logging.warn('closing dcc with %s' % (nick, self.cfg.name)) partyline.del_party(nick) return try: res = self.normalize(res) ievent = IrcEvent() ievent.printto = sock ievent.bottype = "irc" ievent.nick = nick ievent.userhost = userhost ievent.auth = userhost ievent.channel = channel or ievent.userhost ievent.origtxt = res ievent.txt = res ievent.cmnd = 'DCC' ievent.cbtype = 'DCC' ievent.bot = self ievent.sock = sock ievent.speed = 1 ievent.isdcc = True ievent.msg = True
def fakein(self, txt): """ do a fake ircevent. """ if not txt: return logging.debug('%s - fakein - %s' % (self.cfg.name, txt)) self.handle_ievent(IrcEvent().parse(self, txt))
def _readloop(self): """ loop on the socketfile. """ self.stopreadloop = False self.stopped = False doreconnect = True timeout = 1 logging.debug('%s - starting readloop' % self.cfg.name) prevtxt = "" while not self.stopped and not self.stopreadloop and self.sock and self.fsock: try: time.sleep(0.01) if self.cfg.has_key('ssl') and self.cfg['ssl']: intxt = inputmorphs.do(self.sock.read()).split('\n') else: intxt = inputmorphs.do(self.fsock.readline()).split('\n') if self.stopreadloop or self.stopped: doreconnect = 0 break if intxt == [ "", ]: logging.error("remote disconnected") doreconnect = 1 break if prevtxt: intxt[0] = prevtxt + intxt[0] prevtxt = "" if intxt[-1] != '': prevtxt = intxt[-1] intxt = intxt[:-1] for r in intxt: if not r: continue try: r = strippedtxt(r.rstrip(), ["\001", "\002", "\003"]) rr = unicode(fromenc(r.rstrip(), self.encoding)) except UnicodeDecodeError: if not r: logging.warn("decode error - ignoring (%s)" % self.cfg.name) continue rr = r if not rr: continue res = rr try: ievent = IrcEvent().parse(self, res) except Exception, ex: handle_exception() continue try: if int(ievent.cmnd) > 400: logging.error(u"< %s (%s)" % (res, self.cfg.name)) elif int(ievent.cmnd) >= 300: logging.info(u"< %s (%s)" % (res, self.cfg.name)) except ValueError: if not res.startswith("PING") and not res.startswith( "NOTICE"): logging.warn(u"< %s (%s)" % (res, self.cfg.name)) else: logging.info(u"< %s (%s)" % (res, self.cfg.name)) if ievent: self.handle_ievent(ievent) timeout = 1 except UnicodeError: handle_exception() continue except socket.timeout, ex: logging.warn("socket timeout (%s)" % self.cfg.name) self.error = str(ex) if self.stopped or self.stopreadloop: break timeout += 1 if timeout > 2: doreconnect = 1 logging.warn('no pong received (%s)' % self.cfg.name) break pingsend = self.ping() if not pingsend: doreconnect = 1 break continue except socket.sslerror, ex: self.error = str(ex) if self.stopped or self.stopreadloop: break if not 'timed out' in str(ex): handle_exception() doreconnect = 1 break timeout += 1 if timeout > 2: doreconnect = 1 logging.warn('no pong received (%s)' % self.cfg.name) break logging.warn("socket timeout (%s)" % self.cfg.name) pingsend = self.ping() if not pingsend: doreconnect = 1 break continue
def _readloop(self): """ loop on the socketfile. """ self.stopreadloop = False self.stopped = False doreconnect = True timeout = 1 logging.info('%s - starting readloop' % self.name) prevtxt = "" while not self.stopped and not self.stopreadloop and self.sock and self.fsock: try: time.sleep(0.01) if self.cfg.has_key('ssl') and self.cfg['ssl']: intxt = inputmorphs.do(self.sock.read()).split('\n') else: intxt = inputmorphs.do(self.fsock.readline()).split('\n') if self.stopreadloop or self.stopped: doreconnect = 0 break if not intxt or not intxt[0]: doreconnect = 1 break if prevtxt: intxt[0] = prevtxt + intxt[0] prevtxt = "" if intxt[-1] != '': prevtxt = intxt[-1] intxt = intxt[:-1] for r in intxt: try: r = strippedtxt(r.rstrip(), ["\001", "\002", "\003"]) rr = unicode(fromenc(r.rstrip(), self.encoding)) except UnicodeDecodeError: logging.warn("%s - decode error - ignoring" % self.name) continue if not rr: continue res = rr logging.debug(u"%s - %s" % (self.name, res)) try: ievent = IrcEvent().parse(self, res) except Exception, ex: handle_exception() continue if ievent: self.handle_ievent(ievent) timeout = 1 except UnicodeError: handle_exception() continue except socket.timeout: if self.stopped or self.stopreadloop: break timeout += 1 if timeout > 2: doreconnect = 1 logging.warn('%s - no pong received' % self.name) break logging.debug("%s - socket timeout" % self.name) pingsend = self.ping() if not pingsend: doreconnect = 1 break continue except socket.sslerror, ex: if self.stopped or self.stopreadloop: break if not 'timed out' in str(ex): handle_exception() doreconnect = 1 break timeout += 1 if timeout > 2: doreconnect = 1 logging.warn('%s - no pong received' % self.name) break logging.error("%s - socket timeout" % self.name) pingsend = self.ping() if not pingsend: doreconnect = 1 break continue except IOError, ex: if self.blocking and 'temporarily' in str(ex): time.sleep(0.5) continue if not self.stopped: logging.error('%s - connecting error: %s' % (self.name, str(ex))) handle_exception() doreconnect = 1 break