00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 import inspect
00022 import lsm
00023
00024 nesting = 0
00025 visited_module = {}
00026 visited_class = {'ABCMeta': True}
00027 visited_function = {}
00028
00029
00030 def o_p(msg):
00031 print("%s%s" % (' ' * nesting, msg))
00032
00033
00034 def handle_data(c, a):
00035 d = getattr(c, a[0])
00036 o_p("DATA: %s %s %s" % (a[0], type(d), a[3]))
00037
00038
00039 def handle_property(c, a):
00040 o_p("PROPERTY: %s" % (a[0]))
00041
00042
00043 def handle_method(c, a):
00044 o_p("%s: %s %s" % (a[1].upper(), a[0],
00045 inspect.getargspec(getattr(c, a[0]))))
00046
00047
00048 def handle_other(c, a):
00049 o_p("OTHER: %s: %s" % (a[0], a[1]))
00050
00051
00052 f_map = {'data': handle_data,
00053 'property': handle_property,
00054 'method': handle_method,
00055 'static method': handle_method}
00056
00057
00058 def h_class(c):
00059
00060 global nesting
00061
00062 nesting += 4
00063
00064 info = [x for x in inspect.classify_class_attrs(c)
00065 if not x[0].startswith('_')]
00066
00067 s = sorted(info, key=lambda x: (x[1], x[0]))
00068
00069 for i in s:
00070 if i[1] in f_map:
00071 f_map[i[1]](c, i)
00072 else:
00073 handle_other(c, i)
00074
00075 nesting -= 4
00076
00077
00078 def h_module(mod):
00079 global nesting
00080 global visited_module
00081 global visited_class
00082 global visited_function
00083
00084 if str(mod.__name__) in visited_module:
00085 return
00086 else:
00087 visited_module[str(mod.__name__)] = True
00088
00089 class_list = [x for x in inspect.getmembers(mod, inspect.isclass)
00090 if not x[0].startswith('_')]
00091
00092 function_list = [x for x in inspect.getmembers(mod, inspect.isfunction)
00093 if not x[0].startswith('_')]
00094
00095 module_list = [x for x in inspect.getmembers(mod, inspect.ismodule)
00096 if not x[0].startswith('_')]
00097
00098 print '%sModule: %s' % (' ' * nesting, str(mod.__name__))
00099 nesting += 4
00100 for m in function_list:
00101 if not m[0] in visited_function:
00102 visited_function[m[0]] = True
00103 print '%sf: %s' % (' ' * nesting, m[0])
00104
00105 nesting -= 4
00106
00107 for c in class_list:
00108 if not c[0] in visited_class:
00109 visited_class[c[0]] = True
00110 nesting += 4
00111 print '%sClass: %s' % (' ' * nesting, c[0])
00112 h_class(c[1])
00113 nesting -= 4
00114
00115 for m in module_list:
00116 h_module(m[1])
00117
00118 if __name__ == '__main__':
00119 h_module(lsm)