def ask_registry(self,
                     service_area_object,
                     db,
                     do_get=HTTP.debuggable_get):
        # If the circulation manager doesn't know about this location, check whether the Library Registry does.
        result = None
        for registry in RemoteRegistry.for_protocol_and_goal(
                db, ExternalIntegration.OPDS_REGISTRATION,
                ExternalIntegration.DISCOVERY_GOAL):
            base_url = registry.integration.url + "/coverage?coverage="

            response = do_get(base_url + service_area_object)
            if not response.status_code == 200:
                result = REMOTE_INTEGRATION_FAILED.detailed(
                    _("Unable to contact the registry at %(url)s.",
                      url=registry.integration.url))

            if hasattr(response, "content"):
                content = json.loads(response.content)
                found_place = not (content.get("unknown")
                                   or content.get("ambiguous"))
                if found_place:
                    return True

        return result
    def process_get(self):
        registries = list(
            RemoteRegistry.for_protocol_and_goal(self._db,
                                                 self.opds_registration,
                                                 self.goal))
        if not registries:
            # There are no registries at all. Set up the default
            # library registry.
            self.set_up_default_registry()

        services = self._get_integration_info(self.goal, self.protocols)
        return dict(
            discovery_services=services,
            protocols=self.protocols,
        )
    def process_get(self):
        registries = list(
            RemoteRegistry.for_protocol_and_goal(
                self._db, self.opds_registration, self.goal
            )
        )
        if not registries:
            # There are no registries at all. Set up the default
            # library registry.
            self.set_up_default_registry()

        services = self._get_integration_info(self.goal, self.protocols)
        return dict(
            discovery_services=services,
            protocols=self.protocols,
        )
Пример #4
0
    def test_for_protocol_and_goal(self):

        # Create two ExternalIntegrations that have different protocols
        # or goals from our original.
        same_goal_different_protocol = self._external_integration(
            protocol="some other protocol", goal=self.integration.goal)

        same_protocol_different_goal = self._external_integration(
            protocol=self.integration.protocol, goal="some other goal")

        # Only the original ExternalIntegration has both the requested
        # protocol and goal, so only it becomes a RemoteRegistry.
        [registry] = list(
            RemoteRegistry.for_protocol_and_goal(self._db,
                                                 self.integration.protocol,
                                                 self.integration.goal))
        assert isinstance(registry, RemoteRegistry)
        eq_(self.integration, registry.integration)
    def ask_registry(self, service_area_object, db, do_get=HTTP.debuggable_get):
        # If the circulation manager doesn't know about this location, check whether the Library Registry does.
        result = None
        for registry in RemoteRegistry.for_protocol_and_goal(
            db, ExternalIntegration.OPDS_REGISTRATION, ExternalIntegration.DISCOVERY_GOAL
        ):
            base_url = registry.integration.url + "/coverage?coverage="

            response = do_get(base_url + service_area_object)
            if not response.status_code == 200:
                result = REMOTE_INTEGRATION_FAILED.detailed(_("Unable to contact the registry at %(url)s.", url=registry.integration.url))

            if hasattr(response, "content"):
                content = json.loads(response.content)
                found_place = not (content.get("unknown") or content.get("ambiguous"))
                if found_place:
                    return True

        return result
Пример #6
0
    def test_for_protocol_and_goal(self):

        # Create two ExternalIntegrations that have different protocols
        # or goals from our original.
        same_goal_different_protocol = self._external_integration(
            protocol="some other protocol", goal=self.integration.goal
        )

        same_protocol_different_goal = self._external_integration(
            protocol=self.integration.protocol, goal="some other goal"
        )

        # Only the original ExternalIntegration has both the requested
        # protocol and goal, so only it becomes a RemoteRegistry.
        [registry] = list(
            RemoteRegistry.for_protocol_and_goal(
                self._db, self.integration.protocol, self.integration.goal
            )
        )
        assert isinstance(registry, RemoteRegistry)
        eq_(self.integration, registry.integration)
Пример #7
0
    def process_get(self):
        """Make a list of all discovery services, each with the
        list of libraries registered with that service and the
        status of the registration."""

        services = []
        for registry in RemoteRegistry.for_protocol_and_goal(
                self._db, ExternalIntegration.OPDS_REGISTRATION, self.goal):
            libraries = []
            for registration in registry.registrations:
                library_info = self.get_library_info(registration)
                if library_info:
                    libraries.append(library_info)

            services.append(
                dict(
                    id=registry.integration.id,
                    libraries=libraries,
                ))

        return dict(library_registrations=services)
    def process_get(self):
        """Make a list of all discovery services, each with the
        list of libraries registered with that service and the
        status of the registration."""

        services = []
        for registry in RemoteRegistry.for_protocol_and_goal(
                self._db, ExternalIntegration.OPDS_REGISTRATION, self.goal
        ):
            libraries = []
            for registration in registry.registrations:
                library_info = self.get_library_info(registration)
                if library_info:
                    libraries.append(library_info)

            services.append(
                dict(
                    id=registry.integration.id,
                    libraries=libraries,
                )
            )

        return dict(library_registrations=services)
    def process_get(self, do_get=HTTP.debuggable_get):
        """Make a list of all discovery services, each with the
        list of libraries registered with that service and the
        status of the registration."""

        services = []
        for registry in RemoteRegistry.for_protocol_and_goal(
                self._db, ExternalIntegration.OPDS_REGISTRATION, self.goal):
            result = (registry.fetch_registration_document(do_get=do_get))
            if isinstance(result, ProblemDetail):
                # Unlike most cases like this, a ProblemDetail doesn't
                # mean the whole request is ruined -- just that one of
                # the discovery services isn't working. Turn the
                # ProblemDetail into a JSON object and return it for
                # handling on the client side.
                access_problem = json.loads(result.response[0])
                terms_of_service_link = terms_of_service_html = None
            else:
                access_problem = None
                terms_of_service_link, terms_of_service_html = result
            libraries = []
            for registration in registry.registrations:
                library_info = self.get_library_info(registration)
                if library_info:
                    libraries.append(library_info)

            services.append(
                dict(
                    id=registry.integration.id,
                    access_problem=access_problem,
                    terms_of_service_link=terms_of_service_link,
                    terms_of_service_html=terms_of_service_html,
                    libraries=libraries,
                ))

        return dict(library_registrations=services)