contentfilters.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:munch-core 作者: crunchmail 项目源码 文件源码
def handle_images(html, detach_images=False, organization=None, **kwargs):
    """ Detach base64 images and others if detach_images is enabled
    """
    tree = lxml.html.fromstring(html)

    for img in tree.cssselect('img'):
        try:
            src = img.attrib['src']
        except KeyError:
            raise WrongHTML('<img> devrait avoir un attribut "src"')
        if src.startswith('data:image/'):
            # TODO: handle ValueError
            image = InlineImage(src, organization=organization)
            url = image.store()
            img.set('src', url)
        else:
            if detach_images and organization:
                image = HostedImage(src, organization=organization)
                url = image.store()
                img.set('src', url)
    return lxml.html.tostring(tree).decode()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号