def __get_dynamic_attr(self, attname, arg, default=None):
try:<EOL><INDENT>attr = getattr(self, attname)<EOL><DEDENT>except AttributeError:<EOL><INDENT>return default<EOL><DEDENT>if callable(attr):<EOL><INDENT>if hasattr(attr, '<STR_LIT>'):<EOL><INDENT>argcount = attr.__code__.co_argcount<EOL><DEDENT>else:<EOL><INDENT>argcount = attr.__call__.__code__.co_argcount<EOL><DEDENT>if argcount == <NUM_LIT:2>: <EOL><INDENT>return attr(arg)<EOL><DEDENT>else:<EOL><INDENT>return attr()<EOL><DEDENT><DEDENT>return attr<EOL>
Gets "something" from self, which could be an attribute or
a callable with either 0 or 1 arguments (besides self).

Stolen from django.contrib.syntication.feeds.Feed.