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