本文整理汇总了Python中lxml.objectify.fromstring方法的典型用法代码示例。如果您正苦于以下问题:Python objectify.fromstring方法的具体用法?Python objectify.fromstring怎么用?Python objectify.fromstring使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lxml.objectify
的用法示例。
在下文中一共展示了objectify.fromstring方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: xsd
# 需要导入模块: from lxml import objectify [as 别名]
# 或者: from lxml.objectify import fromstring [as 别名]
def xsd(self, xsd, filename):
"""
Look at schema, validation, conform, structure, content, etc...
Code for 1.7.1
"""
# syntax check against XSD for file format
schema = etree.XMLSchema(file=xsd)
parser = objectify.makeparser(schema = schema)
tree = etree.parse(filename)
root = tree.getroot()
database = objectify.fromstring(etree.tostring(root, encoding="UTF-8"), parser)
LOG.info(_('Matches XSD schema.'))
#dump = objectify.dump(database)
#print(dump)
示例2: sign_http_post
# 需要导入模块: from lxml import objectify [as 别名]
# 或者: from lxml.objectify import fromstring [as 别名]
def sign_http_post(xmlstr, key, cert, message=False, assertion=True):
logger.debug('http-post signing')
signer = XMLSigner(
signature_algorithm='rsa-sha256',
digest_algorithm='sha256',
c14n_algorithm='http://www.w3.org/2001/10/xml-exc-c14n#',
)
root = fromstring(xmlstr)
if assertion:
logger.debug('signing assertion')
assertions = root.findall('{%s}Assertion' % SAML)
for assertion in assertions:
issuer = assertion.find('{%s}Issuer' % SAML)
issuer.addnext(fromstring(
'<ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#" Id="placeholder"></ds:Signature>'))
root = signer.sign(root, reference_uri=assertion.attrib['ID'], key=key, cert=cert)
if message:
issuer = root.find('{%s}Issuer' % SAML)
issuer.addnext(fromstring(
'<ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#" Id="placeholder"></ds:Signature>'))
root = signer.sign(root, key=key, cert=cert)
return tostring(root, pretty_print=False)
示例3: test_deserialization
# 需要导入模块: from lxml import objectify [as 别名]
# 或者: from lxml.objectify import fromstring [as 别名]
def test_deserialization(self):
xml = """\
<root>
<child1>some data</child1>
<child2 AnAttribute="more data"></child2>
<SpecialChild3>
<Item AnotherAttribute="foo"></Item>
<Item EvenAnotherAttribute="bar"></Item>
</SpecialChild3>
</root>"""
xml_doc = objectify.fromstring(xml)
saml_tree = SAMLTree(xml_doc, multi_occur_tags={'Item'})
self.assertEqual(saml_tree.child1.text, 'some data')
self.assertEqual(saml_tree.child1.tag, 'child1')
self.assertEqual(saml_tree.child2.an_attribute, 'more data')
self.assertEqual(len(saml_tree.special_child3.item), 2)
self.assertEqual(saml_tree.special_child3.tag, 'special_child3')
self.assertEqual(saml_tree.special_child3.item[
0].another_attribute, 'foo')
self.assertEqual(saml_tree.special_child3.item[
1].even_another_attribute, 'bar')
示例4: test_ovf_parameters
# 需要导入模块: from lxml import objectify [as 别名]
# 或者: from lxml.objectify import fromstring [as 别名]
def test_ovf_parameters(self):
args = {
'vm_name': 'jumper',
'root_uuid': 'uuid',
'vm_description': 'Leap 15 image',
'disk_image_capacity': 21,
}
ovf_file = self.ovf_template.get_template().substitute(args)
ovf = objectify.fromstring(ovf_file)
for (attr, value) in ovf.DiskSection.Disk.items():
if 'capacity' in attr:
assert value == str(args['disk_image_capacity'])
vm_name_attr, vm_name_value = ovf.VirtualSystem.items()[0]
assert 'id' in vm_name_attr and vm_name_value == args['vm_name']
cimos_id_attr, cimos_id_value = \
ovf.VirtualSystem.OperatingSystemSection.items()[0]
assert 'id' in cimos_id_attr and int(cimos_id_value) == 101
assert ovf.VirtualSystem.OperatingSystemSection.Description \
== args['vm_description']
示例5: engine_activity
# 需要导入模块: from lxml import objectify [as 别名]
# 或者: from lxml.objectify import fromstring [as 别名]
def engine_activity(self, engineid):
response = request(self, "EngineActivity", {"engine-id" : engineid})
activity = objectify.fromstring(etree.tostring(response))
ss = activity.ScanSummary[0]
vulns = []
for vuln in ss.vulnerabilities:
vulns.append(Vulnerability(**dict(vuln.items())))
summaryItems = dict(ss.items())
summaryItems['siteid'] = summaryItems['site-id']
del summaryItems['site-id']
summaryItems['scanid'] = summaryItems['scan-id']
del summaryItems['scan-id']
summaryItems['engineid'] = summaryItems['engine-id']
del summaryItems['engine-id']
summaryItems['tasks'] = Tasks(**dict(ss.tasks.items()))
summaryItems['nodes'] = Nodes(**dict(ss.nodes.items()))
summaryItems['vulns'] = vulns
return ScanSummary(**summaryItems)
示例6: scan_activity
# 需要导入模块: from lxml import objectify [as 别名]
# 或者: from lxml.objectify import fromstring [as 别名]
def scan_activity(self):
response = request(self, "ScanActivity")
scans = objectify.fromstring(etree.tostring(response))
scanSummaryList = []
for scan in scans.ScanSummary:
vulns = []
for vuln in scan.vulnerabilities:
vulns.append(Vulnerability(**dict(vuln.items())))
summaryItems = dict(scan.items())
summaryItems['siteid'] = summaryItems['site-id']
del summaryItems['site-id']
summaryItems['scanid'] = summaryItems['scan-id']
del summaryItems['scan-id']
summaryItems['engineid'] = summaryItems['engine-id']
del summaryItems['engine-id']
summaryItems['tasks'] = Tasks(**dict(scan.tasks.items()))
summaryItems['nodes'] = Nodes(**dict(scan.nodes.items()))
summaryItems['vulns'] = vulns
scanSummaryList.append(ScanSummary(**summaryItems))
return scanSummaryList
示例7: scan_statistics
# 需要导入模块: from lxml import objectify [as 别名]
# 或者: from lxml.objectify import fromstring [as 别名]
def scan_statistics(self, scanid):
response = request(self, "ScanStatistics", {'scan-id' : scanid})
ss = objectify.fromstring(etree.tostring(response)).ScanSummary
vulns = []
for vuln in ss.vulnerabilities:
vulns.append(Vulnerability(**dict(vuln.items())))
summaryItems = dict(ss.items())
summaryItems['siteid'] = summaryItems['site-id']
del summaryItems['site-id']
summaryItems['scanid'] = summaryItems['scan-id']
del summaryItems['scan-id']
summaryItems['engineid'] = summaryItems['engine-id']
del summaryItems['engine-id']
summaryItems['tasks'] = Tasks(**dict(ss.tasks.items()))
summaryItems['nodes'] = Nodes(**dict(ss.nodes.items()))
summaryItems['vulns'] = vulns
return ScanSummary(**summaryItems)
示例8: site_scan_history
# 需要导入模块: from lxml import objectify [as 别名]
# 或者: from lxml.objectify import fromstring [as 别名]
def site_scan_history(self, siteid):
response = request(self, "SiteScanHistory", {"site-id" : siteid})
history = objectify.fromstring(etree.tostring(response))
scans = []
for scan in history.ScanSummary:
vulns = []
for vuln in scan.vulnerabilities:
vulns.append(Vulnerability(**dict(vuln.items())))
summaryItems = dict(scan.items())
summaryItems['siteid'] = summaryItems['site-id']
del summaryItems['site-id']
summaryItems['scanid'] = summaryItems['scan-id']
del summaryItems['scan-id']
summaryItems['engineid'] = summaryItems['engine-id']
del summaryItems['engine-id']
summaryItems['tasks'] = Tasks(**dict(scan.tasks.items()))
summaryItems['nodes'] = Nodes(**dict(scan.nodes.items()))
summaryItems['vulns'] = vulns
scans.append(ScanSummary(**summaryItems))
return scans
示例9: __init__
# 需要导入模块: from lxml import objectify [as 别名]
# 或者: from lxml.objectify import fromstring [as 别名]
def __init__(self, data, encoding="utf-8"):
""".. rubric:: Constructor
:param data: an XML document format
:param fixing_unicode: use only with HGNC service to fix issue with the
XML returned by that particular service. No need to use otherwise.
See :class:`~bioservices.hgnc.HGNC` documentation for details.
:param encoding: default is utf-8 used. Used to fix the HGNC XML only.
The data parameter must be a string containing the XML document. If you
have an URL instead, use :class:`readXML`
"""
#if fixing_unicode:
# x = unicodefix.FixingUnicode(data, verbose=False, encoding=encoding)
# self.data = x.fixed_string.encode("utf-8")
#else:
self.data = data[:]
try:
self.root = ET.fromstring(self.data)
except:
self.root = self.data[:]
self._soup = None
self.prettify = self.soup.prettify
self.findAll = self.soup.findAll
示例10: read_xml_sourcefile
# 需要导入模块: from lxml import objectify [as 别名]
# 或者: from lxml.objectify import fromstring [as 别名]
def read_xml_sourcefile(file_name):
all_text = open(file_name).read()
return objectify.fromstring(all_text)
示例11: parse_response
# 需要导入模块: from lxml import objectify [as 别名]
# 或者: from lxml.objectify import fromstring [as 别名]
def parse_response(resp):
resp.raise_for_status()
xml = objectify.fromstring(resp.content)
t = xml.get("type")
if t == "auth-request":
return parse_auth_request_response(xml)
elif t == "complete":
return parse_auth_complete_response(xml)
示例12: parse_xml_response
# 需要导入模块: from lxml import objectify [as 别名]
# 或者: from lxml.objectify import fromstring [as 别名]
def parse_xml_response(self, text):
try:
self.xmlTree = objectify.fromstring(text)
module = __import__('api_classes')
# print self.xmlTree.tag
class_ = getattr(module, self.xmlTree.tag)
instance = class_(self.json, self.xmlTree, text)
setattr(self, self.xmlTree.tag, instance)
return instance
except:
raise
示例13: compare
# 需要导入模块: from lxml import objectify [as 别名]
# 或者: from lxml.objectify import fromstring [as 别名]
def compare(self, xml_str, encoding="utf-8"):
"""Compare with xml string input."""
# fromstring complains when we have UTF declaration like
# `<?xml version="1.0" encoding="utf-8" ?>`, so we use bytes instead
# https://stackoverflow.com/a/38244227
xml_bytes = bytes(bytearray(xml_str, encoding=encoding))
xml_obj = objectify.fromstring(xml_bytes)
self._compare_obj(xml_obj)
示例14: main
# 需要导入模块: from lxml import objectify [as 别名]
# 或者: from lxml.objectify import fromstring [as 别名]
def main():
data = sys.stdin.readlines()
payload = data[0]
payload_dict = json.loads(payload)
if "response" in payload_dict and "body" in payload_dict["response"]:
body = payload_dict["response"]["body"]
try:
root = objectify.fromstring(str(body))
ns = "{http://ws.cdyne.com/}"
logging.debug("transforming")
ipe = ns + "ResolveIPResponse"
ipt = ns + "ResolveIPResult"
root.Body[ipe][ipt].City = "New York"
objectify.deannotate(root.Body[ipe][ipt].City)
etree.cleanup_namespaces(root.Body[ipe][ipt].City)
payload_dict["response"]["body"] = etree.tostring(root)
logging.debug(etree.tostring(root))
except Exception:
pass
print(json.dumps(payload_dict))
示例15: get_was_scan_count
# 需要导入模块: from lxml import objectify [as 别名]
# 或者: from lxml.objectify import fromstring [as 别名]
def get_was_scan_count(self, status):
"""
Checks number of scans, used to control the api limits
"""
parameters = (
E.ServiceRequest(
E.filters(
E.Criteria({'field': 'status', 'operator': 'EQUALS'}, status))))
xml_output = self.qgc.request(self.COUNT_WASSCAN, parameters)
root = objectify.fromstring(xml_output.encode('utf-8'))
return root.count.text