Ejemplo n.º 1
0
    def test_404(self):
        self.manager.files = Files(('', view_value('foobar')), )
        yield self.manager.make_server('127.0.0.1', 8080)

        url = 'http://127.0.0.1:8080/nonexistent'
        exc = self.assert_raises(HTTPError, urlopen, url)
        self.eq(exc.code, 404)
Ejemplo n.º 2
0
    def test_real_path(self):
        self.manager.files = Files(('', view_value('bazbuzz')), )
        yield self.manager.make_server('127.0.0.1', 8080)

        data = urlopen('http://127.0.0.1:8080/index.html')
        self.eq(data.read(), b'bazbuzz')
        self.eq(data.info()['Content-Type'], 'text/html')
Ejemplo n.º 3
0
    def test_simple(self):
        self.manager.files = Files(('', view_value('foobar')), )
        yield self.manager.make_server('127.0.0.1', 8080)

        data = urlopen('http://127.0.0.1:8080/')
        self.eq(data.read(), b'foobar')
        self.eq(data.info()['Content-Type'], 'text/html')
Ejemplo n.º 4
0
    def test_Files_ops(self):
        files = Files()

        files.append(Filespec('a', dummy_view))
        files.append(('b', dummy_view, {'foo': 'bar'}))

        files += Files()
        files += Files(('c', dummy_view))
        files += [
            ('d', dummy_view),
            ('e', dummy_view),
        ]

        files.insert(0, ('0', dummy_view))
        files.insert(len(files), Filespec('999', dummy_view))

        del files[1]

        self.eq(
            list(files),
            [
                Filespec('0', dummy_view),
                Filespec('b', dummy_view, {'foo': 'bar'}),
                Filespec('c', dummy_view),
                Filespec('d', dummy_view),
                Filespec('e', dummy_view),
                Filespec('999', dummy_view),
            ]
        )

        self.eq(
            list(files.add_prefix('quux/')),
            [
                Filespec('quux/0', dummy_view),
                Filespec('quux/b', dummy_view, {'foo': 'bar'}),
                Filespec('quux/c', dummy_view),
                Filespec('quux/d', dummy_view),
                Filespec('quux/e', dummy_view),
                Filespec('quux/999', dummy_view),
            ]
        )

        assert [] == Files()
        assert [None] != Files()
        assert Files(('a', dummy_view)) != [None]
Ejemplo n.º 5
0
    def __init__(self):
        self.files = Files()
        self.index_file = None
        self.jinja_extensions = []
        self.template_dirs = [STANGO_TEMPLATE_DIR]

        # By default, all hooks return the data unmodified
        default_hook = lambda context, data: data
        self.hooks = {hook_name: default_hook for hook_name in self.HOOK_NAMES}
Ejemplo n.º 6
0
    def files(self):
        result = Files(
            ('', self.blog_index),
            (
                'feed.atom',
                self.atom,
                {'feed_id': 'feed.atom', 'entries': self.entries}
            ),
            ('archive/', self.archive_index),
        )

        for page in range(2, self.total_pages):
            first_entry = (page - 1) * self.entries_per_page
            result.append(('page/%s' % page, self.blog_index,
                           {'page': page, 'first_entry': first_entry}))

        for entry in self.entries:
            year = entry.date.year
            month = entry.date.month
            url = '%d/%02d/%s%s' % (year, month, entry.slug, self.entry_suffix)
            result.append((url, self.view_entry, {'entry': entry}))

        for tag in self.tags.values():
            result += [
                ('tags/%s/' % tag.name, self.view_tag, {'tag': tag}),
            ]

        for year in self.archive:
            for month in self.archive[year]:
                result.append(('%d/%02d/' % (year, month), self.view_archive,
                               {'year': year, 'month': month}))

        # Prepend path prefix to all filespecs
        if self.prefix:
            return result.add_prefix(self.prefix)
        else:
            return result