MCPcopy Create free account
hub / github.com/KhronosGroup/OpenCOLLADA / parse

Method parse

Externals/LibXML/python/drv_libxml2.py:133–302  ·  view source on GitHub ↗
(self, source)

Source from the content-addressed store, hash-verified

131 self.__errors = None
132
133 def parse(self, source):
134 self.__parsing = 1
135 try:
136 # prepare source and create reader
137 if type(source) in StringTypes:
138 reader = libxml2.newTextReaderFilename(source)
139 else:
140 source = saxutils.prepare_input_source(source)
141 input = libxml2.inputBuffer(source.getByteStream())
142 reader = input.newTextReader(source.getSystemId())
143 reader.SetErrorHandler(self._errorHandler,None)
144 # configure reader
145 if self.__extparams:
146 reader.SetParserProp(libxml2.PARSER_LOADDTD,1)
147 reader.SetParserProp(libxml2.PARSER_DEFAULTATTRS,1)
148 reader.SetParserProp(libxml2.PARSER_SUBST_ENTITIES,1)
149 reader.SetParserProp(libxml2.PARSER_VALIDATE,self.__validate)
150 else:
151 reader.SetParserProp(libxml2.PARSER_LOADDTD, 0)
152 # we reuse attribute maps (for a slight performance gain)
153 if self.__ns:
154 attributesNSImpl = xmlreader.AttributesNSImpl({},{})
155 else:
156 attributesImpl = xmlreader.AttributesImpl({})
157 # prefixes to pop (for endPrefixMapping)
158 prefixes = []
159 # start loop
160 self._cont_handler.startDocument()
161 while 1:
162 r = reader.Read()
163 # check for errors
164 if r == 1:
165 if not self.__errors is None:
166 self._reportErrors(0)
167 elif r == 0:
168 if not self.__errors is None:
169 self._reportErrors(0)
170 break # end of parse
171 else:
172 if not self.__errors is None:
173 self._reportErrors(1)
174 else:
175 self._err_handler.fatalError(\
176 SAXException("Read failed (no details available)"))
177 break # fatal parse error
178 # get node type
179 nodeType = reader.NodeType()
180 # Element
181 if nodeType == 1:
182 if self.__ns:
183 eltName = (_d(reader.NamespaceUri()),\
184 _d(reader.LocalName()))
185 eltQName = _d(reader.Name())
186 attributesNSImpl._attrs = attrs = {}
187 attributesNSImpl._qnames = qnames = {}
188 newPrefixes = []
189 while reader.MoveToNextAttribute():
190 qname = _d(reader.Name())

Callers

nothing calls this directly

Calls 15

_reportErrorsMethod · 0.95
_dFunction · 0.85
getSystemIdMethod · 0.80
SetErrorHandlerMethod · 0.80
NameMethod · 0.80
ValueMethod · 0.80
ignorableWhitespaceMethod · 0.80
processingInstructionMethod · 0.80
commentMethod · 0.80
startDocumentMethod · 0.45
fatalErrorMethod · 0.45
startElementMethod · 0.45

Tested by

no test coverage detected