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.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.warn('%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') else: try: [i, o, e] = select.select([self.sock], [], []) except socket.error: doreconnect = False ; break if i: intxt = inputmorphs.do(self.sock.recv(600)).split('\n') if self.stopreadloop or self.stopped: doreconnect = 0 break if not i: time.sleep(0.1) ; continue if not intxt: 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: logging.warn("%s - decode error - ignoring" % self.cfg.name) continue if not rr: continue res = rr logging.info(u"%s - %s" % (self.cfg.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.SSLError, ex: logging.error("%s - ssl error: %s" % (self.cfg.name, str(ex))) ; break except socket.timeout, ex: logging.debug("%s - socket timeout" % self.cfg.name) self.error = str(ex) if self.stopped or self.stopreadloop: break timeout += 1 if timeout > 2: doreconnect = 1 logging.warn('%s - no pong received' % 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('%s - no pong received' % self.cfg.name) break logging.error("%s - socket timeout" % 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