Show More
@@ -24,13 +24,14 b" __all__ = ['Inspector','InspectColors']" | |||
|
24 | 24 | |
|
25 | 25 | # stdlib modules |
|
26 | 26 | import __builtin__ |
|
27 | import StringIO | |
|
27 | 28 | import inspect |
|
28 | 29 | import linecache |
|
29 | import string | |
|
30 | import StringIO | |
|
31 | import types | |
|
32 | 30 | import os |
|
31 | import string | |
|
33 | 32 | import sys |
|
33 | import types | |
|
34 | ||
|
34 | 35 | # IPython's own |
|
35 | 36 | from IPython import PyColorize |
|
36 | 37 | from IPython.genutils import page,indent,Term |
@@ -136,6 +137,7 b' def getdoc(obj):' | |||
|
136 | 137 | ds = '%s\n%s' % (ds,ds2) |
|
137 | 138 | return ds |
|
138 | 139 | |
|
140 | ||
|
139 | 141 | def getsource(obj,is_binary=False): |
|
140 | 142 | """Wrapper around inspect.getsource. |
|
141 | 143 | |
@@ -162,6 +164,26 b' def getsource(obj,is_binary=False):' | |||
|
162 | 164 | src = inspect.getsource(obj.__class__) |
|
163 | 165 | return src |
|
164 | 166 | |
|
167 | def getargspec(obj): | |
|
168 | """Get the names and default values of a function's arguments. | |
|
169 | ||
|
170 | A tuple of four things is returned: (args, varargs, varkw, defaults). | |
|
171 | 'args' is a list of the argument names (it may contain nested lists). | |
|
172 | 'varargs' and 'varkw' are the names of the * and ** arguments or None. | |
|
173 | 'defaults' is an n-tuple of the default values of the last n arguments. | |
|
174 | ||
|
175 | Modified version of inspect.getargspec from the Python Standard | |
|
176 | Library.""" | |
|
177 | ||
|
178 | if inspect.isfunction(obj): | |
|
179 | func_obj = obj | |
|
180 | elif inspect.ismethod(obj): | |
|
181 | func_obj = obj.im_func | |
|
182 | else: | |
|
183 | raise TypeError, 'arg is not a Python function' | |
|
184 | args, varargs, varkw = inspect.getargs(func_obj.func_code) | |
|
185 | return args, varargs, varkw, func_obj.func_defaults | |
|
186 | ||
|
165 | 187 | #**************************************************************************** |
|
166 | 188 | # Class definitions |
|
167 | 189 | |
@@ -172,6 +194,7 b' class myStringIO(StringIO.StringIO):' | |||
|
172 | 194 | self.write(*arg,**kw) |
|
173 | 195 | self.write('\n') |
|
174 | 196 | |
|
197 | ||
|
175 | 198 | class Inspector: |
|
176 | 199 | def __init__(self,color_table,code_color_table,scheme, |
|
177 | 200 | str_detail_level=0): |
@@ -181,26 +204,6 b' class Inspector:' | |||
|
181 | 204 | self.str_detail_level = str_detail_level |
|
182 | 205 | self.set_active_scheme(scheme) |
|
183 | 206 | |
|
184 | def __getargspec(self,obj): | |
|
185 | """Get the names and default values of a function's arguments. | |
|
186 | ||
|
187 | A tuple of four things is returned: (args, varargs, varkw, defaults). | |
|
188 | 'args' is a list of the argument names (it may contain nested lists). | |
|
189 | 'varargs' and 'varkw' are the names of the * and ** arguments or None. | |
|
190 | 'defaults' is an n-tuple of the default values of the last n arguments. | |
|
191 | ||
|
192 | Modified version of inspect.getargspec from the Python Standard | |
|
193 | Library.""" | |
|
194 | ||
|
195 | if inspect.isfunction(obj): | |
|
196 | func_obj = obj | |
|
197 | elif inspect.ismethod(obj): | |
|
198 | func_obj = obj.im_func | |
|
199 | else: | |
|
200 | raise TypeError, 'arg is not a Python function' | |
|
201 | args, varargs, varkw = inspect.getargs(func_obj.func_code) | |
|
202 | return args, varargs, varkw, func_obj.func_defaults | |
|
203 | ||
|
204 | 207 | def __getdef(self,obj,oname=''): |
|
205 | 208 | """Return the definition header for any callable object. |
|
206 | 209 | |
@@ -208,7 +211,7 b' class Inspector:' | |||
|
208 | 211 | exception is suppressed.""" |
|
209 | 212 | |
|
210 | 213 | try: |
|
211 |
return oname + inspect.formatargspec(* |
|
|
214 | return oname + inspect.formatargspec(*getargspec(obj)) | |
|
212 | 215 | except: |
|
213 | 216 | return None |
|
214 | 217 |
General Comments 0
You need to be logged in to leave comments.
Login now