How to use the lxml.builder.E function in lxml

To help you get started, we’ve selected a few lxml examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Juniper / py-junos-eznc / lib / jnpr / junos / factory / optable.py View on Github external
Args:
        obj: self object which contains table/view details

    Returns: lxml etree object to be used as sax parser input

    """
    if isinstance(obj.ITEM_NAME_XPATH, list):
        # key can be passed as list and list can have many keys
        key_elem = E(obj.ITEM_NAME_XPATH[0])
        for item in obj.ITEM_NAME_XPATH[1:]:
            key_elem.append(E(item))
    else:
        key_elem = E(obj.ITEM_NAME_XPATH)
    if '/' in obj.ITEM_XPATH:
        tags = obj.ITEM_XPATH.split('/')
        parser_ingest = E(tags.pop(-1), key_elem)
        for tag in tags[::-1]:
            parser_ingest = E(tag, parser_ingest)
    else:
        parser_ingest = E(obj.ITEM_XPATH, key_elem)
    local_field_dict = deepcopy(obj.VIEW.FIELDS)
    # first make element out of group fields
    if obj.VIEW.GROUPS:
        for group, group_xpath in obj.VIEW.GROUPS.items():
            # need to pop out group items so that it wont be reused with fields
            group_field_dict = ({k: local_field_dict.pop(k)
                                 for k, v in obj.VIEW.FIELDS.items()
                                 if v.get('group') == group})
            group_ele = E(group_xpath)
            for key, val in group_field_dict.items():
                group_ele.append(E(val.get('xpath')))
            parser_ingest.append(group_ele)
github nre-learning / nrelabs-curriculum / lessons / tools / lesson-26-openconfig / vpn-services.py View on Github external
or vlan is not None and vlan.get('delete_value')
                or ip is not None and ip.get('delete_value')):
            interfaces.append(E.interface(
                E.name(intf is not None and intf.get('delete_value') or curr_intf.text),
                E.unit(
                    E.name(vlan is not None and vlan.get('delete_value') or curr_vlan.text),
                    operation='delete'
                )
            ))

        if (intf is not None and intf.get('operation') == 'create'
                or vlan is not None and vlan.get('operation') == 'create'
                or ip is not None and ip.get('operation') == 'create'):
            interfaces.append(E.interface(
                E.name(intf is not None and intf.text or curr_intf.text),
                E('vlan-tagging'),
                E.unit(
                    E.name(vlan is not None and vlan.text or curr_vlan.text),
                    E('vlan-id', vlan is not None and vlan.text or curr_vlan.text),
                    E.family( E.inet( E.address (
                        E.name(ip is not None and ip.text or curr_ip.text)
                    ) ) )
                )
            ))

        if not all(check_exist):
            instance = E.instance(
                E.name(name.text),
                E('instance-type', 'vrf'),
                E('route-distinguisher', E('rd-type', rd is not None and rd.text or curr_rd.text)),
                E('vrf-target', E.community('target:', rt is not None and rt.text or curr_rt.text)),
                E.interface(E.name(intf is not None and intf.text or curr_intf.text, '.',
github Juniper / py-junos-eznc / lib / jnpr / junos / cfg / srx / nat / nat_st_rule.py View on Github external
def _xml_change_match_dst_addr(self, xml):
    self._rxml_match.append(
      E('destination-address', JXML.REPLACE, self.should['match_dst_addr'])
    )
    return True
github EOX-A / ngeo-b / ngeo_browse_server / control / control / reporting.py View on Github external
reports = []
    if access_logfile:
        reports.append(BrowseAccessReport(begin, end, access_logfile))
    if report_logfile:
        reports.append(BrowseReportReport(begin, end, report_logfile))

    root = E("fetchReportDataResponse")
    for report in reports:
        for record in report.get_records():
            root.append(
                E("report",
                    E("header",
                        E("operation", report.operation),
                        E("component", component_name),
                        E("date", isotime(record.date)), *[
                            E("additionalKey", value, key=key)
                            for key, value in report.get_additional_keys(record)
                        ]
                    ),
                    E("data", *[
                        E("value", value, key=key)
                        for key, value in report.get_data(record)
                    ])
                )
            )
    return root
github Juniper / py-junos-eznc / lib / jnpr / junos / factory / cfgtable.py View on Github external
        simple = lambda: [E(key_xpath.replace('_', '-'), key_value)]
        composite = lambda: [E(xp.replace('_', '-'), xv)
github sim642 / whatpulse / whatpulse.py View on Github external
def __init__(self, type):
		self.tree = (
			E.request({'type': type},
				E.type_os(type_os),
				E.client_version(client_version)
			)
github kimchi-project / kimchi / model / vms.py View on Github external
vol = conn.storageVolLookupByPath(v['path'])
                vol.delete(0)
            raise OperationFailed(
                'KCHVM0007E', {'name': name, 'err': e.get_error_message()}
            )

        cb('Updating VM metadata')
        meta_elements = []

        distro = t.info.get('os_distro')
        version = t.info.get('os_version')
        if distro is not None:
            meta_elements.append(E.os({'distro': distro, 'version': version}))

        if nonascii_name is not None:
            meta_elements.append(E.name(nonascii_name))

        set_metadata_node(VMModel.get_vm(name, self.conn), meta_elements)
        cb('OK', True)
github sim642 / whatpulse / whatpulse.py View on Github external
def __init__(self, type):
		self.tree = (
			E.request({'type': type},
				E.type_os(type_os),
				E.client_version(client_version)
			)
github MaterialsDiscovery / PyChemia / pychemia / code / vasp / task / convergence.py View on Github external
def report(self, file_format='html'):
        from lxml.builder import ElementMaker, E

        if not os.path.isdir(self.report_dir):
            os.mkdir(self.report_dir)

        self.plot(filedir=self.report_dir, file_format='jpg')

        element_maker = ElementMaker(namespace=None, nsmap={None: "http://www.w3.org/1999/xhtml"})
        html = element_maker.html(E.head(E.title("VASP K-point grid Convergence")),
                                  E.body(E.h1("VASP K-point grid Convergence"),
                                         E.h2('Structure'),
                                         E.pre(str(self.structure)),
                                         E.h2('Convergence'),
                                         E.p(E.img(src='convergence.jpg', width="800", height="600", alt="Forces")),
                                         ))

        return self.report_end(html, file_format)
github Juniper / py-junos-eznc / lib / jnpr / junos / cfg / srx / zone_ab_set.py View on Github external
def _xml_at_top(self):
    return E.security(E.zones(
      E('security-zone', 
        E.name(self.P._name),
        E('address-book', 
          E('address-set',E.name(self._name))
        )