Added changeFunctionName to be used elsewhere.

This commit is contained in:
Jeremy Fincher 2004-01-16 16:13:24 +00:00
parent 8f53601882
commit cd5a1cb14b

View File

@ -43,6 +43,7 @@ import os
import re import re
import md5 import md5
import sha import sha
import types
import string import string
import sgmllib import sgmllib
import compiler import compiler
@ -525,9 +526,17 @@ def nonEmptyLines(fd):
def nonCommentNonEmptyLines(fd): def nonCommentNonEmptyLines(fd):
return nonEmptyLines(nonCommentLines(fd)) return nonEmptyLines(nonCommentLines(fd))
def changeFunctionName(f, name, doc=None):
if doc is None:
doc = f.__doc__
newf = types.FunctionType(f.func_code, f.func_globals, name,
f.func_defaults, f.func_closure)
newf.__doc__ = doc
return newf
if __name__ == '__main__': if __name__ == '__main__':
import sys, doctest import sys, doctest
doctest.testmod(sys.modules['__main__']) doctest.testmod(sys.modules['__main__'])
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: