# HG changeset patch # User John Mulligan # Date 1258227947 18000 # Sat Nov 14 14:45:47 2009 -0500 # Node ID 2bf99ffcf76587684e7ad07210cb22c33b881ff5 # Parent df6804af9b2dd75d8201484ce1256cf91a241356 extract frame check into function, usable by other modules diff --git a/vanity/commander.py b/vanity/commander.py --- a/vanity/commander.py +++ b/vanity/commander.py @@ -240,6 +240,13 @@ return opts +def firstframe(): + """returns true if the type error was caused by the first + function call in the stack + """ + return len(traceback.extract_tb(sys.exc_info()[2])) == 1 + + class Command(object): """A thin class representing a command. @@ -260,7 +267,7 @@ try: return self.target(*args, **opts) except TypeError, err: - if len(traceback.extract_tb(sys.exc_info()[2])) == 1: + if firstframe(): raise InvalidArguments(self.name) raise