def _validateElemStart(self, name, attr, version):
		"""Test the validity of an element starting inside a <template>
		element.

		This function raises an AimlParserError exception if it the tag is
		invalid.  Otherwise, no news is good news.

		"""		
		# Check the element's attributes.  Make sure that all required
		# attributes are present, and that any remaining attributes are
		# valid options.		
		required, optional, canBeParent = self._validInfo[name]
		for a in required:
			if a not in attr and not self._forwardCompatibleMode:
				raise AimlParserError, ("Required \"%s\" attribute missing in <%s> element " % (a,name))+self._location()
		for a in attr:
			if a in required: continue
			if a[0:4] == "xml:": continue # attributes in the "xml" namespace can appear anywhere
			if a not in optional and not self._forwardCompatibleMode:
				raise AimlParserError, ("Unexpected \"%s\" attribute in <%s> element " % (a,name))+self._location()

		# special-case: several tags contain an optional "index" attribute.
		# This attribute's value must be a positive integer.
		if name in ["star", "thatstar", "topicstar"]:
			for k,v in attr.items():
				if k == "index":
					temp = 0
					try: temp = int(v)
					except:
						raise AimlParserError, ("Bad type for \"%s\" attribute (expected integer, found \"%s\") " % (k,v))+self._location()
					if temp < 1:
						raise AimlParserError, ("\"%s\" attribute must have non-negative value " % (k))+self._location()

		# See whether the containing element is permitted to contain
		# subelements. If not, this element is invalid no matter what it is.
		try:
			parent = self._elemStack[-1][0]
			parentAttr = self._elemStack[-1][1]
		except __HOLE__:
			# If the stack is empty, no parent is present.  This should never
			# happen.
			raise AimlParserError, ("Element stack is empty while validating <%s> " % name)+self._location()
		required, optional, canBeParent = self._validInfo[parent]
		nonBlockStyleCondition = (parent == "condition" and not (parentAttr.has_key("name") and parentAttr.has_key("value")))
		if not canBeParent:
			raise AimlParserError, ("<%s> elements cannot have any contents "%parent)+self._location()
		# Special-case test if the parent element is <condition> (the
		# non-block-style variant) or <random>: these elements can only
		# contain <li> subelements.
		elif (parent == "random" or nonBlockStyleCondition) and name!="li":
			raise AimlParserError, ("<%s> elements can only contain <li> subelements "%parent)+self._location()
		# Special-case test for <li> elements, which can only be contained
		# by non-block-style <condition> and <random> elements, and whose
		# required attributes are dependent upon which attributes are
		# present in the <condition> parent.
		elif name=="li":
			if not (parent=="random" or nonBlockStyleCondition):
				raise AimlParserError, ("Unexpected <li> element contained by <%s> element "%parent)+self._location()
			if nonBlockStyleCondition:
				if parentAttr.has_key("name"):
					# Single-predicate condition.  Each <li> element except the
					# last must have a "value" attribute.
					if len(attr) == 0:
						# This could be the default <li> element for this <condition>,
						# unless we've already found one.
						if self._foundDefaultLiStack[-1]:
							raise AimlParserError, "Unexpected default <li> element inside <condition> "+self._location()
						else:
							self._foundDefaultLiStack[-1] = True
					elif len(attr) == 1 and attr.has_key("value"):
						pass # this is the valid case
					else:
						raise AimlParserError, "Invalid <li> inside single-predicate <condition> "+self._location()
				elif len(parentAttr) == 0:
					# Multi-predicate condition.  Each <li> element except the
					# last must have a "name" and a "value" attribute.
					if len(attr) == 0:
						# This could be the default <li> element for this <condition>,
						# unless we've already found one.
						if self._foundDefaultLiStack[-1]:
							raise AimlParserError, "Unexpected default <li> element inside <condition> "+self._location()
						else:
							self._foundDefaultLiStack[-1] = True
					elif len(attr) == 2 and attr.has_key("value") and attr.has_key("name"):
						pass # this is the valid case
					else:
						raise AimlParserError, "Invalid <li> inside multi-predicate <condition> "+self._location()
		# All is well!
		return True
dataset/ETHPy150Open encorehu/django-buddy/core/aiml/AimlParser.py/AimlHandler._validateElemStart