def __init__(self, transp=None, host=None, port=None, addResource=True, createSock=True, eventType=SE.SipEvent): EventHandler.__init__(self) self.sock = None self.transp = None self.ip = None self.port = None self.remoteip = None self.remoteport = None self.timeout = None self.state = NetworkEventHandler.NEH_NO_SOCK self.pkgsize = Config.MAX_PKG_SIZE self.data = None self.old_data = None self.eventType = eventType if transp is None: transp = Config.DEFAULT_NETWORK_TRANSPORT if (transp.lower() == "udp" or transp.lower() == "tcp"): self.setTransport(transp) else: raise SCException("NetworkEventHandler", "__init__", "unsupported transport type") if host is None: host = Config.LOCAL_IP if port is None: port = int(Config.LOCAL_PORT) if host.startswith("["): host = host[1:] if host.endswith("]"): host = host[:len(host) - 1] self.localip = host self.localport = port # Because we can not return another NEH instance if a new instance for # the same triplet (transport, ip, port) was requested, we simply # close the existing NEH and the create a new one key = str(getTransportNumber(transp)) + str(host) + str(port) + "00" if addResource and Config.resources.has_key( 'NEH') and Config.resources['NEH'].has_key(key): Log.logDebug( "NetworkEventHandler.init(): closing NEH which uses the same address (key '" + key + "') to prevent bind error", 3) Config.resources['NEH'][key].close() if createSock: self.createSock(transp, host, port) if addResource: Config.resources['NEH'][key] = self
def __init__(self, _filename=None, _fixLF=True, addResource=True): """If a filename is given as parameter that file will be opened for reading. If the second parameter is True single line-feeds will be replaced by carriage-return line-feed while reading in and writing to a file. """ EventHandler.__init__(self) self.filename = None self.fileobj = None self.fixLF = _fixLF if _filename is not None: self.filename = _filename self.openFile("r") if addResource: Config.resources['FEH'][self.filename] = self
def __init__(self, _filename=None, addResource=True): """If a filename is given as parameter that file will be opened for reading. If the second parameter is True single line-feeds will be replaced by carriage-return line-feed while reading in and writing to a file. """ EventHandler.__init__(self) self.filename = None self.fileobj = None self.framenr = 0 if _filename is not None: self.filename = _filename self.openFile(mode="w") if addResource: if self.filename.endswith('.xml'): fn = self.filename[:len(self.filename)-4] else: fn = self.filename Config.resources['XMLEH'][fn] = self
def __init__(self, _filename=None, addResource=True): """If a filename is given as parameter that file will be opened for reading. If the second parameter is True single line-feeds will be replaced by carriage-return line-feed while reading in and writing to a file. """ EventHandler.__init__(self) self.filename = None self.fileobj = None self.framenr = 0 if _filename is not None: self.filename = _filename self.openFile(mode="w") if addResource: if self.filename.endswith('.xml'): fn = self.filename[:len(self.filename) - 4] else: fn = self.filename Config.resources['XMLEH'][fn] = self
def __init__(self, transp=None, host=None, port=None, addResource=True, createSock=True, eventType=SE.SipEvent): EventHandler.__init__(self) self.sock = None self.transp = None self.ip = None self.port = None self.remoteip = None self.remoteport = None self.timeout = None self.state = NetworkEventHandler.NEH_NO_SOCK self.pkgsize = Config.MAX_PKG_SIZE self.data = None self.old_data = None self.eventType = eventType if transp is None: transp = Config.DEFAULT_NETWORK_TRANSPORT if (transp.lower() == "udp" or transp.lower() == "tcp"): self.setTransport(transp) else: raise SCException("NetworkEventHandler", "__init__", "unsupported transport type") if host is None: host = Config.LOCAL_IP if port is None: port = int(Config.LOCAL_PORT) if host.startswith("["): host = host[1:] if host.endswith("]"): host = host[:len(host)-1] self.localip = host self.localport = port # Because we can not return another NEH instance if a new instance for # the same triplet (transport, ip, port) was requested, we simply # close the existing NEH and the create a new one key = str(getTransportNumber(transp)) + str(host) + str(port) + "00" if addResource and Config.resources.has_key('NEH') and Config.resources['NEH'].has_key(key): Log.logDebug("NetworkEventHandler.init(): closing NEH which uses the same address (key '" + key + "') to prevent bind error", 3) Config.resources['NEH'][key].close() if createSock: self.createSock(transp, host, port) if addResource: Config.resources['NEH'][key] = self