How to use the defusedxml.lxml.parse function in defusedxml

To help you get started, we’ve selected a few defusedxml 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 RUB-NDS / DTD-Attacks / code / python / lxml / testDefusedLxml.py View on Github external
def testParameterEntity_doctype(self):				
		tree = _LXML.parse('../../xml_files_windows/xxep/parameterEntity_doctype.xml')
		root = tree.getroot()
		self.assertEquals(None, root.text)
github RUB-NDS / DTD-Attacks / code / python / lxml / testDefusedLxml.py View on Github external
def testInternalSubset_ExternalPEReferenceInDTD(self):
		with self.assertRaises(EntitiesForbidden):
			tree = _LXML.parse('../../xml_files_windows/xxep/internalSubset_ExternalPEReferenceInDTD.xml')
github RUB-NDS / DTD-Attacks / code / python / lxml / testDefusedLxml.py View on Github external
def testXXE(self):
		with self.assertRaises(EntitiesForbidden):		
			tree = _LXML.parse('../../xml_files_windows/xxe/xxe.xml')
github fossasia / badgeyay / v1 / cli / badgeyay / utils / custom_color.py View on Github external
def do_svg2png(filename, opacity, fill):
    """
    Module to convert svg to png
    :param `filename` - Destination file name
    :param `opacity` - Opacity for the output
    :param `fill` -  Background fill for the output
    :param `text_` - Text to be placed on the badge
    """
    png_filename = filename
    filename = filename.rsplit(".", 1)[0] + '.svg'
    filename = os.path.join(STATIC_ASSET, filename)
    tree = parse(open(filename, 'r'))
    element = tree.getroot()
    # changing style using XPath.
    path = element.xpath('//*[@id="rect4504"]')[0]
    style_detail = path.get("style")
    style_detail = style_detail.split(";")
    style_detail[0] = "opacity:" + str(opacity)
    style_detail[1] = "fill:" + str(fill)
    style_detail = ';'.join(style_detail)
    path.set("style", style_detail)
    # changing text using XPath.
    path = element.xpath('//*[@id="tspan932"]')[0]
    # Saving in the original XML tree
    etree.ElementTree(element).write(filename, pretty_print=True)
    svg2png(url=filename, write_to=GENERATED + '/' + png_filename)
    click.echo('Custom Image Saved')
github ReliaQualAssociates / ramstk / src / rtk / gui / gtk / rtk / TreeView.py View on Github external
def do_parse_format(self, fmt_path, fmt_file, pixbuf=False, indexed=False):
        """
        Parse the format file for the RAMSTKTreeView().

        :param str fmt_path: the base XML path in the format file to read.
        :param str fmt_file: the absolute path to the format file to read.
        :keyword bool pixbuf: indicates whether or not to prepend a PixBuf
                              column to the gtk.TreeModel().
        :keyword bool indexed: indicates whether or not to append a column to
                               the gtk.TreeModel() to hold indexing
                               information.
        :return: None
        :rtype: None
        """
        # Retrieve the column heading text from the format file.
        self.headings = lxml.parse(fmt_file).xpath(fmt_path + "/usertitle")

        # Retrieve the column datatype from the format file.
        self.datatypes = lxml.parse(fmt_file).xpath(fmt_path + "/datatype")

        # Retrieve the column position from the format file.
        _position = lxml.parse(fmt_file).xpath(fmt_path + "/position")

        # Retrieve the cell renderer type from the format file.
        self.widgets = lxml.parse(fmt_file).xpath(fmt_path + "/widget")

        # Retrieve whether or not the column is editable from the format file.
        self.editable = lxml.parse(fmt_file).xpath(fmt_path + "/editable")

        # Retrieve whether or not the column is visible from the format file.
        self.visible = lxml.parse(fmt_file).xpath(fmt_path + "/visible")
github fossasia / badgeyay / v1 / app / generate_badges.py View on Github external
def configure_badge_page(self, badge_page, options):
        """
        Configure the badge page according to the page
        options as passed in the function
        :param `badge_page` - Single Badge Sheet
        :param `options` - Options for the page
        """
        if options.get('width') and options.get('height'):
            paper_width = options.get('width')
            paper_height = options.get('height')
        else:
            paper_size_format = options.get('paper_size_format')
            paper_width = self.paper_sizes[paper_size_format][0]
            paper_height = self.paper_sizes[paper_size_format][1]
        tree = parse(open(badge_page, 'r'))
        root = tree.getroot()
        path = root.xpath('//*[@id="svg2"]')[0]
        path.set('width', paper_width)
        path.set('height', paper_height)
        etree.ElementTree(root).write(badge_page, pretty_print=True)
github ReliaQualAssociates / ramstk / src / rtk / gui / gtk / assistants / Preferences.py View on Github external
# Retrieve the default heading text from the format file.
        _path = _fmt_path + '/defaulttitle'
        _default = lxml.parse(self._fmt_file).xpath(_path)

        # Retrieve the default heading text from the format file.
        _path = _fmt_path + '/usertitle'
        _user = lxml.parse(self._fmt_file).xpath(_path)

        # Retrieve the column position from the format file.
        _path = _fmt_path + '/position'
        _position = lxml.parse(self._fmt_file).xpath(_path)

        # Retrieve whether or not the column is editable from the format file.
        _path = _fmt_path + '/editable'
        _editable = lxml.parse(self._fmt_file).xpath(_path)

        # Retrieve whether or not the column is visible from the format file.
        _path = _fmt_path + '/visible'
        _visible = lxml.parse(self._fmt_file).xpath(_path)

        # Retrieve datatypes from the format file.
        _path = _fmt_path + '/datatype'
        _datatype = lxml.parse(self._fmt_file).xpath(_path)

        # Retrieve widget types from the format file.
        _path = _fmt_path + '/widget'
        _widget = lxml.parse(self._fmt_file).xpath(_path)

        # Retrieve attribute keys from the format file.
        _path = _fmt_path + '/key'
        _keys = lxml.parse(self._fmt_file).xpath(_path)
github ReliaQualAssociates / ramstk / src / ramstk / gui / gtk / ramstk / TreeView.py View on Github external
:rtype: None
        """
        # Retrieve the column heading text from the format file.
        self.headings = lxml.parse(fmt_file).xpath(fmt_path + "/usertitle")

        # Retrieve the column datatype from the format file.
        self.datatypes = lxml.parse(fmt_file).xpath(fmt_path + "/datatype")

        # Retrieve the column position from the format file.
        _position = lxml.parse(fmt_file).xpath(fmt_path + "/position")

        # Retrieve the cell renderer type from the format file.
        self.widgets = lxml.parse(fmt_file).xpath(fmt_path + "/widget")

        # Retrieve whether or not the column is editable from the format file.
        self.editable = lxml.parse(fmt_file).xpath(fmt_path + "/editable")

        # Retrieve whether or not the column is visible from the format file.
        self.visible = lxml.parse(fmt_file).xpath(fmt_path + "/visible")

        # Initialize public scalar instance attributes.
        _keys = lxml.parse(fmt_file).xpath(fmt_path + "/key")

        # Create a list of GObject datatypes to pass to the model.
        for i in range(len(self.datatypes)):  # pylint: disable=C0200
            self.datatypes[i] = self.datatypes[i].text
            self.editable[i] = int(self.editable[i].text)
            self.headings[i] = self.headings[i].text.replace("  ", "\n")
            self.order.append(int(_position[i].text))
            self.visible[i] = int(self.visible[i].text)
            self.widgets[i] = self.widgets[i].text
            _position[i] = int(_position[i].text)