我们从Python开源项目中,提取了以下22个代码示例,用于说明如何使用xml.sax.xmlreader.Locator()。
def reset(self): if self._namespaces: self._parser = expat.ParserCreate(self._source.getEncoding(), " ", intern=self._interning) self._parser.namespace_prefixes = 1 self._parser.StartElementHandler = self.start_element_ns self._parser.EndElementHandler = self.end_element_ns else: self._parser = expat.ParserCreate(self._source.getEncoding(), intern = self._interning) self._parser.StartElementHandler = self.start_element self._parser.EndElementHandler = self.end_element self._reset_cont_handler() self._parser.UnparsedEntityDeclHandler = self.unparsed_entity_decl self._parser.NotationDeclHandler = self.notation_decl self._parser.StartNamespaceDeclHandler = self.start_namespace_decl self._parser.EndNamespaceDeclHandler = self.end_namespace_decl self._decl_handler_prop = None if self._lex_handler_prop: self._reset_lex_handler_prop() # self._parser.DefaultHandler = # self._parser.DefaultHandlerExpand = # self._parser.NotStandaloneHandler = self._parser.ExternalEntityRefHandler = self.external_entity_ref try: self._parser.SkippedEntityHandler = self.skipped_entity_handler except AttributeError: # This pyexpat does not support SkippedEntity pass self._parser.SetParamEntityParsing( expat.XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE) self._parsing = 0 self._entity_stack = [] # Locator methods
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 __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 __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._currentPatternLocation = "" 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)