summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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,