Beispiel #1
0
    def set_caching(self, caching):
        if caching is None:
            caching = self.default_cache

        if caching is True:
            caching = MaxCache()
        elif caching is False:
            caching = NoCache()
        elif type(caching) is int:
            caching = WeakLRUCache(caching)

        if isinstance(caching, Cache):
            self.cache = caching.transfer(self.cache)
Beispiel #2
0
    def __init__(
        self,
        auth_token,
        url="http://content-api.p2p.tribuneinteractive.com",
        debug=False,
        cache=NoCache(),
        image_services_url=None,
        product_affiliate_code='lanews',
        source_code='latimes',
        webapp_name='tRibbit',
        state_filter='working,live,pending,copyready',
        preserve_embedded_tags=True
    ):
        self.config = {
            'P2P_API_ROOT': url,
            'P2P_API_KEY': auth_token,
            'IMAGE_SERVICES_URL': image_services_url,
        }
        self.cache = cache
        self.debug = debug
        self.product_affiliate_code = product_affiliate_code
        self.source_code = source_code
        self.webapp_name = webapp_name
        self.state_filter = state_filter
        self.preserve_embedded_tags = preserve_embedded_tags

        self.default_filter = {
            'product_affiliate': self.product_affiliate_code,
            'state': self.state_filter
        }

        self.default_content_item_query = {
            'include': [
                'web_url',
                'section',
                'related_items',
                'content_topics',
                'embedded_items'
            ],
            'filter': self.default_filter
        }

        self.content_item_defaults = {
            "content_item_type_code": "blurb",
            "product_affiliate_code": self.product_affiliate_code,
            "source_code": self.source_code,
            "content_item_state_code": "live",
        }

        self.s = requests.Session()
        self.s.mount('https://', TribAdapter())
Beispiel #3
0
    def __init__(self, name, content_class):
        """

        Parameters
        ----------
        name : str
            the name of the store
        content_class : class
            the base class of the content, must be subclassed from
            `StorableMixin`

        """

        super(ObjectStore, self).__init__()
        self._storage = None
        self.content_class = content_class
        self.cache = NoCache()
        self._free = set()
        self._cached_all = False
        self._created = False
        self._document = None

        self.name = name

        self.attribute_list = {}
        self.cv = {}

        # This will not be stored since its information is contained in the
        # dimension names
        self._dimension_name_store = None

        self.variables = dict()
        self.units = dict()

        self.index = None

        self.proxy_index = WeakValueDictionary()

        if self.content_class is not None \
                and not issubclass(self.content_class, StorableMixin):
            raise ValueError(
                'Content class "%s" must be subclassed from StorableMixin.' %
                self.content_class.__name__)
Beispiel #4
0
    def __init__(self,
                 url,
                 auth_token,
                 debug=False,
                 cache=NoCache(),
                 image_services_url=None,
                 product_affiliate_code='chinews',
                 source_code='chicagotribune',
                 webapp_name='tRibbit'):
        self.config = {
            'P2P_API_ROOT': url,
            'P2P_API_KEY': auth_token,
            'IMAGE_SERVICES_URL': image_services_url,
        }
        self.cache = cache
        self.debug = debug
        self.product_affiliate_code = product_affiliate_code
        self.source_code = source_code
        self.webapp_name = webapp_name

        self.default_filter = {
            'product_affiliate': self.product_affiliate_code,
            'state': 'live'
        }

        self.default_content_item_query = {
            'include': [
                'web_url', 'section', 'related_items', 'content_topics',
                'embedded_items'
            ],
            'filter':
            self.default_filter
        }

        self.content_item_defaults = {
            "content_item_type_code": "blurb",
            "product_affiliate_code": self.product_affiliate_code,
            "source_code": self.source_code,
            "content_item_state_code": "live",
        }

        self.s = requests.Session()
        self.s.mount('https://', TribAdapter())
Beispiel #5
0
    def set_caching(self, caching):
        """
        Set the caching mode for this store

        Parameters
        ----------
        caching : :class:`mongodb.Cache`

        """
        if caching is None:
            caching = self.default_cache

        if caching is True:
            caching = MaxCache()
        elif caching is False:
            caching = NoCache()
        elif type(caching) is int:
            caching = WeakLRUCache(caching)

        if isinstance(caching, Cache):
            self.cache = caching.transfer(self.cache)
Beispiel #6
0
    def __init__(self,
                 content_class,
                 json=True,
                 caching=None,
                 nestable=False,
                 has_name=False):
        """

        Parameters
        ----------
        storage
        content_class
        json
        dimension_units
        caching : dict-like or bool or int or None
            this is the dict used for caching.
            `True` means to use a python built-in dict which unlimited caching.
            Be careful.
            `False` means no caching at all. If a dict-like object is passed,
            it will be used.
            An integer `n` means to use LRU Caching with maximal n elements and is
            equal to `cache=LRUCache(n)`
            Default (None) is equivalent to `cache=ObjectStore.default_cache`
        nestable : bool
            if true this marks the content_class to be saved as nested dict
            objects and not a pointing to saved objects. So the saved complex
            object is only stored once and not split into several objects that
            are referenced by each other in a tree-like fashion

        Notes
        -----
        Usually you want caching, but limited. Recommended is to use an LRUCache
        with a reasonable number that depends on the typical number of objects to
        cache and their size

        Attributes
        ----------

        storage : Storage
            the reference the Storage object where all data is stored
        content_class : class
            a reference to the class type to be stored using this Storage
        has_name : bool
            if `True` objects can also be loaded by a string name
        json : string
            if already computed a JSON Serialized string of the object
        simplifier : util.StorableObjectJSON
            an instance of a JSON Serializer
        identifier : str
            name of the netCDF variable that contains the string to be
            identified by. So far this is `name`
        cache : dict-like (int or str : object)
            a dictionary that holds references to all stored elements by index
            or string for named objects. This is only used for cached access
            if caching is not `False`

        Notes
        -----
        The class that takes care of storing data in a file is called a Storage,
        so the netCDF subclassed Storage is a storage. The classes that know how
        to load and save an object from the storage are called stores,
        like ObjectStore, SampleStore, etc...

        """

        self._storage = None
        self.content_class = content_class
        self.prefix = None
        self.cache = NoCache()
        self.has_name = has_name
        self.json = json
        self._free = set()
        self._cached_all = False
        self._names_loaded = False
        self.nestable = nestable
        self.name_idx = dict()

        self.variables = dict()
        self.vars = dict()
        self.units = dict()

        self.index = weakref.WeakKeyDictionary()