當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。