<s> """<STR_LIT>""" <EOL> import inspect <EOL> import sys <EOL> def name ( item ) : <EOL> "<STR_LIT>" <EOL> return item . __name__ <EOL> def is_classmethod ( instancemethod ) : <EOL> "<STR_LIT>" <EOL> return instancemethod . im_self is not None <EOL> def is_class_private_name ( name ) : <EOL> "<STR_LIT>" <EOL> return name . startswith ( "<STR_LIT>" ) and not name . endswith ( "<STR_LIT>" ) <EOL> def method_name ( method ) : <EOL> """<STR_LIT>""" <EOL> mname = name ( method ) <EOL> if is_class_private_name ( mname ) : <EOL> mname = "<STR_LIT>" % ( name ( method . im_class ) , mname ) <EOL> return mname <EOL> def format_arg_value ( arg_val ) : <EOL> """<STR_LIT>""" <EOL> arg , val = arg_val <EOL> return "<STR_LIT>" % ( arg , val ) <EOL> def echo ( fn , write = sys . stdout . write ) : <EOL> """<STR_LIT>""" <EOL> import functools <EOL> code = fn . func_code <EOL> argcount = code . co_argcount <EOL> argnames = code . co_varnames [ : argcount ] <EOL> fn_defaults = fn . func_defaults or list ( ) <EOL> argdefs = dict ( zip ( argnames [ - len ( fn_defaults ) : ] , fn_defaults ) ) <EOL> @ functools . wraps ( fn ) <EOL> def wrapped ( * v , ** k ) : <EOL> positional = map ( format_arg_value , zip ( argnames , v ) ) <EOL> defaulted = [ format_arg_value ( ( a , argdefs [ a ] ) ) <EOL> for a in argnames [ len ( v ) : ] if a not in k ] <EOL> nameless = map ( repr , v [ argcount : ] ) <EOL> keyword = map ( format_arg_value , k . items ( ) ) <EOL> args = positional + defaulted + nameless + keyword <EOL> write ( "<STR_LIT>" % ( name ( fn ) , "<STR_LIT:U+002CU+0020>" . join ( args ) ) ) <EOL> return fn ( * v , ** k ) <EOL> return wrapped <EOL> def echo_instancemethod ( klass , method , write = sys . stdout . write ) : <EOL> """<STR_LIT>""" <EOL> mname = method_name ( method ) <EOL> never_echo = "<STR_LIT>" , "<STR_LIT>" , <EOL> if mname in never_echo : <EOL> pass <EOL> elif is_classmethod ( method ) : <EOL> setattr ( klass , mname , classmethod ( echo ( method . im_func , write ) ) ) <EOL> else : <EOL> setattr ( klass , mname , echo ( method , write ) ) <EOL> def echo_class ( klass , write = sys . stdout . write ) : <EOL> """<STR_LIT>""" <EOL> for _ , method in inspect . getmembers ( klass , inspect . ismethod ) : <EOL> echo_instancemethod ( klass , method , write ) <EOL> for _ , fn in inspect . getmembers ( klass , inspect . isfunction ) : <EOL> setattr ( klass , name ( fn ) , staticmethod ( echo ( fn , write ) ) ) <EOL> def echo_module ( mod , write = sys . stdout . write ) : <EOL> """<STR_LIT>""" <EOL> for fname , fn in inspect . getmembers ( mod , inspect . isfunction ) : <EOL> setattr ( mod , fname , echo ( fn , write ) ) <EOL> for _ , klass in inspect . getmembers ( mod , inspect . isclass ) : <EOL> echo_class ( klass , write ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> import doctest <EOL> optionflags = doctest . ELLIPSIS <EOL> doctest . testfile ( '<STR_LIT>' , optionflags = optionflags ) <EOL> doctest . testmod ( optionflags = optionflags ) </s>
