How to use the defusedxml.lxml._etree.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 fossasia / badgeyay / api / utils / svg_to_png.py View on Github external
Module to change size of each badge lines
                :param `filename` - svg file to modify.
                :param `font_size_1` - Size to be applied on first line
                :param `font_size_2` - Size to be applied on Second line
                :param `font_size_3` - Size to be applied on Third line
                :param `font_size_4` - Size to be applied on Fourth line
                :param `font_size_5` - Size to be applied on Fifth line
        """

        font_size = [1, font_size_1, font_size_2, font_size_3, font_size_4, font_size_5]
        dimensions = badge_config[paper_size][badge_size]
        if config.ENV == 'LOCAL':
            filename = 'static/badges/' + dimensions.badgeSize + 'on' + dimensions.paperSize + '.svg'
        else:
            filename = os.getcwd() + '/api/static/badges/' + dimensions.badgeSize + 'on' + dimensions.paperSize + '.svg'
        tree = etree.parse(open(os.path.join(self.APP_ROOT, filename), 'r'))
        element = tree.getroot()

        for idx in range(1, dimensions.badges + 1):

            for row in range(1, 6):
                _id = 'Person_color_{}_{}'.format(idx, row)
                path = element.xpath(("//*[@id='{}']").format(_id))[0]
                style_detail = path.get("style")
                style_detail = style_detail.split(";")

                for ind, i in enumerate(style_detail):
                    if i.split(':')[0] == 'font-size':
                        style_detail[ind] = "font-size:" + str(font_size[row]) + 'px'
                style_detail = ';'.join(style_detail)
                text_nodes = path.getchildren()
                path.set("style", style_detail)
github fossasia / badgeyay / backend / utils / svg_to_png.py View on Github external
def do_text_fill(self, filename, font_color_1, font_color_2, font_color_3, font_color_4, font_color_5, logo_fill, badge_size, paper_size):
        """
        Module to change color of badge's details
        :param `filename` - svg file to modify.
        :param `fill` - lis of color to be applied on each line
        """
        fill = [1, font_color_1, font_color_2, font_color_3, font_color_4, font_color_5]
        dimensions = badge_config[paper_size][badge_size]
        if config.ENV == 'LOCAL':
            filename = 'static/badges/' + dimensions.badgeSize + 'on' + dimensions.paperSize + '.svg'
        else:
            filename = os.getcwd() + '/api/static/badges/' + dimensions.badgeSize + 'on' + dimensions.paperSize + '.svg'
        tree = etree.parse(open(os.path.join(self.APP_ROOT, filename), 'r'))
        element = tree.getroot()

        for idx in range(1, dimensions.badges + 1):

            for row in range(1, 6):
                _id = 'Person_color_{}_{}'.format(idx, row)
                path = element.xpath(("//*[@id='{}']").format(_id))[0]
                style_detail = path.get("style")
                style_detail = style_detail.split(";")

                if style_detail[7].split(':')[0] == 'fill':
                    style_detail[7] = "fill:" + str(fill[row])
                    print(style_detail[7])

                elif style_detail[6].split(':')[0] == 'fill':
                    style_detail[6] = "fill:" + str(fill[row])
github fossasia / badgeyay / api / utils / svg_to_png.py View on Github external
def do_text_fill(self, filename, font_color_1, font_color_2, font_color_3, font_color_4, font_color_5, logo_fill, badge_size, paper_size):
        """
        Module to change color of badge's details
        :param `filename` - svg file to modify.
        :param `fill` - lis of color to be applied on each line
        """
        fill = [1, font_color_1, font_color_2, font_color_3, font_color_4, font_color_5]
        dimensions = badge_config[paper_size][badge_size]
        if config.ENV == 'LOCAL':
            filename = 'static/badges/' + dimensions.badgeSize + 'on' + dimensions.paperSize + '.svg'
        else:
            filename = os.getcwd() + '/api/static/badges/' + dimensions.badgeSize + 'on' + dimensions.paperSize + '.svg'
        tree = etree.parse(open(os.path.join(self.APP_ROOT, filename), 'r'))
        element = tree.getroot()

        for idx in range(1, dimensions.badges + 1):

            for row in range(1, 6):
                _id = 'Person_color_{}_{}'.format(idx, row)
                path = element.xpath(("//*[@id='{}']").format(_id))[0]
                style_detail = path.get("style")
                style_detail = style_detail.split(";")

                if style_detail[7].split(':')[0] == 'fill':
                    style_detail[7] = "fill:" + str(fill[row])
                    print(style_detail[7])

                elif style_detail[6].split(':')[0] == 'fill':
                    style_detail[6] = "fill:" + str(fill[row])
github furlongm / patchman / repos / utils.py View on Github external
def get_primary_url(mirror_url, data):

    if isinstance(data, text_type):
        if data.startswith('Bad repo - not in list') or \
                data.startswith('Invalid repo'):
            return None, None, None
    ns = 'http://linux.duke.edu/metadata/repo'
    try:
        context = etree.parse(BytesIO(data), etree.XMLParser())
    except etree.XMLSyntaxError:
        context = etree.parse(BytesIO(extract(data, 'gz')), etree.XMLParser())
    location = context.xpath("//ns:data[@type='primary']/ns:location/@href",
                             namespaces={'ns': ns})[0]
    checksum = context.xpath("//ns:data[@type='primary']/ns:checksum",
                             namespaces={'ns': ns})[0].text
    csum_type = context.xpath("//ns:data[@type='primary']/ns:checksum/@type",
                              namespaces={'ns': ns})[0]
    primary_url = str(mirror_url.rsplit('/', 2)[0]) + '/' + location
    return primary_url, checksum, csum_type
github furlongm / patchman / repos / utils.py View on Github external
def get_metalink_urls(url):
    """  Parses a metalink and returns a list of mirrors
    """
    res = get_url(url)
    if response_is_valid(res):
        if 'content-type' in res.headers and \
           res.headers['content-type'] == 'application/metalink+xml':
            data = download_url(res, 'Downloading repo info:')
            ns = 'http://www.metalinker.org/'
            try:
                context = etree.parse(BytesIO(data), etree.XMLParser())
            except etree.XMLSyntaxError:
                context = etree.parse(BytesIO(extract(data, 'gz')),
                                      etree.XMLParser())
            xpath = "//ns:files/ns:file[@name='repomd.xml']/ns:resources/ns:url[@protocol='https']"  # noqa
            metalink_urls = context.xpath(xpath, namespaces={'ns': ns})
            return [x.text for x in metalink_urls]
github fossasia / badgeyay / backend / utils / generate_badges.py View on Github external
def remove_extra(badge_page, offset):
    tree = etree.parse(open(badge_page, 'r'))
    root = tree.getroot()
    children = root.findall('.//{http://www.w3.org/2000/svg}g')
    for i in range(offset, len(children)):
        children[i].getparent().remove(children[i])
    etree.ElementTree(root).write(badge_page, pretty_print=True)