• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python xmlreader.Locator类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中xml.sax.xmlreader.Locator的典型用法代码示例。如果您正苦于以下问题:Python Locator类的具体用法?Python Locator怎么用?Python Locator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Locator类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: __init__

    def __init__(self, encoding = "UTF-8"):
        self.categories = {}
        self._encoding = encoding
        self._state = self._STATE_OutsideAiml
        self._version = ""
        self._namespace = ""
        self._forwardCompatibleMode = False
        self._currentPattern = ""
        self._currentThat    = ""
        self._currentTopic   = ""
        self._insideTopic = False
        self._currentUnknown = "" # the name of the current unknown element

        # This is set to true when a parse error occurs in a category.
        self._skipCurrentCategory = False

        # Counts the number of parse errors in a particular AIML document.
        # query with getNumErrors().  If 0, the document is AIML-compliant.
        self._numParseErrors = 0

        # TODO: select the proper validInfo table based on the version number.
        self._validInfo = self._validationInfo101

        # This stack of bools is used when parsing <li> elements inside
        # <condition> elements, to keep track of whether or not an
        # attribute-less "default" <li> element has been found yet.  Only
        # one default <li> is allowed in each <condition> element.  We need
        # a stack in order to correctly handle nested <condition> tags.
        self._foundDefaultLiStack = []
        
        self._elemStack = []
        self._locator = Locator()
        self.setDocumentLocator(self._locator)
开发者ID:atrinik,项目名称:atrinik,代码行数:33,代码来源:AimlParser.py


示例2: __init__

    def __init__(self, encoding="UTF-8"):
        self.categories = {}
        self._encoding = encoding
        self._state = self._STATE_OutsideAiml
        self._version = ""
        self._namespace = ""
        self._forwardCompatibleMode = False
        self._currentPattern = ""
        self._currentThat = ""
        self._currentTopic = ""
        self._insideTopic = False
        # the name of the current unknown element
        self._currentUnknown = ""

        # special treatment for <learn> to work with Badanswer.aiml
        # (http://www.alicebot.org/aiml/aaa/Badanswer.txt)
        self._insideLearn = False

        # This is set to true when a parse error occurs in a category.
        self._skipCurrentCategory = False

        # Counts the number of parse errors in a particular AIML document.
        # query with getNumErrors().  If 0, the document is AIML-compliant.
        self._numParseErrors = 0

        # TODO: select the proper validInfo table based on the version number.
        self._validInfo = self._validationInfo101_ext

        # This stack of bools is used when parsing <li> elements inside
        # <condition> elements, to keep track of whether or not an
        # attribute-less "default" <li> element has been found yet.  Only
        # one default <li> is allowed in each <condition> element.  We need
        # a stack in order to correctly handle nested <condition> tags.
        self._foundDefaultLiStack = []

        # This stack of strings indicates what the current whitespace-handling
        # behavior should be.  Each string in the stack is either "default" or
        # "preserve".  When a new AIML element is encountered, a new string is
        # pushed onto the stack, based on the value of the element's
        # "xml:space" attribute (if absent, the top of the stack is pushed
        # again).  When ending an element, pop an object off the stack.
        self._whitespaceBehaviorStack = ["default"]
        self._elemStack = []
        self._locator = Locator()
        self.setDocumentLocator(self._locator)
开发者ID:bithub,项目名称:bit.aiml.async,代码行数:45,代码来源:parser.py


示例3: __init__

 def __init__(self, encoding="UTF-8"):
     ContentHandler.__init__(self)
     self.categories = {}
     self._encoding = encoding
     self._state = self._STATE_OutsideAiml
     self._version = ""
     self._namespace = ""
     self._forwardCompatibleMode = False
     self._currentPattern = ""
     self._currentThat = ""
     self._currentTopic = ""
     self._insideTopic = False
     self._currentUnknown = "" # the name of the current unknown element
     self._skipCurrentCategory = False
     self._numParseErrors = 0
     self._validInfo = self._validationInfo101
     self._foundDefaultLiStack = []
     self._whitespaceBehaviorStack = ["default"]
     self._elemStack = []
     self._locator = Locator()
     self.setDocumentLocator(self._locator)
开发者ID:alfonsodg,项目名称:sboty,代码行数:21,代码来源:AimlParser.py


示例4: AimlHandler

