# Path: pygopherd/handlers/file.py
# class FileHandler(base.BaseHandler):
#     def canhandlerequest(self):
#         """We can handle the request if it's for a file."""
#         return self.statresult and S_ISREG(self.statresult[ST_MODE])
# 
#     def getentry(self):
#         if not self.entry:
#             self.entry = gopherentry.GopherEntry(self.selector, self.config)
#             self.entry.populatefromfs(self.getselector(), self.statresult, vfs = self.vfs)
#         return self.entry
# 
#     def write(self, wfile):
#         self.vfs.copyto(self.getselector(), wfile)
# 
# Path: pygopherd/gopherentry.py
# class GopherEntry:
#     def __init__(self, selector, config):
#     def populatefromvfs(self, vfs, selector):
#     def populatefromfs(self, fspath, statval = None, vfs = None):
#     def guesstype(self):
#     def handleeaext(self, selector, vfs):
#     def getselector(self, default = None):
#     def setselector(self, arg):
#     def getconfig(self, default = None):
#     def setconfig(self, arg):
#     def getfspath(self, default = None):
#     def setfspath(self, arg):
#     def gettype(self, default = None):
#     def settype(self, arg):
#     def getname(self, default = None):
#     def setname(self, arg):
#     def gethost(self, default = None):
#     def sethost(self, arg):
#     def getport(self, default = None):
#     def setport(self, arg):
#     def getmimetype(self, default = None):
#     def getencodedmimetype(self, default = None):
#     def setencodedmimetype(self, arg):
#     def setmimetype(self, arg):
#     def getsize(self, default = None):
#     def setsize(self, arg):
#     def getencoding(self, default = None):
#     def setencoding(self, arg):
#     def getlanguage(self, default = None):
#     def setlanguage(self, arg):
#     def getctime(self, default = None):
#     def setctime(self, arg):
#     def getmtime(self, default = None):
#     def setmtime(self, arg):
#     def getpopulated(self, default = None):
#     def setpopulated(self, arg):
#     def geturl(self, defaulthost = 'MISSINGHOST', defaultport = 70):
#     def getnum(self, default = None):
#     def setnum(self, arg):
#     def getgopherpsupport(self, default = None):
#     def setgopherpsupport(self, arg):
#     def getea(self, name, default = None):
#     def geteadict(self):
#     def setea(self, name, value):
# def getinfoentry(text, config):


    from simpletal import simpleTAL, simpleTALES
from pygopherd.handlers.file import FileHandler
from pygopherd import gopherentry
    import logging
    import os
import re, os.path
    def getchildrennames(self):
        return self.vfs.listdir(self.path)

    #def getchildren(self):
    #    return [self.__class__(self.vfs, os.path.join(self.path, item)) \
    #            for item in self.getchildrennames()]


    def __getattr__(self, key):
        fq = os.path.join(self.path, key)
        if self.vfs.isfile(fq + ".html.tal"):
            templateFile = self.vfs.open(fq + ".html.tal")
            compiled = simpleTAL.compileHTMLTemplate(templateFile)
            templateFile.close()
            return compiled
        elif self.vfs.isdir(fq):
            return self.__class__(self.vfs, fq)
        else:
            raise AttributeError("Key %s not found in %s" % (key, self.path))

class RecursiveTALLoader(TALLoader):
    def __getattr__(self, key):
        if self.path == '/':
            # Already at the top -- can't recurse.
            return TALLoader.__getattr__(self, key)
        try:
            return TALLoader.__getattr__(self, key)
        except AttributeError:
            return self.getparent().__getattr__(self, key)


# Path: pygopherd/handlers/file.py
# class FileHandler(base.BaseHandler):
#     def canhandlerequest(self):
#         """We can handle the request if it's for a file."""
#         return self.statresult and S_ISREG(self.statresult[ST_MODE])
# 
#     def getentry(self):
#         if not self.entry:
#             self.entry = gopherentry.GopherEntry(self.selector, self.config)
#             self.entry.populatefromfs(self.getselector(), self.statresult, vfs = self.vfs)
#         return self.entry
# 
#     def write(self, wfile):
#         self.vfs.copyto(self.getselector(), wfile)
# 
# Path: pygopherd/gopherentry.py
# class GopherEntry:
#     def __init__(self, selector, config):
#     def populatefromvfs(self, vfs, selector):
#     def populatefromfs(self, fspath, statval = None, vfs = None):
#     def guesstype(self):
#     def handleeaext(self, selector, vfs):
#     def getselector(self, default = None):
#     def setselector(self, arg):
#     def getconfig(self, default = None):
#     def setconfig(self, arg):
#     def getfspath(self, default = None):
#     def setfspath(self, arg):
#     def gettype(self, default = None):
#     def settype(self, arg):
#     def getname(self, default = None):
#     def setname(self, arg):
#     def gethost(self, default = None):
#     def sethost(self, arg):
#     def getport(self, default = None):
#     def setport(self, arg):
#     def getmimetype(self, default = None):
#     def getencodedmimetype(self, default = None):
#     def setencodedmimetype(self, arg):
#     def setmimetype(self, arg):
#     def getsize(self, default = None):
#     def setsize(self, arg):
#     def getencoding(self, default = None):
#     def setencoding(self, arg):
#     def getlanguage(self, default = None):
#     def setlanguage(self, arg):
#     def getctime(self, default = None):
#     def setctime(self, arg):
#     def getmtime(self, default = None):
#     def setmtime(self, arg):
#     def getpopulated(self, default = None):
#     def setpopulated(self, arg):
#     def geturl(self, defaulthost = 'MISSINGHOST', defaultport = 70):
#     def getnum(self, default = None):
#     def setnum(self, arg):
#     def getgopherpsupport(self, default = None):
#     def setgopherpsupport(self, arg):
#     def getea(self, name, default = None):
#     def geteadict(self):
#     def setea(self, name, value):
# def getinfoentry(text, config):


# Path: pygopherd/handlers/tal.py
    from simpletal import simpleTAL, simpleTALES
from pygopherd.handlers.file import FileHandler
from pygopherd import gopherentry
    import logging
    import os
import re, os.path

    def getchildrennames(self):
        return self.vfs.listdir(self.path)

    #def getchildren(self):
    #    return [self.__class__(self.vfs, os.path.join(self.path, item)) \
    #            for item in self.getchildrennames()]


    def __getattr__(self, key):
        fq = os.path.join(self.path, key)
        if self.vfs.isfile(fq + ".html.tal"):
            templateFile = self.vfs.open(fq + ".html.tal")
            compiled = simpleTAL.compileHTMLTemplate(templateFile)
            templateFile.close()
            return compiled
        elif self.vfs.isdir(fq):
            return self.__class__(self.vfs, fq)
        else:
            raise AttributeError("Key %s not found in %s" % (key, self.path))

class RecursiveTALLoader(TALLoader):
    def __getattr__(self, key):
        if self.path == '/':
            # Already at the top -- can't recurse.
            return TALLoader.__getattr__(self, key)
        try:
            return TALLoader.__getattr__(self, key)
        except AttributeError:
            return self.getparent().__getattr__(self, key)


class TALFileHandler(FileHandler):