@@ -594,8 +594,10 @@ def filename_for_module(module, abs_path):
594
594
return abs_path
595
595
596
596
597
- def serialize_frame (frame , tb_lineno = None , include_local_variables = True ):
598
- # type: (FrameType, Optional[int], bool) -> Dict[str, Any]
597
+ def serialize_frame (
598
+ frame , tb_lineno = None , include_local_variables = True , include_source_context = True
599
+ ):
600
+ # type: (FrameType, Optional[int], bool, bool) -> Dict[str, Any]
599
601
f_code = getattr (frame , "f_code" , None )
600
602
if not f_code :
601
603
abs_path = None
@@ -611,18 +613,24 @@ def serialize_frame(frame, tb_lineno=None, include_local_variables=True):
611
613
if tb_lineno is None :
612
614
tb_lineno = frame .f_lineno
613
615
614
- pre_context , context_line , post_context = get_source_context (frame , tb_lineno )
615
-
616
616
rv = {
617
617
"filename" : filename_for_module (module , abs_path ) or None ,
618
618
"abs_path" : os .path .abspath (abs_path ) if abs_path else None ,
619
619
"function" : function or "<unknown>" ,
620
620
"module" : module ,
621
621
"lineno" : tb_lineno ,
622
- "pre_context" : pre_context ,
623
- "context_line" : context_line ,
624
- "post_context" : post_context ,
625
622
} # type: Dict[str, Any]
623
+
624
+ if include_source_context :
625
+ pre_context , context_line , post_context = get_source_context (frame , tb_lineno )
626
+ rv .update (
627
+ {
628
+ "pre_context" : pre_context ,
629
+ "context_line" : context_line ,
630
+ "post_context" : post_context ,
631
+ }
632
+ )
633
+
626
634
if include_local_variables :
627
635
rv ["vars" ] = frame .f_locals
628
636
@@ -1240,7 +1248,6 @@ def sanitize_url(url, remove_authority=True, remove_query_values=True):
1240
1248
1241
1249
1242
1250
def parse_url (url , sanitize = True ):
1243
-
1244
1251
# type: (str, bool) -> ParsedUrl
1245
1252
"""
1246
1253
Splits a URL into a url (including path), query and fragment. If sanitize is True, the query
0 commit comments