summaryrefslogtreecommitdiff
path: root/bs4
diff options
context:
space:
mode:
authorLeonard Richardson <leonardr@segfault.org>2018-07-14 16:18:43 -0400
committerLeonard Richardson <leonardr@segfault.org>2018-07-14 16:18:43 -0400
commit932a4a73b204ab44376a3d4294499168f47d3044 (patch)
tree82199989c5b335d41030315040976c6e6bc893ee /bs4
parent670ecfdeb3b315cf05777e6bd361539a21604907 (diff)
downloadbeautifulsoup4-932a4a73b204ab44376a3d4294499168f47d3044.tar.gz
Improve the technique for finding the line number with the problematic method call.
Diffstat (limited to 'bs4')
-rw-r--r--bs4/__init__.py16
1 files changed, 13 insertions, 3 deletions
diff --git a/bs4/__init__.py b/bs4/__init__.py
index e184cce..297e4b7 100644
--- a/bs4/__init__.py
+++ b/bs4/__init__.py
@@ -29,6 +29,7 @@ __all__ = ['BeautifulSoup']
import os
import re
+import sys
import traceback
import warnings
@@ -203,9 +204,18 @@ class BeautifulSoup(Tag):
else:
markup_type = "HTML"
- caller = traceback.extract_stack()[0]
- filename = caller[0]
- line_number = caller[1]
+ # This code taken from warnings.py so that we get the same line
+ # of code as our warnings.warn() call gets, even if the answer is wrong
+ # (as it may be in a multithreading situation).
+ try:
+ caller = sys._getframe(2)
+ except ValueError:
+ globals = sys.__dict__
+ lineno = 1
+ else:
+ globals = caller.f_globals
+ line_number = caller.f_lineno
+ filename = globals.get('__file__')
values = dict(
filename=filename,
line_number=line_number,