本文整理汇总了Python中Ft.Xml.Domlette.NonvalidatingReader.parseStream方法的典型用法代码示例。如果您正苦于以下问题:Python NonvalidatingReader.parseStream方法的具体用法?Python NonvalidatingReader.parseStream怎么用?Python NonvalidatingReader.parseStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Ft.Xml.Domlette.NonvalidatingReader
的用法示例。
在下文中一共展示了NonvalidatingReader.parseStream方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from Ft.Xml.Domlette import NonvalidatingReader [as 别名]
# 或者: from Ft.Xml.Domlette.NonvalidatingReader import parseStream [as 别名]
def main(argv=[__name__]):
#Ideas borrowed from
# http://www.artima.com/forums/flat.jsp?forum=106&thread=4829
if argv is None:
argv = sys.argv
try:
try:
optparser = command_line(argv)
dtll_fname = ARGS[1]
except KeyboardInterrupt:
pass
except:
raise Usage(optparser.format_help())
enc, dec, inwrap, outwrap = codecs.lookup('utf-8')
output_stem = OPTIONS.dt_modname_stem
if not output_stem:
output_stem = os.path.splitext(dtll_fname)[0] + '-datatypes'
if dtll_fname == '-':
dtllf = sys.stdin
else:
dtllf = open(dtll_fname, 'r')
dtll_doc = NonvalidatingReader.parseStream(dtllf, 'http://example.com')
run(dtll_doc, output_stem, OPTIONS.test_ready)
except Usage, err:
print >>sys.stderr, err.msg
return 2
示例2: parseFile
# 需要导入模块: from Ft.Xml.Domlette import NonvalidatingReader [as 别名]
# 或者: from Ft.Xml.Domlette.NonvalidatingReader import parseStream [as 别名]
def parseFile(file):
"""File can be an open handle or filesystem path"""
from Ft.Xml.Domlette import NonvalidatingReader
if isinstance(file, basestring):
dom = NonvalidatingReader.parseUri("file:%s" % self._file)
else:
dom = NonvalidatingReader.parseStream(file, **kwargs)
return McmLogFile(dom)
示例3: _convertXML
# 需要导入模块: from Ft.Xml.Domlette import NonvalidatingReader [as 别名]
# 或者: from Ft.Xml.Domlette.NonvalidatingReader import parseStream [as 别名]
def _convertXML(self):
"""
Convert an XML result into a Python dom tree. This method can be overwritten in a
subclass for a different conversion method.
:return: converted result
:rtype: 4Suite DOMlette instance (http://infinitesque.net/projects/4Suite/docs/CoreManual.html#domlette_API)
"""
try:
from Ft.Xml import InputSource
from Ft.Xml.Domlette import NonvalidatingReader
except ImportError:
raise Exception("4Suite-XML needs to be installed (http://pypi.python.org/pypi/4Suite-XML/1.0.2)")
return NonvalidatingReader.parseStream(self.response, MEANINGLESS_URI)
示例4: contexts
# 需要导入模块: from Ft.Xml.Domlette import NonvalidatingReader [as 别名]
# 或者: from Ft.Xml.Domlette.NonvalidatingReader import parseStream [as 别名]
def contexts(self, triple=None):
"""
iterates over results to SELECT ?NAME { GRAPH ?NAME { ?s ?p ?o } }
returning instances of this store with the SPARQL wrapper
object updated via addNamedGraph(?NAME)
This causes a named-graph-uri key / value pair to be sent over the protocol
"""
raise NotImplementedError(".contexts(..) not supported")
self.setQuery("SELECT ?NAME { GRAPH ?NAME { ?s ?p ?o } }")
doc = NonvalidatingReader.parseStream(self.query().convert)
for result in doc.xpath('/sparql:sparql/sparql:results/sparql:result',
explicitNss=sparqlNsBindings):
statmentTerms = {}
for binding in result.xpath('sparql:binding',
explicitNss=sparqlNsBindings):
term = CastToTerm(binding.xpath('*')[0])
newStore = SPARQLStore(self.baseURI)
newStore.addNamedGraph(term)
yield Graph(self,term)
示例5: triples_choices
# 需要导入模块: from Ft.Xml.Domlette import NonvalidatingReader [as 别名]
# 或者: from Ft.Xml.Domlette.NonvalidatingReader import parseStream [as 别名]
else:
selectVars.append(predVar)
if obj is not None:
termsSlots[objVar] = obj
else:
selectVars.append(objVar)
query ="SELECT %s WHERE { %s %s %s }"%(
' '.join([term.n3() for term in selectVars]),
termsSlots.get(subjVar, subjVar).n3(),
termsSlots.get(predVar, predVar).n3(),
termsSlots.get(objVar , objVar ).n3()
)
self.setQuery(query)
doc = NonvalidatingReader.parseStream(self.query().response)
for rt,vars in TraverseSPARQLResultDOM(doc,asDictionary=True):
yield (rt.get(subjVar,subject),
rt.get(predVar,predicate),
rt.get(objVar,obj)),None
def triples_choices(self, (subject, predicate, object_),context=None):
"""
A variant of triples that can take a list of terms instead of a single
term in any slot. Stores can implement this to optimize the response time
from the import default 'fallback' implementation, which will iterate
over each term in the list and dispatch to tripless
"""
raise NotImplementedError('Triples choices currently not supported')
def __len__(self, context=None):