@@ -449,6 +449,48 @@ def from_list(klass, a_list):
449449 result .append (FrameSummary (filename , lineno , name , line = line ))
450450 return result
451451
452+ def format_frame (self , frame ):
453+ """Format the lines for a single frame.
454+
455+ Returns a string representing one frame involved in the stack. This
456+ gets called for every frame to be printed in the stack summary.
457+ """
458+ row = []
459+ row .append (' File "{}", line {}, in {}\n ' .format (
460+ frame .filename , frame .lineno , frame .name ))
461+ if frame .line :
462+ row .append (' {}\n ' .format (frame .line .strip ()))
463+
464+ stripped_characters = len (frame ._original_line ) - len (frame .line .lstrip ())
465+ if frame .end_lineno == frame .lineno and frame .end_colno != 0 :
466+ colno = _byte_offset_to_character_offset (frame ._original_line , frame .colno )
467+ end_colno = _byte_offset_to_character_offset (frame ._original_line , frame .end_colno )
468+
469+ try :
470+ anchors = _extract_caret_anchors_from_line_segment (
471+ frame ._original_line [colno - 1 :end_colno - 1 ]
472+ )
473+ except Exception :
474+ anchors = None
475+
476+ row .append (' ' )
477+ row .append (' ' * (colno - stripped_characters ))
478+
479+ if anchors :
480+ row .append (anchors .primary_char * (anchors .left_end_offset ))
481+ row .append (anchors .secondary_char * (anchors .right_start_offset - anchors .left_end_offset ))
482+ row .append (anchors .primary_char * (end_colno - colno - anchors .right_start_offset ))
483+ else :
484+ row .append ('^' * (end_colno - colno ))
485+
486+ row .append ('\n ' )
487+
488+ if frame .locals :
489+ for name , value in sorted (frame .locals .items ()):
490+ row .append (' {name} = {value}\n ' .format (name = name , value = value ))
491+
492+ return '' .join (row )
493+
452494 def format (self ):
453495 """Format the stack ready for printing.
454496
@@ -483,40 +525,8 @@ def format(self):
483525 count += 1
484526 if count > _RECURSIVE_CUTOFF :
485527 continue
486- row = []
487- row .append (' File "{}", line {}, in {}\n ' .format (
488- frame .filename , frame .lineno , frame .name ))
489- if frame .line :
490- row .append (' {}\n ' .format (frame .line .strip ()))
491-
492- stripped_characters = len (frame ._original_line ) - len (frame .line .lstrip ())
493- if frame .end_lineno == frame .lineno and frame .end_colno != 0 :
494- colno = _byte_offset_to_character_offset (frame ._original_line , frame .colno )
495- end_colno = _byte_offset_to_character_offset (frame ._original_line , frame .end_colno )
496-
497- try :
498- anchors = _extract_caret_anchors_from_line_segment (
499- frame ._original_line [colno - 1 :end_colno - 1 ]
500- )
501- except Exception :
502- anchors = None
503-
504- row .append (' ' )
505- row .append (' ' * (colno - stripped_characters ))
506-
507- if anchors :
508- row .append (anchors .primary_char * (anchors .left_end_offset ))
509- row .append (anchors .secondary_char * (anchors .right_start_offset - anchors .left_end_offset ))
510- row .append (anchors .primary_char * (end_colno - colno - anchors .right_start_offset ))
511- else :
512- row .append ('^' * (end_colno - colno ))
513-
514- row .append ('\n ' )
515-
516- if frame .locals :
517- for name , value in sorted (frame .locals .items ()):
518- row .append (' {name} = {value}\n ' .format (name = name , value = value ))
519- result .append ('' .join (row ))
528+ result .append (self .format_frame (frame ))
529+
520530 if count > _RECURSIVE_CUTOFF :
521531 count -= _RECURSIVE_CUTOFF
522532 result .append (
0 commit comments