MCPcopy Create free account
hub / github.com/ipython/ipython / format_record

Method format_record

IPython/core/ultratb.py:919–1094  ·  view source on GitHub ↗

Format a single stack frame

(self, frame, file, lnum, func, lines, index)

Source from the content-addressed store, hash-verified

917 return frames
918
919 def format_record(self, frame, file, lnum, func, lines, index):
920 """Format a single stack frame"""
921 Colors = self.Colors # just a shorthand + quicker name lookup
922 ColorsNormal = Colors.Normal # used a lot
923 col_scheme = self.color_scheme_table.active_scheme_name
924 indent = ' ' * INDENT_SIZE
925 em_normal = '%s\n%s%s' % (Colors.valEm, indent, ColorsNormal)
926 undefined = '%sundefined%s' % (Colors.em, ColorsNormal)
927 tpl_link = '%s%%s%s' % (Colors.filenameEm, ColorsNormal)
928 tpl_call = 'in %s%%s%s%%s%s' % (Colors.vName, Colors.valEm,
929 ColorsNormal)
930 tpl_call_fail = 'in %s%%s%s(***failed resolving arguments***)%s' % \
931 (Colors.vName, Colors.valEm, ColorsNormal)
932 tpl_local_var = '%s%%s%s' % (Colors.vName, ColorsNormal)
933 tpl_global_var = '%sglobal%s %s%%s%s' % (Colors.em, ColorsNormal,
934 Colors.vName, ColorsNormal)
935 tpl_name_val = '%%s %s= %%s%s' % (Colors.valEm, ColorsNormal)
936
937 if not file:
938 file = '?'
939 elif file.startswith(str("<")) and file.endswith(str(">")):
940 # Not a real filename, no problem...
941 pass
942 elif not os.path.isabs(file):
943 # Try to make the filename absolute by trying all
944 # sys.path entries (which is also what linecache does)
945 for dirname in sys.path:
946 try:
947 fullname = os.path.join(dirname, file)
948 if os.path.isfile(fullname):
949 file = os.path.abspath(fullname)
950 break
951 except Exception:
952 # Just in case that sys.path contains very
953 # strange entries...
954 pass
955
956 file = py3compat.cast_unicode(file, util_path.fs_encoding)
957 link = tpl_link % util_path.compress_user(file)
958 args, varargs, varkw, locals_ = inspect.getargvalues(frame)
959
960 if func == '?':
961 call = ''
962 elif func == '<module>':
963 call = tpl_call % (func, '')
964 else:
965 # Decide whether to include variable details or not
966 var_repr = eqrepr if self.include_vars else nullrepr
967 try:
968 call = tpl_call % (func, inspect.formatargvalues(args,
969 varargs, varkw,
970 locals_, formatvalue=var_repr))
971 except KeyError:
972 # This happens in situations like errors inside generator
973 # expressions, where local variables are listed in the
974 # line, but can't be extracted from the frame. I'm not
975 # 100% sure this isn't actually a bug in inspect itself,
976 # but since there's no info for us to compute with, the

Callers 1

format_recordsMethod · 0.95

Calls 3

uniq_stableFunction · 0.90
generate_tokensFunction · 0.85
_format_traceback_linesFunction · 0.85

Tested by

no test coverage detected