Пример #1
0
    def get_feed_parser(self, provider, article=None):
        """
        Returns instance of configured feed parser for the given provider.

        :param provider: Ingest Provider Details.
        :type provider: dict :py:class: `superdesk.io.ingest_provider_model.IngestProviderResource`
        :param article: article which needs to parsed by the parser, defaults to None. When None, the registered parser
                        will be returned without checking if the parser can parse the article.
        :return: Feed Parser instance.
        :rtype: :py:class:`superdesk.io.feed_parsers.FeedParser`
        :raises: SuperdeskIngestError.parserNotFoundError()
                    if either feed_parser value is empty or Feed Parser not found.
        """

        parser = registered_feed_parsers.get(provider.get('feed_parser', ''))
        if not parser:
            raise SuperdeskIngestError.parserNotFoundError(provider=provider)

        if article is not None and not parser.can_parse(article):
            raise SuperdeskIngestError.parserNotFoundError(provider=provider)

        if article is not None:
            parser = parser.__class__()

        return parser
Пример #2
0
    def get_feed_parser(self, provider, article=None):
        """
        Returns instance of configured feed parser for the given provider.

        :param provider: Ingest Provider Details.
        :type provider: dict :py:class: `superdesk.io.ingest_provider_model.IngestProviderResource`
        :param article: article which needs to parsed by the parser, defaults to None. When None, the registered parser
                        will be returned without checking if the parser can parse the article.
        :return: Feed Parser instance.
        :rtype: :py:class:`superdesk.io.feed_parsers.FeedParser`
        :raises: SuperdeskIngestError.parserNotFoundError()
                    if either feed_parser value is empty or Feed Parser not found.
        """

        parser = registered_feed_parsers.get(provider.get('feed_parser', ''))
        if not parser:
            raise SuperdeskIngestError.parserNotFoundError(provider=provider)

        if article and not parser.can_parse(article):
            raise SuperdeskIngestError.parserNotFoundError(provider=provider)

        if article:
            parser = parser.__class__()

        return parser
Пример #3
0
def register_feeding_service(service_class):
    """
    Registers the Feeding Service with the application.

    :class: `superdesk.io.feeding_services.RegisterFeedingService` uses this function to register the feeding service.

    :param service_class: Feeding Service class
    :raises: AlreadyExistsError if a feeding service with same name already been registered
    """

    if service_class.NAME in registered_feeding_services:
        raise AlreadyExistsError('Feeding Service: {} already registered by {}'
                                 .format(service_class.NAME,
                                         type(registered_feeding_services[service_class.NAME])))

    registered_feeding_services[service_class.NAME] = service_class()
    allowed_feeding_services.append(service_class.NAME)

    service_class.ERRORS.append(SuperdeskIngestError.parserNotFoundError().get_error_description())
    feeding_service_errors[service_class.NAME] = dict(service_class.ERRORS)
Пример #4
0
def register_feeding_service(service_class):
    """
    Registers the Feeding Service with the application.

    :class: `superdesk.io.feeding_services.RegisterFeedingService` uses this function to register the feeding service.

    :param service_class: Feeding Service class
    :raises: AlreadyExistsError if a feeding service with same name already been registered
    """

    if service_class.NAME in registered_feeding_services:
        raise AlreadyExistsError('Feeding Service: {} already registered by {}'
                                 .format(service_class.NAME,
                                         type(registered_feeding_services[service_class.NAME])))

    registered_feeding_services[service_class.NAME] = service_class()
    allowed_feeding_services.append(service_class.NAME)

    service_class.ERRORS.append(SuperdeskIngestError.parserNotFoundError().get_error_description())
    feeding_service_errors[service_class.NAME] = dict(service_class.ERRORS)
Пример #5
0
def register_feeding_service(service_name, service_class, errors):
    """
    Registers the Feeding Service with the application.
    :class: `superdesk.io.feeding_services.RegisterFeedingService` uses this function to register the feeding service.

    :param service_name: unique name to identify the Feeding Service class
    :param service_class: Feeding Service class
    :param errors: list of tuples, where each tuple represents an error that can be raised by a Feeding Service class.
                   Tuple syntax: (error_code, error_message)
    :raises: AlreadyExistsError if a feeding service with same name already been registered
    """

    if service_name in registered_feed_parsers:
        raise AlreadyExistsError('Feeding Service: {} already registered by {}'
                                 .format(service_name, type(registered_feeding_services[service_name])))

    registered_feeding_services[service_name] = service_class
    allowed_feeding_services.append(service_name)

    errors.append(SuperdeskIngestError.parserNotFoundError().get_error_description())
    feeding_service_errors[service_name] = dict(errors)