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

from muyhomepage2 import util

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')

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

    def contentcode(self):
        return util.contentcode(self.filename)

class PseduoPage(object):
    def __init__(self, filename, contentcode, title, action):
        self.filename = filename
        self.contentcode = contentcode
        self.title = title
        self.action = action