class AimlHandler(ContentHandler):
    # The legal states of the AIML parser
    _STATE_OutsideAiml = 0
    _STATE_InsideAiml = 1
    _STATE_InsideCategory = 2
    _STATE_InsidePattern = 3
    _STATE_AfterPattern = 4
    _STATE_InsideThat = 5
    _STATE_AfterThat = 6
    _STATE_InsideTemplate = 7
    _STATE_AfterTemplate = 8

    def __init__(self, encoding="UTF-8"):
        self.categories = {}
        self._encoding = encoding
        self._state = self._STATE_OutsideAiml
        self._version = ""
        self._namespace = ""
        self._forwardCompatibleMode = False
        self._currentPattern = ""
        self._currentThat = ""
        self._currentTopic = ""
        self._insideTopic = False
        self._currentUnknown = ""  # the name of the current unknown element

        # This is set to true when a parse error occurs in a category.
        self._skipCurrentCategory = False

        # Counts the number of parse errors in a particular AIML document.
        # query with getNumErrors().  If 0, the document is AIML-compliant.
        self._numParseErrors = 0

        # TODO: select the proper validInfo table based on the version number.
        self._validInfo = self._validationInfo101

        # This stack of bools is used when parsing <li> elements inside
        # <condition> elements, to keep track of whether or not an
        # attribute-less "default" <li> element has been found yet.  Only
        # one default <li> is allowed in each <condition> element.  We need
        # a stack in order to correctly handle nested <condition> tags.
        self._foundDefaultLiStack = []

        # This stack of strings indicates what the current whitespace-handling
        # behavior should be.  Each string in the stack is either "default" or
        # "preserve".  When a new AIML element is encountered, a new string is
        # pushed onto the stack, based on the value of the element's "xml:space"
        # attribute (if absent, the top of the stack is pushed again).  When
        # ending an element, pop an object off the stack.
        self._whitespaceBehaviorStack = ["default"]

        self._elemStack = []
        self._locator = Locator()
        self.setDocumentLocator(self._locator)

    def getNumErrors(self):
        "Return the number of errors found while parsing the current document."
        return self._numParseErrors

    def setEncoding(self, encoding):
        """Set the text encoding to use when encoding strings read from XML.

		Defaults to 'UTF-8'.

		"""
        self._encoding = encoding

    def _location(self):
        "Return a string describing the current location in the source file."
        line = self._locator.getLineNumber()
        column = self._locator.getColumnNumber()
        return "(line %d, column %d)" % (line, column)

    def _pushWhitespaceBehavior(self, attr):
        """Push a new string onto the whitespaceBehaviorStack.

		The string's value is taken from the "xml:space" attribute, if it exists
		and has a legal value ("default" or "preserve").  Otherwise, the previous
		stack element is duplicated.

		"""
        assert len(self._whitespaceBehaviorStack) > 0, "Whitespace behavior stack should never be empty!"
        try:
            if attr["xml:space"] == "default" or attr["xml:space"] == "preserve":
                self._whitespaceBehaviorStack.append(attr["xml:space"])
            else:
                raise AimlParserError, "Invalid value for xml:space attribute " + self._location()
        except KeyError:
            self._whitespaceBehaviorStack.append(self._whitespaceBehaviorStack[-1])

    def startElementNS(self, name, qname, attr):
        print "QNAME:", qname
        print "NAME:", name
        uri, elem = name
        if elem == "bot":
            print "name:", attr.getValueByQName("name"), "a'ite?"
        self.startElement(elem, attr)
        pass

    def startElement(self, name, attr):
        # Wrapper around _startElement, which catches errors in _startElement()
#.........这里部分代码省略.........
开发者ID:KrustyHack,项目名称:pyAIML,代码行数:101,代码来源:AimlParser.py


示例5: AimlHandler

