# Path: EventHandler.py
# class EventHandler:
# 	"""An abstract class for SIP event handling classes."""
# 
# 	def __init__(self):
# 		pass
# 
# 	def readEvent(self):
# 		"""This function will be called to get a SIP event as return value.
# 		"""
# 		raise SCNotImplemented("EventHandler", "readEvent", "not implemented")
# 
# 	def writeEvent(self, event):
# 		"""This function will be called to write the given SIP event to the
# 		destination.
# 		"""
# 		raise SCNotImplemented("EventHandler", "writeEvent", "not implemented")
# 
# Path: SCException.py
# class SCException(Exception):
# 	"""Generic internal exception class. Consits out of class name, function
# 	name and the reason phrase.
# 	"""
# 
# 	def __init__(self, cls, funct, reason):
# 		Exception.__init__(self)
# 		self.cls = cls
# 		self.funct = funct
# 		self.reason = reason
# 
# 	def __str__(self):
# 		return str(self.cls) + '.' + str(self.funct) + '(): ' + str(self.reason)
# 
# class SCNotImplemented (SCException):
# 	"""See SCException. Called if implementation is missing."""
# 
# 	def __init__(self, cls, function, reason):
# 		SCException.__init__(self, cls, function, reason)


from EventHandler import EventHandler
from SCException import SCException, SCNotImplemented
import Log, Config, socket, select, copy
import SipEvent as SE
import time
		successfull, False otherwise.
		"""
		if (self.sock is None):
			if (self.transp is None):
				raise SCException("NetworkEventHandler", "writeEvent", "no socket and transport given")
			else:
				self.createSock(self.transp, Config.LOCAL_IP, Config.LOCAL_PORT)
		else:
			#SOL_SOCKET = getattr(socket, "SOL_SOCKET")
			#SO_TYPE = getattr(socket, "SO_TYPE")
			self.transp = self.sock.getsockopt(socket.SOL_SOCKET, socket.SO_TYPE)
			sn = self.sock.getsockname()
			self.ip = sn[0]
			perc = self.ip.find("%")
			if (perc != -1):
				self.ip = self.ip[:perc]
			col = self.ip.find(":")
			if (col != -1):
				if not self.ip.startswith("["):
					self.ip = "[" + self.ip
				if not self.ip.endswith("]"):
					self.ip = self.ip + "]"
			self.port = sn[1]
		# to prevent conversion at other places
		if isinstance(event.srcAddress[2], str):
			if event.srcAddress[2].lower() == "udp":
				event.srcAddress = (event.srcAddress[0], event.srcAddress[1], socket.SOCK_DGRAM)
			elif event.srcAddress[2].lower() == "tcp":
				event.srcAddress = (event.srcAddress[0], event.srcAddress[1], socket.SOCK_STREAM)
		if (event.srcAddress[0] != "file") and (event.srcAddress[2] != self.transp):

# Path: EventHandler.py
# class EventHandler:
# 	"""An abstract class for SIP event handling classes."""
# 
# 	def __init__(self):
# 		pass
# 
# 	def readEvent(self):
# 		"""This function will be called to get a SIP event as return value.
# 		"""
# 		raise SCNotImplemented("EventHandler", "readEvent", "not implemented")
# 
# 	def writeEvent(self, event):
# 		"""This function will be called to write the given SIP event to the
# 		destination.
# 		"""
# 		raise SCNotImplemented("EventHandler", "writeEvent", "not implemented")
# 
# Path: SCException.py
# class SCException(Exception):
# 	"""Generic internal exception class. Consits out of class name, function
# 	name and the reason phrase.
# 	"""
# 
# 	def __init__(self, cls, funct, reason):
# 		Exception.__init__(self)
# 		self.cls = cls
# 		self.funct = funct
# 		self.reason = reason
# 
# 	def __str__(self):
# 		return str(self.cls) + '.' + str(self.funct) + '(): ' + str(self.reason)
# 
# class SCNotImplemented (SCException):
# 	"""See SCException. Called if implementation is missing."""
# 
# 	def __init__(self, cls, function, reason):
# 		SCException.__init__(self, cls, function, reason)


# Path: NetworkEventHandler.py
from EventHandler import EventHandler
from SCException import SCException, SCNotImplemented
import Log, Config, socket, select, copy
import SipEvent as SE
import time

		successfull, False otherwise.
		"""
		if (self.sock is None):
			if (self.transp is None):
				raise SCException("NetworkEventHandler", "writeEvent", "no socket and transport given")
			else:
				self.createSock(self.transp, Config.LOCAL_IP, Config.LOCAL_PORT)
		else:
			#SOL_SOCKET = getattr(socket, "SOL_SOCKET")
			#SO_TYPE = getattr(socket, "SO_TYPE")
			self.transp = self.sock.getsockopt(socket.SOL_SOCKET, socket.SO_TYPE)
			sn = self.sock.getsockname()
			self.ip = sn[0]
			perc = self.ip.find("%")
			if (perc != -1):
				self.ip = self.ip[:perc]
			col = self.ip.find(":")
			if (col != -1):
				if not self.ip.startswith("["):
					self.ip = "[" + self.ip
				if not self.ip.endswith("]"):
					self.ip = self.ip + "]"
			self.port = sn[1]
		# to prevent conversion at other places
		if isinstance(event.srcAddress[2], str):
			if event.srcAddress[2].lower() == "udp":
				event.srcAddress = (event.srcAddress[0], event.srcAddress[1], socket.SOCK_DGRAM)
			elif event.srcAddress[2].lower() == "tcp":
				event.srcAddress = (event.srcAddress[0], event.srcAddress[1], socket.SOCK_STREAM)
		if (event.srcAddress[0] != "file") and (event.srcAddress[2] != self.transp):

			raise SCException("NetworkEventHandler", "writeEvent", "event transport != socket type")