How to use the castero.feed.FeedStructureError function in castero

To help you get started, we’ve selected a few castero 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 xgi / castero / castero / feed.py View on Github external
# channel should have at least 3 children, including a
                    # title, link, and description tag
                    channel = root_children[0]
                    channel_children = list(channel)
                    if len(channel_children) >= 3:
                        chan_title_tags = channel.findall('title')
                        chan_link_tags = channel.findall('link')
                        chan_description_tags = channel.findall('description')

                        if len(chan_title_tags) != 1:
                            raise FeedStructureError(
                                "RSS feed's channel has too many or too few"
                                " title tags; expected 1, was: "
                                + str(len(chan_title_tags)))
                        if len(chan_link_tags) != 1:
                            raise FeedStructureError(
                                "RSS feed's channel has too many or too few"
                                " link tags; expected 1, was: "
                                + str(len(chan_link_tags)))
                        if len(chan_description_tags) != 1:
                            raise FeedStructureError(
                                "RSS feed's channel has too many or too few"
                                " description tags; expected 1, was: "
                                + str(len(chan_description_tags)))

                        # if the channel has any items, each item should have
                        # at least a title or description tag
                        channel_item_tags = channel.findall('item')
                        for item in channel_item_tags:
                            if len(item.findall('title')
                                   + item.findall('description')) < 1:
                                raise FeedStructureError(
github xgi / castero / castero / feed.py View on Github external
if self._tree.attrib['version'] != '2.0':
                raise FeedStructureError("RSS version is not 2.0")
        else:
            raise FeedStructureError(
                "RSS feed does not have a version attribute")

        # root should have one child, which is the channel tag
        root_children = list(self._tree)
        if len(root_children) > 0:
            if len(root_children) > 1:
                raise FeedStructureError(
                    "RSS feed has too many children; expected 1, was: "
                    + str(len(root_children)))
            else:
                if root_children[0].tag != 'channel':
                    raise FeedStructureError(
                        "RSS feed does not have a channel tag as its child")
                else:
                    # channel should have at least 3 children, including a
                    # title, link, and description tag
                    channel = root_children[0]
                    channel_children = list(channel)
                    if len(channel_children) >= 3:
                        chan_title_tags = channel.findall('title')
                        chan_link_tags = channel.findall('link')
                        chan_description_tags = channel.findall('description')

                        if len(chan_title_tags) != 1:
                            raise FeedStructureError(
                                "RSS feed's channel has too many or too few"
                                " title tags; expected 1, was: "
                                + str(len(chan_title_tags)))
github xgi / castero / castero / feed.py View on Github external
# at least a title or description tag
                        channel_item_tags = channel.findall('item')
                        for item in channel_item_tags:
                            if len(item.findall('title')
                                   + item.findall('description')) < 1:
                                raise FeedStructureError(
                                    "An item in the RSS feed's channel did not"
                                    " have at least one of a title or a"
                                    " description tag")
                    else:
                        raise FeedStructureError(
                            "RSS feed's channel does not have enough required"
                            " children; expected >=3, was: "
                            + str(len(channel_children)))
        else:
            raise FeedStructureError(
                "RSS feed does not have any children; expected 1 (a channel"
                " tag)")

        self._validated = True
github xgi / castero / castero / display.py View on Github external
self.menus_valid = False
            self.change_status("Feed '%s\' successfully added" % str(feed))
        except FeedError as e:
            if isinstance(e, FeedLoadError):
                self.change_status(
                    "FeedLoadError: %s" % str(e)
                )
            elif isinstance(e, FeedDownloadError):
                self.change_status(
                    "FeedDownloadError: %s" % str(e)
                )
            elif isinstance(e, FeedParseError):
                self.change_status(
                    "FeedParseError: %s" % str(e)
                )
            elif isinstance(e, FeedStructureError):
                self.change_status(
                    "FeedStructureError: %s" % str(e)
                )
            else:
                self.change_status(
                    "FeedError [ambiguous]: %s" % str(e)
                )
github xgi / castero / castero / feed.py View on Github external
- for each child of the channel tag which is an item tag, if any:
                - the item tag must have at least one child, which is a title
                  tag or a description tag
        See http://cyber.harvard.edu/rss/rss.html for more details.

        This method does not set this object's metadata. That is done in
        _process_feed().

        Raises:
            FeedStructureError: the XML document violates one of the conditions
        """
        assert self._tree is not None

        # root should be an rss tag
        if self._tree.tag != 'rss':
            raise FeedStructureError("XML document is not an RSS feed")

        # root should have version attribute which equals 2.0
        if 'version' in self._tree.attrib:
            if self._tree.attrib['version'] != '2.0':
                raise FeedStructureError("RSS version is not 2.0")
        else:
            raise FeedStructureError(
                "RSS feed does not have a version attribute")

        # root should have one child, which is the channel tag
        root_children = list(self._tree)
        if len(root_children) > 0:
            if len(root_children) > 1:
                raise FeedStructureError(
                    "RSS feed has too many children; expected 1, was: "
                    + str(len(root_children)))
github xgi / castero / castero / feed.py View on Github external
"RSS feed's channel has too many or too few"
                                " link tags; expected 1, was: "
                                + str(len(chan_link_tags)))
                        if len(chan_description_tags) != 1:
                            raise FeedStructureError(
                                "RSS feed's channel has too many or too few"
                                " description tags; expected 1, was: "
                                + str(len(chan_description_tags)))

                        # if the channel has any items, each item should have
                        # at least a title or description tag
                        channel_item_tags = channel.findall('item')
                        for item in channel_item_tags:
                            if len(item.findall('title')
                                   + item.findall('description')) < 1:
                                raise FeedStructureError(
                                    "An item in the RSS feed's channel did not"
                                    " have at least one of a title or a"
                                    " description tag")
                    else:
                        raise FeedStructureError(
                            "RSS feed's channel does not have enough required"
                            " children; expected >=3, was: "
                            + str(len(channel_children)))
        else:
            raise FeedStructureError(
                "RSS feed does not have any children; expected 1 (a channel"
                " tag)")

        self._validated = True
github xgi / castero / castero / feed.py View on Github external
Raises:
            FeedStructureError: the XML document violates one of the conditions
        """
        assert self._tree is not None

        # root should be an rss tag
        if self._tree.tag != 'rss':
            raise FeedStructureError("XML document is not an RSS feed")

        # root should have version attribute which equals 2.0
        if 'version' in self._tree.attrib:
            if self._tree.attrib['version'] != '2.0':
                raise FeedStructureError("RSS version is not 2.0")
        else:
            raise FeedStructureError(
                "RSS feed does not have a version attribute")

        # root should have one child, which is the channel tag
        root_children = list(self._tree)
        if len(root_children) > 0:
            if len(root_children) > 1:
                raise FeedStructureError(
                    "RSS feed has too many children; expected 1, was: "
                    + str(len(root_children)))
            else:
                if root_children[0].tag != 'channel':
                    raise FeedStructureError(
                        "RSS feed does not have a channel tag as its child")
                else:
                    # channel should have at least 3 children, including a
                    # title, link, and description tag
github xgi / castero / castero / feed.py View on Github external
This method does not set this object's metadata. That is done in
        _process_feed().

        Raises:
            FeedStructureError: the XML document violates one of the conditions
        """
        assert self._tree is not None

        # root should be an rss tag
        if self._tree.tag != 'rss':
            raise FeedStructureError("XML document is not an RSS feed")

        # root should have version attribute which equals 2.0
        if 'version' in self._tree.attrib:
            if self._tree.attrib['version'] != '2.0':
                raise FeedStructureError("RSS version is not 2.0")
        else:
            raise FeedStructureError(
                "RSS feed does not have a version attribute")

        # root should have one child, which is the channel tag
        root_children = list(self._tree)
        if len(root_children) > 0:
            if len(root_children) > 1:
                raise FeedStructureError(
                    "RSS feed has too many children; expected 1, was: "
                    + str(len(root_children)))
            else:
                if root_children[0].tag != 'channel':
                    raise FeedStructureError(
                        "RSS feed does not have a channel tag as its child")
                else: