muyhomepage2 / muyhomepage2 /

Full commit
#!/usr/bin/env python
# Copyright 2009 John Mulligan <>
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2, incorporated herein by reference.
"""page data

import os
import email.parser

def parse(name):
    """Parses a page file and returns a Page object.
    fp = open(name)
        message = email.parser.Parser().parse(fp)
    headers = dict([(k.lower(), v) for k, v in message.items()])
    return Page(name, headers, message.get_payload())

def walkpages(root, suffix='.page'):
    """Generates a series of page filenames from the given root directory.
    for dname, dirs, files in os.walk(root):
        for fn in files:
            if fn.endswith(suffix):
                yield os.path.join(dname, fn)

class Page(object):
    """A page object.
    def __init__(self, filename, headers=None, body=None):
        self.filename = filename
        self.headers = headers
        self.body = body

    def title(self):
        return self.headers.get('title')