本文整理匯總了Python中xml.sax.saxutils.prepare_input_source方法的典型用法代碼示例。如果您正苦於以下問題:Python saxutils.prepare_input_source方法的具體用法?Python saxutils.prepare_input_source怎麽用?Python saxutils.prepare_input_source使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類xml.sax.saxutils
的用法示例。
在下文中一共展示了saxutils.prepare_input_source方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: external_entity_ref
# 需要導入模塊: from xml.sax import saxutils [as 別名]
# 或者: from xml.sax.saxutils import prepare_input_source [as 別名]
def external_entity_ref(self, context, base, sysid, pubid):
if not self._external_ges:
return 1
source = self._ent_handler.resolveEntity(pubid, sysid)
source = saxutils.prepare_input_source(source,
self._source.getSystemId() or
"")
self._entity_stack.append((self._parser, self._source))
self._parser = self._parser.ExternalEntityParserCreate(context)
self._source = source
try:
xmlreader.IncrementalParser.parse(self, source)
except:
return 0 # FIXME: save error info here?
(self._parser, self._source) = self._entity_stack[-1]
del self._entity_stack[-1]
return 1
示例2: parse
# 需要導入模塊: from xml.sax import saxutils [as 別名]
# 或者: from xml.sax.saxutils import prepare_input_source [as 別名]
def parse(self, source):
"Parse an XML document from a URL or an InputSource."
source = saxutils.prepare_input_source(source)
self._source = source
self.reset()
self._cont_handler.setDocumentLocator(ExpatLocator(self))
xmlreader.IncrementalParser.parse(self, source)
示例3: parse
# 需要導入模塊: from xml.sax import saxutils [as 別名]
# 或者: from xml.sax.saxutils import prepare_input_source [as 別名]
def parse(self, source):
"Parse an XML document from a URL or an InputSource."
source = saxutils.prepare_input_source(source)
self._source = source
try:
self.reset()
self._cont_handler.setDocumentLocator(ExpatLocator(self))
xmlreader.IncrementalParser.parse(self, source)
except:
# bpo-30264: Close the source on error to not leak resources:
# xml.sax.parse() doesn't give access to the underlying parser
# to the caller
self._close_source()
raise