# Path: SCException.py
# class SCNotImplemented (SCException):
# 	"""See SCException. Called if implementation is missing."""
# 
# 	def __init__(self, cls, function, reason):
# 		SCException.__init__(self, cls, function, reason)
# 
# class HFHException(SCException):
# 	"""See SCException. Called for exceptions during parsing header fields."""
# 
# 	def __init__(self, cls, function, reason):
# 		SCException.__init__(self, cls, function, reason)
# 
# Path: NetworkEventHandler.py
# def compareHostNames(name1, name2):
# 	"""Compares the both given hostnames (DNS names or IPs) and
# 	returns True if they are equal (except DNS aliases), False otherwise.
# 	"""
# 	#FIXME IPs of aliases could be detected as not equal
# 	# the result lists should be compared each one by one
# 	if (name1 is None) or (name2 is None):
# 		return False
# 	try:
# 		list1 = socket.getaddrinfo(name1, 0, socket.AF_UNSPEC)
# 		ip1 = list1[0][4][0]
# 	except socket.gaierror:
# 		ip1 = name1
# 	try:
# 		list2 = socket.getaddrinfo(name2, 0, socket.AF_UNSPEC)
# 		ip2 = list2[0][4][0]
# 	except socket.gaierror:
# 		ip2 = name2
# 	if ip1 == ip2:
# 		return True
# 	else:
# 		return False


from HeaderFieldHandler import HeaderFieldHandler
from SCException import SCNotImplemented, HFHException
from NetworkEventHandler import compareHostNames
	def cmp(self, other):
		ret = 0
		cur = self
		cur_o = other
		while ((cur is not None) and (cur_o is not None) and (ret == 0)):
			ret = ret + cur.__cmp__(cur_o)
			cur = cur.next
		if ((cur is not None) and (cur_o is None)) or ((cur is None) and (cur_o is not None)):
			return False
		return ret == 0

	def parse(self, value):
		v = value.replace("\t", " ").replace("\r", "").lstrip()
		sep = v.find("/")
		if (sep != -1):
			self.protocol = v[:sep]
			v = v[sep+1:]
		else:
			raise HFHException("Via", "parse", "failed to parse because protocol/verion seperator '/' missing")
		sep = v.find("/")
		if (sep != -1):
			self.version = v[:sep]
			v = v[sep+1:]
		else:
			raise HFHException("Via", "parse", "failed to parse because version/transport seperator '/' missing")
		sep = v.find(" ")
		if (sep != -1):
			self.transport = v[:sep].rstrip()
			v = v[sep+1:].lstrip()
		else:

# Path: SCException.py
# class SCNotImplemented (SCException):
# 	"""See SCException. Called if implementation is missing."""
# 
# 	def __init__(self, cls, function, reason):
# 		SCException.__init__(self, cls, function, reason)
# 
# class HFHException(SCException):
# 	"""See SCException. Called for exceptions during parsing header fields."""
# 
# 	def __init__(self, cls, function, reason):
# 		SCException.__init__(self, cls, function, reason)
# 
# Path: NetworkEventHandler.py
# def compareHostNames(name1, name2):
# 	"""Compares the both given hostnames (DNS names or IPs) and
# 	returns True if they are equal (except DNS aliases), False otherwise.
# 	"""
# 	#FIXME IPs of aliases could be detected as not equal
# 	# the result lists should be compared each one by one
# 	if (name1 is None) or (name2 is None):
# 		return False
# 	try:
# 		list1 = socket.getaddrinfo(name1, 0, socket.AF_UNSPEC)
# 		ip1 = list1[0][4][0]
# 	except socket.gaierror:
# 		ip1 = name1
# 	try:
# 		list2 = socket.getaddrinfo(name2, 0, socket.AF_UNSPEC)
# 		ip2 = list2[0][4][0]
# 	except socket.gaierror:
# 		ip2 = name2
# 	if ip1 == ip2:
# 		return True
# 	else:
# 		return False


# Path: HFH/Via.py
from HeaderFieldHandler import HeaderFieldHandler
from SCException import SCNotImplemented, HFHException
from NetworkEventHandler import compareHostNames

	def cmp(self, other):
		ret = 0
		cur = self
		cur_o = other
		while ((cur is not None) and (cur_o is not None) and (ret == 0)):
			ret = ret + cur.__cmp__(cur_o)
			cur = cur.next
		if ((cur is not None) and (cur_o is None)) or ((cur is None) and (cur_o is not None)):
			return False
		return ret == 0

	def parse(self, value):
		v = value.replace("\t", " ").replace("\r", "").lstrip()
		sep = v.find("/")
		if (sep != -1):
			self.protocol = v[:sep]
			v = v[sep+1:]
		else:
			raise HFHException("Via", "parse", "failed to parse because protocol/verion seperator '/' missing")
		sep = v.find("/")
		if (sep != -1):
			self.version = v[:sep]
			v = v[sep+1:]
		else:
			raise HFHException("Via", "parse", "failed to parse because version/transport seperator '/' missing")
		sep = v.find(" ")
		if (sep != -1):
			self.transport = v[:sep].rstrip()
			v = v[sep+1:].lstrip()
		else:

			raise HFHException("Via", "parse", "failed to parse because LWS missing in front of uri")