class AimlHandler(ContentHandler):
	# The legal states of the AIML parser
	_STATE_OutsideAiml    = 0
	_STATE_InsideAiml     = 1
	_STATE_InsideCategory = 2
	_STATE_InsidePattern  = 3
	_STATE_AfterPattern   = 4
	_STATE_InsideThat     = 5
	_STATE_AfterThat      = 6
	_STATE_InsideTemplate = 7
	_STATE_AfterTemplate  = 8
	
	def __init__(self, encoding = "UTF-8"):
		self.categories = {}
		self._encoding = encoding
		self._state = self._STATE_OutsideAiml
		self._version = ""
		self._namespace = ""
		self._forwardCompatibleMode = False
		self._currentPattern = ""
		self._currentThat    = ""
		self._currentTopic   = ""
		self._insideTopic = False
		self._currentUnknown = "" # the name of the current unknown element

		# This is set to true when a parse error occurs in a category.
		self._skipCurrentCategory = False

		# Counts the number of parse errors in a particular AIML document.
		# query with getNumErrors().  If 0, the document is AIML-compliant.
		self._numParseErrors = 0

		# TODO: select the proper validInfo table based on the version number.
		self._validInfo = self._validationInfo101

		# This stack of bools is used when parsing <li> elements inside
		# <condition> elements, to keep track of whether or not an
		# attribute-less "default" <li> element has been found yet.  Only
		# one default <li> is allowed in each <condition> element.  We need
		# a stack in order to correctly handle nested <condition> tags.
		self._foundDefaultLiStack = []

		# This stack of strings indicates what the current whitespace-handling
		# behavior should be.  Each string in the stack is either "default" or
		# "preserve".  When a new AIML element is encountered, a new string is
		# pushed onto the stack, based on the value of the element's "xml:space"
		# attribute (if absent, the top of the stack is pushed again).  When
		# ending an element, pop an object off the stack.
		self._whitespaceBehaviorStack = ["default"]
		
		self._elemStack = []
		self._locator = Locator()
		self.setDocumentLocator(self._locator)

	def getNumErrors(self):
		"Return the number of errors found while parsing the current document."
		return self._numParseErrors

	def setEncoding(self, encoding):
		"""Set the text encoding to use when encoding strings read from XML.

		Defaults to 'UTF-8'.

		"""
		self._encoding = encoding

	def _location(self):
		"Return a string describing the current location in the source file."
		line = self._locator.getLineNumber()
		column = self._locator.getColumnNumber()
		return "(line %d, column %d)" % (line, column)

	def _pushWhitespaceBehavior(self, attr):
		"""Push a new string onto the whitespaceBehaviorStack.

		The string's value is taken from the "xml:space" attribute, if it exists
		and has a legal value ("default" or "preserve").  Otherwise, the previous
		stack element is duplicated.

		"""
		assert len(self._whitespaceBehaviorStack) > 0, "Whitespace behavior stack should never be empty!"
		try:
			if attr["xml:space"] == "default" or attr["xml:space"] == "preserve":
				self._whitespaceBehaviorStack.append(attr["xml:space"])
			else:
				raise AimlParserError("Invalid value for xml:space attribute "+self._location())
		except KeyError:
			self._whitespaceBehaviorStack.append(self._whitespaceBehaviorStack[-1])

	def startElementNS(self, name, qname, attr):
		print("QNAME:", qname)
		print("NAME:", name)
		uri,elem = name
		if (elem == "bot"): print("name:", attr.getValueByQName("name"), "a'ite?")
		self.startElement(elem, attr)
		pass

	def startElement(self, name, attr):
		# Wrapper around _startElement, which catches errors in _startElement()
		# and keeps going.
#.........这里部分代码省略.........
开发者ID:cszipper,项目名称:PyAIML3,代码行数:101,代码来源:AimlParser.py


示例6: AimlHandler

class AimlHandler(ContentHandler):
    # The legal states of the AIML parser
    _STATE_OutsideAiml    = 0
    _STATE_InsideAiml     = 1
    _STATE_InsideCategory = 2
    _STATE_InsidePattern  = 3
    _STATE_AfterPattern   = 4
    _STATE_InsideThat     = 5
    _STATE_AfterThat      = 6
    _STATE_InsideTemplate = 7
    _STATE_AfterTemplate  = 8
    
    def __init__(self, encoding = "UTF-8"):
        self.categories = {}
        self._encoding = encoding
        self._state = self._STATE_OutsideAiml
        self._version = ""
        self._namespace = ""
        self._forwardCompatibleMode = False
        self._currentPattern = ""
        self._currentThat    = ""
        self._currentTopic   = ""
        self._insideTopic = False
        self._currentUnknown = "" # the name of the current unknown element

        # This is set to true when a parse error occurs in a category.
        self._skipCurrentCategory = False

        # Counts the number of parse errors in a particular AIML document.
        # query with getNumErrors().  If 0, the document is AIML-compliant.
        self._numParseErrors = 0

        # TODO: select the proper validInfo table based on the version number.
        self._validInfo = self._validationInfo101

        # This stack of bools is used when parsing <li> elements inside
        # <condition> elements, to keep track of whether or not an
        # attribute-less "default" <li> element has been found yet.  Only
        # one default <li> is allowed in each <condition> element.  We need
        # a stack in order to correctly handle nested <condition> tags.
        self._foundDefaultLiStack = []
        
        self._elemStack = []
        self._locator = Locator()
        self.setDocumentLocator(self._locator)

    def getNumErrors(self):
        "Returns the number of errors found while parsing the current document."
        return self._numParseErrors

    def setEncoding(self, encoding):
        """Sets the text encoding to use when encoding strings read from XML.
Defaults to 'UTF-8'."""
        self._encoding = encoding

    def _location(self):
        "Returns a string describing the current location in the source file."
        line = self._locator.getLineNumber()
        column = self._locator.getColumnNumber()
        return "(line %d, column %d)" % (line, column)

    def startElementNS(self, name, qname, attr):
        print "QNAME:", qname
        print "NAME:", name
        uri,elem = name
        if (elem == "bot"): print "name:", attr.getValueByQName("name"), "a'ite?"
        self.startElement(elem, attr)
        pass

    def startElement(self, name, attr):
        # Wrapper around _startElement, which catches errors in _startElement()
        # and keeps going.
        
        # If we're inside an unknown element, ignore everything until we're
        # out again.
        if self._currentUnknown != "":
            return
        # If we're skipping the current category, ignore everything until
        # it's finished.
        if self._skipCurrentCategory:
            return

        # process this start-element.
        try: self._startElement(name, attr)
        except AimlParserError, msg:
            # Print the error message
            sys.stderr.write("PARSE ERROR: %s\n" % msg)
            
            self._numParseErrors += 1 # increment error count
            # In case of a parse error, if we're inside a category, skip it.
            if self._state >= self._STATE_InsideCategory:
                self._skipCurrentCategory = True
