view piecrust/sources/list.py @ 1169:978ed6deea91

tests: Add ability to test different expected outputs based on Python version. Similar to the previous change, there was also a change in what gets escaped by `urllib.parse.quote` (as in: the tilde sign ('~') stopped being escaped). So now we need to be able to test different outputs in the tests, yay again.
author Ludovic Chabant <ludovic@chabant.com>
date Fri, 04 Oct 2019 11:15:11 -0700
parents 8adc27285d93
children
line wrap: on
line source

from piecrust.sources.base import ContentSource


class ListSource(ContentSource):
    def __init__(self, inner_source, items):
        super().__init__(
            inner_source.app, inner_source.name, inner_source.config)

        self.inner_source = inner_source
        self.items = items

    def openItem(self, item, mode='r', **kwargs):
        return self.inner_source.openItem(item, mode, **kwargs)

    def getItemMtime(self, item):
        return self.inner_source.getItemMtime(item)

    def getContents(self, group):
        return self.items

    def getRelatedContents(self, item, relationship):
        return self.inner_source.getRelatedContents(item, relationship)

    def findContentFromRoute(self, route_params):
        # Can't find items... we could find stuff that's not in our list?
        raise NotImplementedError(
            "The list source doesn't support finding items.")

    def getSupportedRouteParameters(self):
        return self.inner_source.getSupportedRouteParameters()