Show More
@@ -61,7 +61,7 b' from IPython.utils.path import get_home_dir, get_ipython_dir, HomeDirError' | |||
|
61 | 61 | from IPython.utils.process import system, getoutput |
|
62 | 62 | from IPython.utils.strdispatch import StrDispatch |
|
63 | 63 | from IPython.utils.syspathcontext import prepended_to_syspath |
|
64 | from IPython.utils.text import num_ini_spaces | |
|
64 | from IPython.utils.text import num_ini_spaces, format_screen | |
|
65 | 65 | from IPython.utils.traitlets import (Int, Str, CBool, CaselessStrEnum, Enum, |
|
66 | 66 | List, Unicode, Instance, Type) |
|
67 | 67 | from IPython.utils.warn import warn, error, fatal |
@@ -1036,7 +1036,15 b' class InteractiveShell(Configurable, Magic):' | |||
|
1036 | 1036 | |
|
1037 | 1037 | Has special code to detect magic functions. |
|
1038 | 1038 | """ |
|
1039 | oname = oname.strip() | |
|
1039 | #oname = oname.strip() | |
|
1040 | #print '1- oname: <%r>' % oname # dbg | |
|
1041 | try: | |
|
1042 | oname = oname.strip().encode('ascii') | |
|
1043 | #print '2- oname: <%r>' % oname # dbg | |
|
1044 | except UnicodeEncodeError: | |
|
1045 | print 'Python identifiers can only contain ascii characters.' | |
|
1046 | return dict(found=False) | |
|
1047 | ||
|
1040 | 1048 | alias_ns = None |
|
1041 | 1049 | if namespaces is None: |
|
1042 | 1050 | # Namespaces to search in: |
@@ -1105,32 +1113,13 b' class InteractiveShell(Configurable, Magic):' | |||
|
1105 | 1113 | obj = eval(oname_head) |
|
1106 | 1114 | found = True |
|
1107 | 1115 | ospace = 'Interactive' |
|
1108 | ||
|
1116 | ||
|
1109 | 1117 | return {'found':found, 'obj':obj, 'namespace':ospace, |
|
1110 | 1118 | 'ismagic':ismagic, 'isalias':isalias, 'parent':parent} |
|
1111 | 1119 | |
|
1112 |
def _ |
|
|
1113 | """Generic interface to the inspector system. | |
|
1114 | ||
|
1115 | This function is meant to be called by pdef, pdoc & friends.""" | |
|
1116 | ||
|
1117 | #oname = oname.strip() | |
|
1118 | #print '1- oname: <%r>' % oname # dbg | |
|
1119 | try: | |
|
1120 | oname = oname.strip().encode('ascii') | |
|
1121 | #print '2- oname: <%r>' % oname # dbg | |
|
1122 | except UnicodeEncodeError: | |
|
1123 | print 'Python identifiers can only contain ascii characters.' | |
|
1124 | return 'not found' | |
|
1125 | ||
|
1126 | info = Struct(self._ofind(oname, namespaces)) | |
|
1127 | ||
|
1120 | def _ofind_property(self, oname, info): | |
|
1121 | """Second part of object finding, to look for property details.""" | |
|
1128 | 1122 | if info.found: |
|
1129 | try: | |
|
1130 | IPython.utils.generics.inspect_object(info.obj) | |
|
1131 | return | |
|
1132 | except TryNext: | |
|
1133 | pass | |
|
1134 | 1123 | # Get the docstring of the class property if it exists. |
|
1135 | 1124 | path = oname.split('.') |
|
1136 | 1125 | root = '.'.join(path[:-1]) |
@@ -1146,18 +1135,36 b' class InteractiveShell(Configurable, Magic):' | |||
|
1146 | 1135 | info = Struct(self._ofind(oname)) |
|
1147 | 1136 | except AttributeError: pass |
|
1148 | 1137 | except AttributeError: pass |
|
1149 | ||
|
1150 | pmethod = getattr(self.inspector,meth) | |
|
1151 | formatter = info.ismagic and self.format_screen or None | |
|
1138 | ||
|
1139 | # We return either the new info or the unmodified input if the object | |
|
1140 | # hadn't been found | |
|
1141 | return info | |
|
1142 | ||
|
1143 | def _object_find(self, oname, namespaces=None): | |
|
1144 | """Find an object and return a struct with info about it.""" | |
|
1145 | inf = Struct(self._ofind(oname, namespaces)) | |
|
1146 | return Struct(self._ofind_property(oname, inf)) | |
|
1147 | ||
|
1148 | def _inspect(self, meth, oname, namespaces=None, **kw): | |
|
1149 | """Generic interface to the inspector system. | |
|
1150 | ||
|
1151 | This function is meant to be called by pdef, pdoc & friends.""" | |
|
1152 | info = self._object_find(oname) | |
|
1153 | if info.found: | |
|
1154 | pmethod = getattr(self.inspector, meth) | |
|
1155 | formatter = format_screen if info.ismagic else None | |
|
1152 | 1156 | if meth == 'pdoc': |
|
1153 | pmethod(info.obj,oname,formatter) | |
|
1157 | pmethod(info.obj, oname, formatter) | |
|
1154 | 1158 | elif meth == 'pinfo': |
|
1155 | pmethod(info.obj,oname,formatter,info,**kw) | |
|
1159 | pmethod(info.obj, oname, formatter, info, **kw) | |
|
1156 | 1160 | else: |
|
1157 | pmethod(info.obj,oname) | |
|
1161 | pmethod(info.obj, oname) | |
|
1158 | 1162 | else: |
|
1159 | 1163 | print 'Object `%s` not found.' % oname |
|
1160 | 1164 | return 'not found' # so callers can take other action |
|
1165 | ||
|
1166 | def object_inspect(self, oname): | |
|
1167 | info = self._object_find(oname) | |
|
1161 | 1168 | |
|
1162 | 1169 | #------------------------------------------------------------------------- |
|
1163 | 1170 | # Things related to history management |
@@ -62,7 +62,7 b' import IPython.utils.io' | |||
|
62 | 62 | from IPython.utils.path import get_py_filename |
|
63 | 63 | from IPython.utils.process import arg_split, abbrev_cwd |
|
64 | 64 | from IPython.utils.terminal import set_term_title |
|
65 | from IPython.utils.text import LSString, SList, StringTypes | |
|
65 | from IPython.utils.text import LSString, SList, StringTypes, format_screen | |
|
66 | 66 | from IPython.utils.timing import clock, clock2 |
|
67 | 67 | from IPython.utils.warn import warn, error |
|
68 | 68 | from IPython.utils.ipstruct import Struct |
@@ -240,15 +240,6 b' python-profiler package from non-free.""")' | |||
|
240 | 240 | strng = newline_re.sub(r'\\textbackslash{}n',strng) |
|
241 | 241 | return strng |
|
242 | 242 | |
|
243 | def format_screen(self,strng): | |
|
244 | """Format a string for screen printing. | |
|
245 | ||
|
246 | This removes some latex-type format codes.""" | |
|
247 | # Paragraph continue | |
|
248 | par_re = re.compile(r'\\$',re.MULTILINE) | |
|
249 | strng = par_re.sub('',strng) | |
|
250 | return strng | |
|
251 | ||
|
252 | 243 | def parse_options(self,arg_str,opt_str,*long_opts,**kw): |
|
253 | 244 | """Parse options passed to an argument string. |
|
254 | 245 | |
@@ -387,7 +378,7 b' python-profiler package from non-free.""")' | |||
|
387 | 378 | print self.format_latex(magic_docs) |
|
388 | 379 | return |
|
389 | 380 | else: |
|
390 |
magic_docs = |
|
|
381 | magic_docs = format_screen(magic_docs) | |
|
391 | 382 | if mode == 'brief': |
|
392 | 383 | return magic_docs |
|
393 | 384 | |
@@ -585,8 +576,8 b' Currently the magic system has the following functions:\\n"""' | |||
|
585 | 576 | if "*" in oname: |
|
586 | 577 | self.magic_psearch(oname) |
|
587 | 578 | else: |
|
588 | self._inspect('pinfo', oname, detail_level=detail_level, | |
|
589 | namespaces=namespaces) | |
|
579 | self.shell._inspect('pinfo', oname, detail_level=detail_level, | |
|
580 | namespaces=namespaces) | |
|
590 | 581 | |
|
591 | 582 | def magic_pdef(self, parameter_s='', namespaces=None): |
|
592 | 583 | """Print the definition header for any callable object. |
@@ -200,7 +200,7 b' class Inspector:' | |||
|
200 | 200 | self.str_detail_level = str_detail_level |
|
201 | 201 | self.set_active_scheme(scheme) |
|
202 | 202 | |
|
203 |
def |
|
|
203 | def _getdef(self,obj,oname=''): | |
|
204 | 204 | """Return the definition header for any callable object. |
|
205 | 205 | |
|
206 | 206 | If any exception is generated, None is returned instead and the |
@@ -245,7 +245,7 b' class Inspector:' | |||
|
245 | 245 | elif type(obj) is types.InstanceType: |
|
246 | 246 | obj = obj.__call__ |
|
247 | 247 | |
|
248 |
output = self. |
|
|
248 | output = self._getdef(obj,oname) | |
|
249 | 249 | if output is None: |
|
250 | 250 | self.noinfo('definition header',oname) |
|
251 | 251 | else: |
@@ -438,7 +438,7 b' class Inspector:' | |||
|
438 | 438 | binary_file = True |
|
439 | 439 | |
|
440 | 440 | # reconstruct the function definition and print it: |
|
441 |
defln = self. |
|
|
441 | defln = self._getdef(obj,oname) | |
|
442 | 442 | if defln: |
|
443 | 443 | out.write(header('Definition:\t')+self.format(defln)) |
|
444 | 444 | |
@@ -478,7 +478,7 b' class Inspector:' | |||
|
478 | 478 | except AttributeError: |
|
479 | 479 | init_def = init_ds = None |
|
480 | 480 | else: |
|
481 |
init_def = self. |
|
|
481 | init_def = self._getdef(obj_init,oname) | |
|
482 | 482 | init_ds = getdoc(obj_init) |
|
483 | 483 | # Skip Python's auto-generated docstrings |
|
484 | 484 | if init_ds and \ |
@@ -532,7 +532,7 b' class Inspector:' | |||
|
532 | 532 | # Call form docstring for callable instances |
|
533 | 533 | if hasattr(obj,'__call__'): |
|
534 | 534 | #out.writeln(header('Callable:\t')+'Yes') |
|
535 |
call_def = self. |
|
|
535 | call_def = self._getdef(obj.__call__,oname) | |
|
536 | 536 | #if call_def is None: |
|
537 | 537 | # out.writeln(header('Call def:\t')+ |
|
538 | 538 | # 'Calling definition not available.') |
@@ -487,3 +487,13 b' def num_ini_spaces(strng):' | |||
|
487 | 487 | else: |
|
488 | 488 | return 0 |
|
489 | 489 | |
|
490 | ||
|
491 | def format_screen(strng): | |
|
492 | """Format a string for screen printing. | |
|
493 | ||
|
494 | This removes some latex-type format codes.""" | |
|
495 | # Paragraph continue | |
|
496 | par_re = re.compile(r'\\$',re.MULTILINE) | |
|
497 | strng = par_re.sub('',strng) | |
|
498 | return strng | |
|
499 |
General Comments 0
You need to be logged in to leave comments.
Login now