Exemplo n.º 1
0
    def lookup(self, identifier):
        """Requests NoveList metadata for a particular identifier

        :return: Metadata object or None
        """
        client_identifier = identifier.urn
        if identifier.type != Identifier.ISBN:
            return self.lookup_equivalent_isbns(identifier)

        params = dict(
            ClientIdentifier=client_identifier, ISBN=identifier.identifier,
            version=self.version, profile=self.profile, password=self.password
        )
        scrubbed_url = unicode(self.scrubbed_url(params))

        representation = self.cached_representation(scrubbed_url)
        if not representation:
            self.log.info("No cached NoveList request available.")

            url = self.build_query_url(params)
            self.log.debug("NoveList lookup: %s",  url)
            representation, from_cache = Representation.post(
                self._db, unicode(url), '', max_age=self.MAX_REPRESENTATION_AGE,
                response_reviewer=self.review_response
            )

            # Remove credential information from the Representation URL. This
            # avoids holding those details in an unexpected part of the database
            # and lets multiple libraries to use the same cached representation.
            representation.url = scrubbed_url

        return self.lookup_info_to_metadata(representation)
Exemplo n.º 2
0
    def lookup(self, identifier):
        """Requests NoveList metadata for a particular identifier

        :return: Metadata object or None
        """
        client_identifier = identifier.urn
        if identifier.type != Identifier.ISBN:
            return self.lookup_equivalent_isbns(identifier)

        params = dict(ClientIdentifier=client_identifier,
                      ISBN=identifier.identifier,
                      version=self.version,
                      profile=self.profile,
                      password=self.password)
        scrubbed_url = unicode(self.scrubbed_url(params))

        representation = self.cached_representation(scrubbed_url)
        if not representation:
            self.log.info("No cached NoveList request available.")

            url = self.build_query_url(params)
            self.log.debug("NoveList lookup: %s", url)
            representation, from_cache = Representation.post(
                self._db,
                unicode(url),
                '',
                max_age=self.MAX_REPRESENTATION_AGE,
                response_reviewer=self.review_response)

            # Remove credential information from the Representation URL. This
            # avoids holding those details in an unexpected part of the database
            # and lets multiple libraries to use the same cached representation.
            representation.url = scrubbed_url

        return self.lookup_info_to_metadata(representation)
Exemplo n.º 3
0
    def lookup(self, identifier, **kwargs):
        """Requests NoveList metadata for a particular identifier

        :param kwargs: Keyword arguments passed into Representation.post().

        :return: Metadata object or None
        """
        client_identifier = identifier.urn
        if identifier.type != Identifier.ISBN:
            return self.lookup_equivalent_isbns(identifier)

        params = dict(
            ClientIdentifier=client_identifier,
            ISBN=identifier.identifier,
            version=self.version,
            profile=self.profile,
            password=self.password,
        )
        scrubbed_url = str(self.scrubbed_url(params))

        url = self.build_query_url(params)
        self.log.debug("NoveList lookup: %s", url)

        # We want to make an HTTP request for `url` but cache the
        # result under `scrubbed_url`. Define a 'URL normalization'
        # function that always returns `scrubbed_url`.
        def normalized_url(original):
            return scrubbed_url

        representation, from_cache = Representation.post(
            _db=self._db,
            url=str(url),
            data="",
            max_age=self.MAX_REPRESENTATION_AGE,
            response_reviewer=self.review_response,
            url_normalizer=normalized_url,
            **kwargs
        )

        # Commit to the database immediately to reduce the chance
        # that some other incoming request will try to create a
        # duplicate Representation and crash.
        self._db.commit()

        return self.lookup_info_to_metadata(representation)