def METHOD_NAME(self, f, functions, vars):
    def p(templ, vars=vars): # helper function to generate output
        print >> f, templ % vars
    if not functions:
        return
    p(template.methoddef_start)
    for name, func in sortitems(functions):
        if func.__doc__:
            p(template.methoddef_def_doc, func.vars)
        else:
            p(template.methoddef_def, func.vars)
    p(template.methoddef_end)