Пример #1
0
    def test_parsing_skip_with_scheme(self):
        """should only add images that do not start with an path"""
        test_urls = [
            '<p><img src="/bar/foo.jpg" /></p>',
            '<p><img src="/foo.jpg" /></p>',
            '<p><img src="https://foo.jpg" /></p>',
            '<p><img src="http://foo.jpg" /></p>',
            '<p><img src="ftp://foo.jpg" /></p>',
            '<p><img src="//foo.jpg" /></p>'
        ]

        for url in test_urls:
            parser = ImageParser()
            parser.feed(url)
            self.assertEqual(len(parser.images), 0)
Пример #2
0
    def images(self):
        """
        Returns:
            list of all user defined images
        """
        if self._images:
            return self._images

        parser = ImageParser()

        if hasattr(self, "rendered"):
            parser.feed(self.rendered)
        elif self.content is not None:
            parser.feed(self.content)
        else:
            return list()

        if len(parser.images) == 0:
            self._images = list()
        else:
            self._images = parser.images

        return self._images
Пример #3
0
    def test_parsing(self):
        parser = ImageParser()
        parser.feed('<p><img src="foo.jpg" /></p>')

        self.assertEqual(len(parser.images), 1)
        self.assertEqual(parser.images[0], "foo.jpg")