##// END OF EJS Templates
i1673 some DRY refactoring
Justyna Ilczuk -
Show More
@@ -936,6 +936,31 b' class VerboseTB(TBTools):'
936 exception.append('\n%s%s = %s' % (indent, name, value))
936 exception.append('\n%s%s = %s' % (indent, name, value))
937 return exception
937 return exception
938
938
939 def format_exception_as_a_whole(self, etype, evalue, etb, number_of_lines_of_context, tb_offset):
940 # some locals
941 try:
942 etype = etype.__name__
943 except AttributeError:
944 pass
945
946 tb_offset = self.tb_offset if tb_offset is None else tb_offset
947 head = self.prepare_header(etype, self.long_header)
948 records = self.get_records(etb, number_of_lines_of_context, tb_offset)
949
950 frames = self.format_records(records)
951 if records is None:
952 return ""
953
954 formatted_exception = self.format_exception(etype, evalue)
955 if records:
956 filepath, lnum = records[-1][1:3]
957 filepath = os.path.abspath(filepath)
958 ipinst = get_ipython()
959 if ipinst is not None:
960 ipinst.hooks.synchronize_with_editor(filepath, lnum, 0)
961
962 return [[head] + frames + [''.join(formatted_exception[0])]]
963
939 def get_records(self, etb, number_of_lines_of_context, tb_offset):
964 def get_records(self, etb, number_of_lines_of_context, tb_offset):
940 try:
965 try:
941 # Try the default getinnerframes and Alex's: Alex's fixes some
966 # Try the default getinnerframes and Alex's: Alex's fixes some
@@ -956,13 +981,13 b' class VerboseTB(TBTools):'
956 return None
981 return None
957
982
958 def get_exception_from_context(self, evalue):
983 def get_exception_from_context(self, evalue):
959 if hasattr(evalue, '__context__'): # and not evalue.__suppress_context__:
984 if hasattr(evalue, '__context__') and not evalue.__suppress_context__:
960 context = evalue.__context__
985 context = evalue.__context__
961 if not context:
986 if not context:
962 return None
987 return None
963 else:
988 else:
964 exception_traceback = context.__traceback__
989 exception_traceback = context.__traceback__
965 exception_type = context.__class__.__name__
990 exception_type = context.__class__
966 return exception_type, context, exception_traceback
991 return exception_type, context, exception_traceback
967 else:
992 else:
968 return None
993 return None
@@ -970,62 +995,30 b' class VerboseTB(TBTools):'
970 def structured_traceback(self, etype, evalue, etb, tb_offset=None,
995 def structured_traceback(self, etype, evalue, etb, tb_offset=None,
971 number_of_lines_of_context=5):
996 number_of_lines_of_context=5):
972 """Return a nice text document describing the traceback."""
997 """Return a nice text document describing the traceback."""
973 tb_offset = self.tb_offset if tb_offset is None else tb_offset
974
998
975 # some locals
976 try:
977 etype = etype.__name__
978 except AttributeError:
979 pass
980
999
981 structured_traceback_parts = []
1000 structured_traceback_parts = []
982
1001
983 exceptions = []
984 current_exception_value = evalue
985 if py3compat.PY3:
1002 if py3compat.PY3:
986 while current_exception_value:
1003 formatted_exceptions = []
987 head = self.prepare_header(etype, self.long_header)
1004 while evalue:
988 records = self.get_records(etb, number_of_lines_of_context, tb_offset)
1005 formatted_exceptions += self.format_exception_as_a_whole(etype, evalue, etb, number_of_lines_of_context,
989
1006 tb_offset)
990 frames = self.format_records(records)
1007 exception = self.get_exception_from_context(evalue)
991 if records is None:
992 return ""
993
994 formatted_exception = self.format_exception(etype, current_exception_value)
995 if records:
996 filepath, lnum = records[-1][1:3]
997 filepath = os.path.abspath(filepath)
998 ipinst = get_ipython()
999 if ipinst is not None:
1000 ipinst.hooks.synchronize_with_editor(filepath, lnum, 0)
1001
1002 exceptions += [[head] + frames + [''.join(formatted_exception[0])]]
1003
1004 exception = self.get_exception_from_context(current_exception_value)
1005 if exception:
1008 if exception:
1006 exceptions += self.prepare_chained_exception_message(current_exception_value.__cause__)
1009 formatted_exceptions += self.prepare_chained_exception_message(evalue.__cause__)
1007 etype, current_exception_value, etb = exception
1010 etype, evalue, etb = exception
1008 else:
1011 else:
1009 break
1012 evalue = None
1010
1013
1011 for exception in reversed(exceptions):
1014 # we want to see exceptions in a reversed order:
1012 structured_traceback_parts += exception
1015 # the first exception should be on top
1016 for formatted_exception in reversed(formatted_exceptions):
1017 structured_traceback_parts += formatted_exception
1013 else:
1018 else:
1014 head = self.prepare_header(etype, self.long_header)
1019 formatted_exception = self.format_exception_as_a_whole(etype, evalue, etb, number_of_lines_of_context,
1015 records = self.get_records(etb, number_of_lines_of_context, tb_offset)
1020 tb_offset)
1016
1021 structured_traceback_parts.append(formatted_exception)
1017 frames = self.format_records(records)
1018 if records is None:
1019 return ""
1020
1021 exception = self.format_exception(etype, evalue)
1022 if records:
1023 filepath, lnum = records[-1][1:3]
1024 filepath = os.path.abspath(filepath)
1025 ipinst = get_ipython()
1026 if ipinst is not None:
1027 ipinst.hooks.synchronize_with_editor(filepath, lnum, 0)
1028 structured_traceback_parts.append([head] + frames + [''.join(exception[0])])
1029
1022
1030 return structured_traceback_parts
1023 return structured_traceback_parts
1031
1024
@@ -1323,8 +1316,6 b' def nullrepr(value, repr=text_repr):'
1323 return ''
1316 return ''
1324
1317
1325
1318
1326
1327
1328 #----------------------------------------------------------------------------
1319 #----------------------------------------------------------------------------
1329
1320
1330 # module testing (minimal)
1321 # module testing (minimal)
General Comments 0
You need to be logged in to leave comments. Login now