Source

muyhomepage2 / muyhomepage2 / metadata.py

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

import urllib


def writepagecache(data, fp):
    for (filename, ccode, title, action) in data:
        parts = [filename, ccode, title, action]
        parts = [p or '.' for p in parts]
        parts = [urllib.quote(p) for p in parts]
        fp.write('%s\n' % ' '.join(parts))


def readpagecache(fp):
    def _unquote(value):
        if value == '.':
            return ''
        else:
            return urllib.unquote(value)
    for line in fp:
        parts = line.split()
        assert len(parts) == 4
        yield tuple([_unquote(p) for p in parts])


def writetagcache(data, fp):
    pass

def readtagcache(fp):
    pass