开发者ID:atrinik,项目名称:atrinik,代码行数:92,代码来源:AimlParser.py


示例7: AimlHandler

class AimlHandler(ContentHandler):
    # The legal states of the AIML parser
    _STATE_OutsideAiml    = 0
    _STATE_InsideAiml     = 1
    _STATE_InsideCategory = 2
    _STATE_InsidePattern  = 3
    _STATE_AfterPattern   = 4
    _STATE_InsideThat     = 5
    _STATE_AfterThat      = 6
    _STATE_InsideTemplate = 7
    _STATE_AfterTemplate  = 8

    def __init__(self, encoding="UTF-8"):
        ContentHandler.__init__(self)
        self.categories = {}
        self._encoding = encoding
        self._state = self._STATE_OutsideAiml
        self._version = ""
        self._namespace = ""
        self._forwardCompatibleMode = False
        self._currentPattern = ""
        self._currentThat = ""
        self._currentTopic = ""
        self._insideTopic = False
        self._currentUnknown = "" # the name of the current unknown element
        self._skipCurrentCategory = False
        self._numParseErrors = 0
        self._validInfo = self._validationInfo101
        self._foundDefaultLiStack = []
        self._whitespaceBehaviorStack = ["default"]
        self._elemStack = []
        self._locator = Locator()
        self.setDocumentLocator(self._locator)

    def getNumErrors(self):
        """Return the number of errors found while parsing the current document."""
        return self._numParseErrors

    def setEncoding(self, encoding):
        """Set the text encoding to use when encoding strings read from XML.

        Defaults to 'UTF-8'.

        """
        self._encoding = encoding

    def _location(self):
        """Return a string describing the current location in the source file."""
        line = self._locator.getLineNumber()
        column = self._locator.getColumnNumber()
        return "(line %d, column %d)" % (line, column)

    def _pushWhitespaceBehavior(self, attr):
        """Push a new string onto the whitespaceBehaviorStack.

        The string's value is taken from the "xml:space" attribute, if it exists
        and has a legal value ("default" or "preserve").  Otherwise, the previous
        stack element is duplicated.

        """
        assert len(self._whitespaceBehaviorStack) > 0, "Whitespace behavior stack should never be empty!"
        try:
            if attr["xml:space"] == "default" or attr["xml:space"] == "preserve":
                self._whitespaceBehaviorStack.append(attr["xml:space"])
            else:
                raise AimlParserError, "Invalid value for xml:space attribute "+self._location()
        except KeyError:
            self._whitespaceBehaviorStack.append(self._whitespaceBehaviorStack[-1])

    def startElementNS(self, name, qname, attr):
        print "QNAME:", qname
        print "NAME:", name
        uri,elem = name
        if elem == "bot": print "name:", attr.getValueByQName("name"), "a'ite?"
        self.startElement(elem, attr)
        pass

    def startElement(self, name, attr):
        # Wrapper around _startElement, which catches errors in _startElement()
        # and keeps going.

        # If we're inside an unknown element, ignore everything until we're
        # out again.
        if self._currentUnknown != "":
            return
        # If we're skipping the current category, ignore everything until
        # it's finished.
        if self._skipCurrentCategory:
            return

        # process this start-element.
        try: self._startElement(name, attr)
        except AimlParserError, msg:
            # Print the error message
            sys.stderr.write("PARSE ERROR: %s\n" % msg)

            self._numParseErrors += 1 # increment error count
            # In case of a parse error, if we're inside a category, skip it.
            if self._state >= self._STATE_InsideCategory:
                self._skipCurrentCategory = True
开发者ID:alfonsodg,项目名称:sboty,代码行数:100,代码来源:AimlParser.py



注:本文中的xml.sax.xmlreader.Locator类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python xslt.XsltElement类代码示例发布时间:2022-05-26
下一篇:
Python xmlreader.InputSource类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap