Skip to content

Commit bba4882

Browse files
committed
Improve compatibility on older versions of Python
1 parent 58ac219 commit bba4882

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

seleniumbase/fixtures/base_case.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ def test_anything(self):
5757
logging.getLogger("urllib3").setLevel(logging.ERROR)
5858
urllib3.disable_warnings()
5959
LOGGER.setLevel(logging.WARNING)
60+
if sys.version_info[0] < 3:
61+
reload(sys) # noqa: F821
62+
sys.setdefaultencoding("utf8")
6063

6164

6265
class BaseCase(unittest.TestCase):
@@ -3248,14 +3251,14 @@ def print_unique_links_with_status_codes(self):
32483251

32493252
def __fix_unicode_conversion(self, text):
32503253
""" Fixing Chinese characters when converting from PDF to HTML. """
3251-
if sys.version_info[0] < 3:
3252-
# Update encoding for Python 2 users
3253-
reload(sys) # noqa
3254-
sys.setdefaultencoding("utf8")
32553254
text = text.replace("\u2f8f", "\u884c")
32563255
text = text.replace("\u2f45", "\u65b9")
32573256
text = text.replace("\u2f08", "\u4eba")
32583257
text = text.replace("\u2f70", "\u793a")
3258+
text = text.replace("\xe2\xbe\x8f", "\xe8\xa1\x8c")
3259+
text = text.replace("\xe2\xbd\xb0", "\xe7\xa4\xba")
3260+
text = text.replace("\xe2\xbe\x8f", "\xe8\xa1\x8c")
3261+
text = text.replace("\xe2\xbd\x85", "\xe6\x96\xb9")
32593262
return text
32603263

32613264
def get_pdf_text(
@@ -8114,7 +8117,7 @@ def __recalculate_selector(self, selector, by, xp_ok=True):
81148117
_type = type(selector) # First make sure the selector is a string
81158118
not_string = False
81168119
if sys.version_info[0] < 3:
8117-
if _type is not str and _type is not unicode: # noqa
8120+
if _type is not str and _type is not unicode: # noqa: F821
81188121
not_string = True
81198122
else:
81208123
if _type is not str:

0 commit comments

Comments
 (0)