本文整理汇总了Python中xml.sax.parseString方法的典型用法代码示例。如果您正苦于以下问题:Python sax.parseString方法的具体用法?Python sax.parseString怎么用?Python sax.parseString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xml.sax
的用法示例。
在下文中一共展示了sax.parseString方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from xml import sax [as 别名]
# 或者: from xml.sax import parseString [as 别名]
def main():
xmlString = "<note>\n<to>Tove</to>\n<from>Jani</from>\n<heading>Reminder</heading>\n<body>Don't forget me this weekend!</body>\n</note>"
# bad
xml.sax.parseString(xmlString, ExampleContentHandler())
xml.sax.parse('notaxmlfilethatexists.xml', ExampleContentHandler())
sax.parseString(xmlString, ExampleContentHandler())
sax.parse('notaxmlfilethatexists.xml', ExampleContentHandler)
# good
defusedxml.sax.parseString(xmlString, ExampleContentHandler())
# bad
xml.sax.make_parser()
sax.make_parser()
print('nothing')
# good
defusedxml.sax.make_parser()
示例2: parse
# 需要导入模块: from xml import sax [as 别名]
# 或者: from xml.sax import parseString [as 别名]
def parse(self, desc):
sax.parseString(desc, self)
示例3: fetch_index
# 需要导入模块: from xml import sax [as 别名]
# 或者: from xml.sax import parseString [as 别名]
def fetch_index():
"""Return an iterable of every project name on PyPI."""
r = requests.get('https://pypi.python.org/simple/')
sax_handler = PyPIIndexHandler()
sax.parseString(r.text, sax_handler)
return sax_handler.projects
示例4: __init__
# 需要导入模块: from xml import sax [as 别名]
# 或者: from xml.sax import parseString [as 别名]
def __init__(self, topologyFile):
""" Initialize with the topology file reference ready for reading """
handler = TopologyHandler()
sax.make_parser()
sax.parseString(topologyFile.read(), handler)
self.residues = handler.residues
示例5: __init__
# 需要导入模块: from xml import sax [as 别名]
# 或者: from xml.sax import parseString [as 别名]
def __init__(self):
"""
Create a new Definition Object
"""
self.map = {}
self.patches = {}
handler = DefinitionHandler()
sax.make_parser()
for path in [AAPATH, NAPATH]:
defpath = getDatFile(path)
if defpath == "":
raise ValueError, "%s not found!" % path
file = open(defpath)
sax.parseString(file.read(), handler)
file.close()
self.map.update(handler.map)
# Now handle patches
defpath = getDatFile(PATCHPATH)
if defpath == "":
raise ValueError, "%s not found!" % PATCHPATH
handler.map = {}
file = open(defpath)
sax.parseString(file.read(), handler)
file.close()
# Apply specific patches to the reference object, allowing users
# to specify protonation states in the PDB file
for patch in handler.patches:
if patch.newname != "":
# Find all residues matching applyto
resnames = self.map.keys()
for name in resnames:
regexp = re.compile(patch.applyto).match(name)
if not regexp: continue
newname = patch.newname.replace("*", name)
self.addPatch(patch, name, newname)
# Either way, make sure the main patch name is available
self.addPatch(patch, patch.applyto, patch.name)