Beispiel #1
0
 def open_access_link(self, lpdm):
     url = cdnify(lpdm.resource.url, Configuration.cdns())
     kw = dict(rel=OPDSFeed.OPEN_ACCESS_REL, href=url)
     rep = lpdm.resource.representation
     if rep and rep.media_type:
         kw['type'] = rep.media_type
     link_tag = AcquisitionFeed.link(**kw)
     always_available = OPDSFeed.makeelement("{%s}availability" %
                                             OPDSFeed.OPDS_NS,
                                             status="available")
     link_tag.append(always_available)
     return link_tag
    def fulfill_open_access(self, licensepool, delivery_mechanism):
        """Fulfill an open-access LicensePool through the requested
        DeliveryMechanism.

        :param licensepool: The title to be fulfilled.
        :param delivery_mechanism: A DeliveryMechanism.
        """
        if isinstance(delivery_mechanism, LicensePoolDeliveryMechanism):
            self.log.warn(
                "LicensePoolDeliveryMechanism passed into fulfill_open_access, should be DeliveryMechanism."
            )
            delivery_mechanism = delivery_mechanism.delivery_mechanism
        fulfillment = None
        for lpdm in licensepool.delivery_mechanisms:
            if not (lpdm.resource and lpdm.resource.representation
                    and lpdm.resource.representation.url):
                # This LicensePoolDeliveryMechanism can't actually
                # be used for fulfillment.
                continue
            if lpdm.delivery_mechanism == delivery_mechanism:
                # We found it! This is how the patron wants
                # the book to be delivered.
                fulfillment = lpdm
                break

        if not fulfillment:
            # There is just no way to fulfill this loan the way the
            # patron wants.
            raise FormatNotAvailable()

        rep = fulfillment.resource.representation
        cdns = Configuration.cdns()
        content_link = cdnify(rep.url, cdns)
        media_type = rep.media_type
        return FulfillmentInfo(identifier_type=licensepool.identifier.type,
                               identifier=licensepool.identifier.identifier,
                               content_link=content_link,
                               content_type=media_type,
                               content=None,
                               content_expires=None)
Beispiel #3
0
def cdnify(url, cdns=None):
    """Turn local URLs into CDN URLs"""
    cdns = cdns or Configuration.cdns()
    if not cdns:
        # No CDNs configured
        return url
    scheme, netloc, path, query, fragment = urlparse.urlsplit(url)

    if netloc == 's3.amazonaws.com':
        # This is a URL like "http://s3.amazonaws.com/bucket/foo".
        # It's equivalent to "http://bucket/foo".
        # i.e. treat the bucket name as the netloc.
        bucket, path = S3Uploader.bucket_and_filename(url)
        netloc = bucket

    if netloc not in cdns:
        # This domain name is not covered by any of our CDNs.
        return url

    cdn_host = cdns[netloc]
    cdn_scheme, cdn_netloc, i1, i2, i3 = urlparse.urlsplit(cdn_host)
    return urlparse.urlunsplit((cdn_scheme, cdn_netloc, path, query, fragment))
Beispiel #4
0
    def cover_links(cls, work):
        """Return all links to be used as cover links for this work.

        In a distribution application, each work will have only one
        link. In a content server-type application, each work may have
        a large number of links.

        :return: A 2-tuple (thumbnail_links, full_links)

        """
        thumbnails = []
        full = []
        cdns = Configuration.cdns()
        if work:
            if work.cover_thumbnail_url:
                thumb = work.cover_thumbnail_url
                old_thumb = thumb
                thumbnails = [cdnify(thumb, cdns)]

            if work.cover_full_url:
                full = work.cover_full_url
                full = [cdnify(full, cdns)]
        return thumbnails, full
Beispiel #5
0
def cdnify(url, cdns=None):
    """Turn local URLs into CDN URLs"""
    try:
        cdns = cdns or Configuration.cdns()
    except CannotLoadConfiguration, e:
        pass
Beispiel #6
0
from model import (
    get_one,
    Complaint,
    Identifier,
    Patron,
)
from util.cdn import cdnify
from classifier import Classifier
from config import Configuration
from lane import (
    Facets,
    Pagination,
)
from problem_details import *

cdns = Configuration.cdns()


def cdn_url_for(*args, **kwargs):
    base_url = url_for(*args, **kwargs)
    return cdnify(base_url, cdns)


def load_lending_policy(policy):
    if not policy:
        logging.info("No lending policy.")
        return {}
    if isinstance(policy, basestring):
        policy = json.loads(policy)
    for external_type, p in policy.items():
        if Patron.AUDIENCE_RESTRICTION_POLICY in p:
Beispiel #7
0
def cdnify(url, cdns=None):
    """Turn local URLs into CDN URLs"""
    try:
        cdns = cdns or Configuration.cdns()
    except CannotLoadConfiguration, e:
        pass