当前位置: 首页>>代码示例>>Python>>正文


Python objectify.fromstring方法代码示例

本文整理汇总了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) 
开发者ID:gramps-project,项目名称:addons-source,代码行数:22,代码来源:lxmlGramplet.py

示例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) 
开发者ID:italia,项目名称:spid-testenv2,代码行数:26,代码来源:crypto.py

示例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') 
开发者ID:italia,项目名称:spid-testenv2,代码行数:23,代码来源:test_parsers.py

示例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'] 
开发者ID:OSInside,项目名称:kiwi,代码行数:25,代码来源:virtualbox_ovf_test.py

示例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) 
开发者ID:d1vious,项目名称:pnexpose,代码行数:21,代码来源:pnexpose.py

示例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 
开发者ID:d1vious,项目名称:pnexpose,代码行数:24,代码来源:pnexpose.py

示例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) 
开发者ID:d1vious,项目名称:pnexpose,代码行数:20,代码来源:pnexpose.py

示例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 
开发者ID:d1vious,项目名称:pnexpose,代码行数:25,代码来源:pnexpose.py

示例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 
开发者ID:cokelaer,项目名称:bioservices,代码行数:29,代码来源:xmltools.py

示例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) 
开发者ID:hbrands,项目名称:jira-issues-importer,代码行数:5,代码来源:main.py

示例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) 
开发者ID:vlaci,项目名称:openconnect-sso,代码行数:10,代码来源:authenticator.py

示例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 
开发者ID:rainforestautomation,项目名称:Eagle-Http-API,代码行数:13,代码来源:eagle_http.py

示例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) 
开发者ID:Morgan-Stanley,项目名称:testplan,代码行数:10,代码来源:testing.py

示例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)) 
开发者ID:SpectoLabs,项目名称:hoverpy,代码行数:30,代码来源:modify_payload.py

示例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 
开发者ID:HASecuritySolutions,项目名称:VulnWhisperer,代码行数:13,代码来源:qualys_web.py


注:本文中的lxml.objectify.fromstring方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。