本文整理汇总了Python中Ft.Xml.Domlette.NonvalidatingReader.parseString方法的典型用法代码示例。如果您正苦于以下问题:Python NonvalidatingReader.parseString方法的具体用法?Python NonvalidatingReader.parseString怎么用?Python NonvalidatingReader.parseString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Ft.Xml.Domlette.NonvalidatingReader
的用法示例。
在下文中一共展示了NonvalidatingReader.parseString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setConfig
# 需要导入模块: from Ft.Xml.Domlette import NonvalidatingReader [as 别名]
# 或者: from Ft.Xml.Domlette.NonvalidatingReader import parseString [as 别名]
def setConfig(self, text):
"""
sets new original configuration xml in this instances, recreates dynamic configuration
"""
logger().debug("VermontInstance.setConfig()")
self.__cfgModified = True
self.__cfgText = text
if self.__parseXml:
self.__cfgXml = NonvalidatingReader.parseString(text)
self.__dynCfgModified = True
self.__dynCfgText = self.cfgText
if self.__parseXml:
self.__dynCfgXml = NonvalidatingReader.parseString(self.__cfgText)
示例2: __init__
# 需要导入模块: from Ft.Xml.Domlette import NonvalidatingReader [as 别名]
# 或者: from Ft.Xml.Domlette.NonvalidatingReader import parseString [as 别名]
def __init__(self, uri=None, xmlString=None):
global doc
if uri is not None:
doc = NonvalidatingReader.parseUri(uri)
elif xmlString is not None:
uri = 'file:bogusFile.txt' # Required by Domlette or it issues a warning.
doc = NonvalidatingReader.parseString(xmlString, uri)
示例3: _parseResults
# 需要导入模块: from Ft.Xml.Domlette import NonvalidatingReader [as 别名]
# 或者: from Ft.Xml.Domlette.NonvalidatingReader import parseString [as 别名]
def _parseResults(self):
if self.resultDOM is not None:
from Ft.Xml.Domlette import NonvalidatingReader
self.resultDOM = NonvalidatingReader.parseString(self.result)
self.askAnswer=self.resultDOM.xpath(
'string(/sparql:sparql/sparql:boolean)',
explicitNss=sparqlNsBindings)
示例4: xml
# 需要导入模块: from Ft.Xml.Domlette import NonvalidatingReader [as 别名]
# 或者: from Ft.Xml.Domlette.NonvalidatingReader import parseString [as 别名]
def xml(xmlin, forced=False):
""" Parse some XML.
Argument xmlin can be a string, the filename of some XML;
or an open file, from which xml is read.
forced to True to skip caching check
The return value is the parsed XML as DOM nodes.
"""
filename = None
# A string argument is a file name.
if isinstance(xmlin, types.StringTypes):
filename = _findFile(xmlin)
if not filename:
raise "Couldn't find XML to parse: %s" % xmlin
if filename:
if _xmlcache.has_key(filename) and not forced:
return _xmlcache[filename]
xmlin = open(filename)
xmldata = xmlin.read()
if bDomlette:
doc = NonvalidatingReader.parseString(xmldata, filename or ' ')
else:
doc = PyExpat.Reader().fromString(xmldata)
parsedxml = HandyXmlWrapper(doc.documentElement)
if filename:
_xmlcache[filename] = parsedxml
return parsedxml
示例5: show_modulegraph
# 需要导入模块: from Ft.Xml.Domlette import NonvalidatingReader [as 别名]
# 或者: from Ft.Xml.Domlette.NonvalidatingReader import parseString [as 别名]
def show_modulegraph(req, host):
try:
statxml = remotevm.getSensorData(host)
except:
return show_error(req, "failed to contact manager", traceback.format_exc())
doc = NonvalidatingReader.parseString(statxml)
g = "digraph G {\n"
g += "\tnode[fontsize=8,shape=box,fontname=Helvetica,height=.3]\n"
g += "\trankdir=LR;\n"
for m in doc.xpath('/vermont/sensorData/sensor[@type=\'module\']'):
mid = m.xpath('@id')[0].nodeValue
mname = "%s(%s)" % (m.xpath('@name')[0].nodeValue, mid)
g += "\t%s [label=\"%s\"];\n" % (mid, mname)
for n in m.xpath('next'):
nid = n.childNodes[0].nodeValue
g += "\t%s -> %s;\n" % (mid, nid)
g += "}\n"
fn = "/tmp/graph-%s.dot.tmp" % host
gfn = "/tmp/graph-%s.png.tmp" % host
fh = open(fn, "w")
fh.write(g)
fh.close()
err = os.system("cat %s | dot -Tpng -o %s" % (fn, gfn))
if err != 0:
raise Exception("failed to execute dot (error code %d)" % err)
fh = open(gfn, "r")
req.content_type = "image/png"
req.write(fh.read())
fh.close()
示例6: test08WhitespaceNormalized
# 需要导入模块: from Ft.Xml.Domlette import NonvalidatingReader [as 别名]
# 或者: from Ft.Xml.Domlette.NonvalidatingReader import parseString [as 别名]
def test08WhitespaceNormalized(self):
# ...outside the document element and within start and end tags
dat = \
''' 1 2
3'''
xml = \
'''<?xml version="1.0" encoding="UTF-8"?>
<doc xmlns="http://example.com/default">
<a
a2="2" a1="1"
>%s</a>
</doc>
''' % dat
ftDoc = NonvalidatingReader.parseString(xml)
f = StringIO()
CanonicalPrint(ftDoc, f)
c14n = f.getvalue()
self.failUnless('a1="1" a2="2"' in c14n,
"Expecting single space between attributes")
self.failUnless(dat in c14n,
"Expecting element content to be preserved")
sub = c14n[c14n.find('<a'):c14n.find('>')]
self.failIf('\n' in sub,
"Expecting removal of line breaks for 'a' element")
示例7: GetNumberOfNoisyStripsInDB
# 需要导入模块: from Ft.Xml.Domlette import NonvalidatingReader [as 别名]
# 或者: from Ft.Xml.Domlette.NonvalidatingReader import parseString [as 别名]
def GetNumberOfNoisyStripsInDB(array, server, schema, dbname, folder, tag, channels):
Array_numNoisyStrips = []
if (array[0] != -999):
for i in range(len(array)):
runNumber=array[i]
iovSince=ConvertedRunNumber(runNumber)
iovUntil=ConvertedRunNumber(runNumber+1)-1
derived_string=channelValueQuery(server, schema, dbname, folder, iovSince, iovUntil, tag, channels)
derived=NonvalidatingReader.parseString(derived_string,uri="dummy")
numNoisyModules=derived.xpath(u'count(//channel)')
if numNoisyModules !=0.0:
allDefectStripsList=(derived.xpath(u"//channel/value[@name='DefectList']"))
numNoisyStrips=0
numNoisyStripsAdds=0
for strips in allDefectStripsList:
words=strips.firstChild.data.split()
for j in range(len(words)):
jk=words[j]
if jk.find("-")>=0:
sep=jk.replace ( '-', ' ' )
sep1=sep.split()
numNoisyStripsAdds=numNoisyStripsAdds+int(sep1[1])-int(sep1[0])
numNoisyStrips=numNoisyStrips+len(strips.firstChild.data.split())
Array_numNoisyStrips.append(numNoisyStrips + numNoisyStripsAdds)
else:
Array_numNoisyStrips.append(-999)
return Array_numNoisyStrips
示例8: test05CDATASectionsReplaced
# 需要导入模块: from Ft.Xml.Domlette import NonvalidatingReader [as 别名]
# 或者: from Ft.Xml.Domlette.NonvalidatingReader import parseString [as 别名]
def test05CDATASectionsReplaced(self):
xml = \
"""<?xml version="1.0" encoding="UTF-8"?>
<script>
<![CDATA[
function matchwo(a,b)
{
if (a < b && a > 0) then
{
print("Match");
return 1;
}
else
{
print('Different');
return 0;
}
}
]]>
</script>
"""
ftDoc = NonvalidatingReader.parseString(xml)
f = StringIO()
CanonicalPrint(ftDoc, f)
c14n = f.getvalue()
self.failIf('CDATA' in c14n, "CDATA not removed, c14n = %s" % c14n)
self.failUnless('<' in c14n,
"Less than not converted, c14n = %s" % c14n)
self.failUnless('>' in c14n,
"Greater than not converted, c14n = %s" % c14n)
self.failUnless('&' in c14n,
"Ampersand not converted, c14n = %s" % c14n)
示例9: test07EmptyElemsConvertedStartEndPairs
# 需要导入模块: from Ft.Xml.Domlette import NonvalidatingReader [as 别名]
# 或者: from Ft.Xml.Domlette.NonvalidatingReader import parseString [as 别名]
def test07EmptyElemsConvertedStartEndPairs(self):
xml = '<?xml version="1.0" encoding="UTF-8"?><a/>'
ftDoc = NonvalidatingReader.parseString(xml)
f = StringIO()
CanonicalPrint(ftDoc, f)
c14n = f.getvalue()
self.failUnless(c14n == '<a></a>', "C14N = %s" % c14n)
示例10: _workerThread
# 需要导入模块: from Ft.Xml.Domlette import NonvalidatingReader [as 别名]
# 或者: from Ft.Xml.Domlette.NonvalidatingReader import parseString [as 别名]
def _workerThread(self):
while True:
logger().info("VermontController._workerThread: collecting monitoring data now")
self.rInterface.retrieveStatus()
if self.rInterface.running:
# try to read in statistics data several times ...
xml = None
trycount = 0
while xml is None:
#if trycount>=100:
#raise RuntimeError("Failed to read sensor data!")
try:
logger().debug("trying to read sensor data ...")
self.rInterface.retrieveSensorData()
xml = NonvalidatingReader.parseString(self.rInterface.sensorDataText)
except:
logger().error(traceback.format_exc())
logger().info("failed to read sensor data xml, trying again ...")
time.sleep(1)
trycount += 1
self.vMonitor.collect_data(xml)
else:
logger().info("VermontController._workerThread: skipping stat recording, as instance is not running")
time.sleep(self.moninterval)
示例11: test02NormalizeLineBreaks
# 需要导入模块: from Ft.Xml.Domlette import NonvalidatingReader [as 别名]
# 或者: from Ft.Xml.Domlette.NonvalidatingReader import parseString [as 别名]
def test02NormalizeLineBreaks(self):
xml = '<?xml version="1.0" encoding="UTF-8"?>\r\n<a/>\r\n'
ftDoc = NonvalidatingReader.parseString(xml)
f = StringIO()
CanonicalPrint(ftDoc, f)
c14n = f.getvalue()
self.failIf('\r' in c14n, "Carriage return \r char found in c14n")
示例12: test01UTF8DocEncoding
# 需要导入模块: from Ft.Xml.Domlette import NonvalidatingReader [as 别名]
# 或者: from Ft.Xml.Domlette.NonvalidatingReader import parseString [as 别名]
def test01UTF8DocEncoding(self):
# http://www.w3.org/TR/xml-c14n#Example-UTF8
xml = '<?xml version="1.0" encoding="ISO-8859-1"?><doc>©</doc>'
ftDoc = NonvalidatingReader.parseString(xml)
f = StringIO()
CanonicalPrint(ftDoc, f)
c14n = f.getvalue()
#self.assertEqual(c14n, '<doc>#xC2#xA9</doc>')
self.assertEqual(c14n, '<doc>\xC2\xA9</doc>')
示例13: Test
# 需要导入模块: from Ft.Xml.Domlette import NonvalidatingReader [as 别名]
# 或者: from Ft.Xml.Domlette.NonvalidatingReader import parseString [as 别名]
def Test(tester):
tester.startGroup('Idan Elfassy finds well-formedness bug in printer')
doc = NonvalidatingReader.parseString(SRC1, __name__)
tester.startTest('Ft.Xml.Domlette.Print')
stream = cStringIO.StringIO()
Print(doc, stream=stream)
result = stream.getvalue()
tester.compare(EXPECTED1_PRINTED, result)
tester.testDone()
tester.groupDone()
return
示例14: test10AttrValDelimitersSet2DblQuotes
# 需要导入模块: from Ft.Xml.Domlette import NonvalidatingReader [as 别名]
# 或者: from Ft.Xml.Domlette.NonvalidatingReader import parseString [as 别名]
def test10AttrValDelimitersSet2DblQuotes(self):
xml = \
"""<?xml version="1.0" encoding="UTF-8"?>
<b y:a1='1' a3='"3"'
xmlns:y='http://example.com/y' y:a2='2'/>
"""
ftDoc = NonvalidatingReader.parseString(xml)
f = StringIO()
CanonicalPrint(ftDoc, f)
c14n = f.getvalue()
self.failIf("'" in c14n,
"Expecting removal of apostrophes C14N = %s" % c14n)
示例15: _walkhtml
# 需要导入模块: from Ft.Xml.Domlette import NonvalidatingReader [as 别名]
# 或者: from Ft.Xml.Domlette.NonvalidatingReader import parseString [as 别名]
def _walkhtml(self, ip):
'''Walks HTML input
Arguments:
ip -- HTML input path'''
# Tidy the HTML and Feed into DOM tree
try: html = nr.parseString(tidy(ip, output_xhtml=1)[2], 'file://file')
# Don't embed if parsing errors
except self._rex: return None
# Extract only first child for cleanliness
html = html.firstChild
# Avoids issue with HTML docs made up of comments
try: self._attdel(html, 'xmlns')
except AttributeError: pass
# Return HTML
return html