##// END OF EJS Templates
change oinspect.py to be unicode safe
jstenar -
Show More
@@ -40,6 +40,7 b' from IPython.utils import py3compat'
40 from IPython.utils.text import indent
40 from IPython.utils.text import indent
41 from IPython.utils.wildcard import list_namespace
41 from IPython.utils.wildcard import list_namespace
42 from IPython.utils.coloransi import *
42 from IPython.utils.coloransi import *
43 from IPython.utils.py3compat import cast_unicode
43
44
44 #****************************************************************************
45 #****************************************************************************
45 # Builtin color schemes
46 # Builtin color schemes
@@ -144,7 +145,7 b' def getsource(obj,is_binary=False):'
144 except TypeError:
145 except TypeError:
145 if hasattr(obj,'__class__'):
146 if hasattr(obj,'__class__'):
146 src = inspect.getsource(obj.__class__)
147 src = inspect.getsource(obj.__class__)
147 return src
148 return cast_unicode(src)
148
149
149 def getargspec(obj):
150 def getargspec(obj):
150 """Get the names and default values of a function's arguments.
151 """Get the names and default values of a function's arguments.
@@ -320,9 +321,8 b' class Inspector:'
320 exception is suppressed."""
321 exception is suppressed."""
321
322
322 try:
323 try:
323 # We need a plain string here, NOT unicode!
324 hdef = oname + inspect.formatargspec(*getargspec(obj))
324 hdef = oname + inspect.formatargspec(*getargspec(obj))
325 return py3compat.unicode_to_str(hdef, 'ascii')
325 return cast_unicode(hdef)
326 except:
326 except:
327 return None
327 return None
328
328
@@ -436,7 +436,7 b' class Inspector:'
436 except:
436 except:
437 self.noinfo('source',oname)
437 self.noinfo('source',oname)
438 else:
438 else:
439 page.page(self.format(py3compat.unicode_to_str(src)))
439 page.page(self.format(src))
440
440
441 def pfile(self, obj, oname=''):
441 def pfile(self, obj, oname=''):
442 """Show the whole file where an object was defined."""
442 """Show the whole file where an object was defined."""
@@ -477,7 +477,7 b' class Inspector:'
477 title = header(title + ":") + "\n"
477 title = header(title + ":") + "\n"
478 else:
478 else:
479 title = header((title+":").ljust(title_width))
479 title = header((title+":").ljust(title_width))
480 out.append(title + content)
480 out.append(cast_unicode(title) + cast_unicode(content))
481 return "\n".join(out)
481 return "\n".join(out)
482
482
483 # The fields to be displayed by pinfo: (fancy_name, key_in_info_dict)
483 # The fields to be displayed by pinfo: (fancy_name, key_in_info_dict)
@@ -537,7 +537,8 b' class Inspector:'
537 # Source or docstring, depending on detail level and whether
537 # Source or docstring, depending on detail level and whether
538 # source found.
538 # source found.
539 if detail_level > 0 and info['source'] is not None:
539 if detail_level > 0 and info['source'] is not None:
540 displayfields.append(("Source", self.format(py3compat.cast_bytes_py2(info['source']))))
540 displayfields.append(("Source",
541 self.format(cast_unicode(info['source']))))
541 elif info['docstring'] is not None:
542 elif info['docstring'] is not None:
542 displayfields.append(("Docstring", info["docstring"]))
543 displayfields.append(("Docstring", info["docstring"]))
543
544
General Comments 0
You need to be logged in to leave comments. Login now