Exemplo n.º 1
0
def test_filter():
    page = mock.MagicMock(spec=Page)
    page.config = PageConfiguration()
    page.config.set('threes', {'is_foo': 3})
    it = PageIterator([TestItem(v) for v in [3, 2, 3, 1, 4, 3]], page)
    it.filter('threes')
    assert it.total_count == 3
    assert len(it) == 3
    assert list(it) == [TestItem(3), TestItem(3), TestItem(3)]
Exemplo n.º 2
0
    def __init__(self, source, page, override):
        super(IteratorDataProvider, self).__init__(source, page, override)

        self._innerIt = None
        if isinstance(override, IteratorDataProvider):
            # Iterator providers can be chained, like for instance with
            # `site.pages` listing both the theme pages and the user site's
            # pages.
            self._innerIt = override

        self._pages = PageIterator(source, current_page=page)
        self._pages._iter_event += self._onIteration
        self._ctx_set = False
Exemplo n.º 3
0
    def _load(self):
        if self._iterator is not None:
            return

        if self._source is None:
            raise Exception("Can't load pagination data: no source has "
                            "been defined.")

        pag_filter = self._getPaginationFilter()
        offset = (self._page_num - 1) * self.items_per_page
        self._iterator = PageIterator(
                self._source,
                current_page=self._parent_page,
                pagination_filter=pag_filter,
                offset=offset, limit=self.items_per_page,
                locked=True)
        self._iterator._iter_event += self._onIteration
Exemplo n.º 4
0
    def _writeAutoLocs(self, sitemap, fp):
        source_names = sitemap.setdefault('autogen', None)
        if not source_names:
            return

        cur_time = strftime_iso8601(time.time())
        for name in source_names:
            logger.debug("Generating automatic sitemap entries for '%s'." %
                         name)
            source = self.app.getSource(name)
            if source is None:
                raise Exception("No such source: %s" % name)

            it = PageIterator(source)
            for page in it:
                uri = page['url']
                sm_cfg = page.get('sitemap')

                args = {'url': uri, 'lastmod': cur_time}
                if sm_cfg:
                    args.update(sm_cfg)

                self._writeEntry(args, fp)
Exemplo n.º 5
0
 def _iterItems(self, max_depth=-1, filter_func=None):
     items = walk_linkers(self,
                          max_depth=max_depth,
                          filter_func=filter_func)
     src = LinkerSource(items, self._source)
     return PageIterator(src)
Exemplo n.º 6
0
 def _posts(self):
     it = PageIterator(self._source, current_page=self._page)
     it._iter_event += self._onIteration
     return it
Exemplo n.º 7
0
    def _load(self):
        if self._iterator is not None:
            return

        self._iterator = PageIterator(self._source, self._page)
Exemplo n.º 8
0
 def _load(self):
     if self._iterator is not None:
         return
     source = ArraySource(self._page.app, self._data_source)
     self._iterator = PageIterator(source, current_page=self._page)
Exemplo n.º 9
0
def test_magic_filter():
    it = PageIterator([TestItem(v) for v in [3, 2, 3, 1, 4, 3]])
    it.is_foo(3)
    assert it.total_count == 3
    assert len(it) == 3
    assert list(it) == [TestItem(3), TestItem(3), TestItem(3)]
Exemplo n.º 10
0
def test_setting_sort_reversed():
    it = PageIterator([TestItem(v) for v in [4, 3, 1, 2, 0]])
    it.sort('foo', reverse=True)
    assert it.total_count == 5
    assert len(it) == 5
    assert list(it) == [TestItem(v) for v in reversed(range(5))]
Exemplo n.º 11
0
def test_setting_sort():
    it = PageIterator([TestItem(v) for v in [4, 3, 1, 2, 0]])
    it.sort('foo')
    assert it.total_count == 5
    assert len(it) == 5
    assert list(it) == [TestItem(v) for v in range(5)]
Exemplo n.º 12
0
def test_skip():
    it = PageIterator(range(12))
    it.skip(5)
    assert it.total_count == 12
    assert len(it) == 7
    assert list(it) == list(range(5, 12))
Exemplo n.º 13
0
def test_natural_sort_reversed():
    it = PageIterator([4, 3, 1, 2, 0])
    it.sort(reverse=True)
    assert it.total_count == 5
    assert len(it) == 5
    assert list(it) == list(reversed(range(5)))
Exemplo n.º 14
0
def test_slice():
    it = PageIterator(range(12))
    it.slice(3, 4)
    assert it.total_count == 12
    assert len(it) == 4
    assert list(it) == list(range(3, 7))
Exemplo n.º 15
0
def test_limit():
    it = PageIterator(range(12))
    it.limit(4)
    assert it.total_count == 12
    assert len(it) == 4
    assert list(it) == list(range(4))