本文整理汇总了Python中Ft.Xml.Domlette.NonvalidatingReader类的典型用法代码示例。如果您正苦于以下问题:Python NonvalidatingReader类的具体用法?Python NonvalidatingReader怎么用?Python NonvalidatingReader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NonvalidatingReader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: read_file
def read_file(my, file_path, cache=True):
#my.reader = PyExpat.Reader()
#my.doc = my.reader.fromUri(file_path)
# the xml library does not like windows style separators
try:
file_path = file_path.replace("\\", "/")
if not cache:
my.doc = NonvalidatingReader.parseUri("file://%s" % file_path, my.uri)
else:
cur_mtime = os.path.getmtime(file_path)
cache_mtime = my.XML_FILE_MTIME.get(file_path)
if cur_mtime == cache_mtime:
my.doc = my.XML_FILE_CACHE.get(file_path)
else:
my.doc = NonvalidatingReader.parseUri("file://%s" % file_path, my.uri)
my.cache_xml(file_path, my.doc, cur_mtime)
except Exception, e:
#print "Error in xml file: ", file_path
raise XmlException(e)
示例2: __init__
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: parseFile
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)
示例4: setConfig
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)
示例5: test08WhitespaceNormalized
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")
示例6: test07EmptyElemsConvertedStartEndPairs
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)
示例7: test05CDATASectionsReplaced
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)
示例8: test02NormalizeLineBreaks
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")
示例9: _parseResults
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)
示例10: xml
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
示例11: show_modulegraph
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()
示例12: __init__
def __init__(self,iptFile,ctFile,truncTime):
# Read epidemic and truncate to truncTime
self.infectives = []
self.labels = []
epiFile = open(iptFile,'r')
for line in epiFile:
toks = line.split()
label = atoi(toks[0])
I = atof(toks[1])
N = atof(toks[2])
R = atof(toks[3])
if N <= truncTime: # Take individuals who have been notified by truncTime
if R > truncTime: # If R > truncTime, set R = truncTime
R = truncTime
self.infectives.append(Infective(label,I,N,R))
self.labels.append(label)
epiFile.close()
# Read in XML
conFile = Uri.OsPathToUri(ctFile)
xmlSrc = DefaultFactory.fromUri(conFile,stripElements=[(EMPTY_NAMESPACE,'*',1)])
self.doc = NonvalidatingReader.parse(xmlSrc)
# Remove from the contact DOM any contact info
# for individuals that are not present in labels
self.labels = set(self.labels)
for contact in self.doc.documentElement.xpath(u'tc:contact',explicitNss={u'tc':u'tracedcontacts'}):
contactLabel = atoi(contact.getAttributeNS(None,u'id'))
if contactLabel not in self.labels:
self.doc.documentElement.removeChild(contact)
示例13: _workerThread
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)
示例14: GetNumberOfNoisyStripsInDB
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
示例15: main
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