Skip to content

Commit 2036e8f

Browse files
[py] Remove the use of basestring
Basestring is used for python 2 so removing as it is effectively dead code.
1 parent 2985a8e commit 2036e8f

File tree

7 files changed

+11
-52
lines changed

7 files changed

+11
-52
lines changed

py/selenium/webdriver/common/utils.py

+1-8
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,7 @@
2121
import socket
2222
from selenium.webdriver.common.keys import Keys
2323

24-
try:
25-
# Python 2
26-
basestring
27-
_is_connectable_exceptions = (socket.error,)
28-
except NameError:
29-
# Python 3
30-
basestring = str
31-
_is_connectable_exceptions = (socket.error, ConnectionResetError)
24+
_is_connectable_exceptions = (socket.error, ConnectionResetError)
3225

3326

3427
def free_port():

py/selenium/webdriver/firefox/webdriver.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@
1414
# KIND, either express or implied. See the License for the
1515
# specific language governing permissions and limitations
1616
# under the License.
17-
try:
18-
basestring
19-
except NameError: # Python 3.x
20-
basestring = str
2117

2218
from base64 import b64decode
2319
from shutil import rmtree
@@ -154,12 +150,12 @@ def __init__(self, firefox_profile=None, firefox_binary=None,
154150
# firefox_binary and firefox_profile
155151
# override options
156152
if firefox_binary:
157-
if isinstance(firefox_binary, basestring):
153+
if isinstance(firefox_binary, str):
158154
firefox_binary = FirefoxBinary(firefox_binary)
159155
self.binary = firefox_binary
160156
options.binary = firefox_binary
161157
if firefox_profile:
162-
if isinstance(firefox_profile, basestring):
158+
if isinstance(firefox_profile, str):
163159
firefox_profile = FirefoxProfile(firefox_profile)
164160
self.profile = firefox_profile
165161
options.profile = firefox_profile

py/selenium/webdriver/remote/errorhandler.py

+4-9
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,6 @@
4444
UnknownMethodException,
4545
WebDriverException)
4646

47-
try:
48-
basestring
49-
except NameError: # Python 3.x
50-
basestring = str
51-
5247

5348
class ErrorCode(object):
5449
"""
@@ -119,7 +114,7 @@ def check_response(self, response):
119114
stacktrace = None
120115
if isinstance(status, int):
121116
value_json = response.get('value', None)
122-
if value_json and isinstance(value_json, basestring):
117+
if value_json and isinstance(value_json, str):
123118
import json
124119
try:
125120
value = json.loads(value_json)
@@ -129,7 +124,7 @@ def check_response(self, response):
129124
if not status:
130125
status = value["status"]
131126
message = value["value"]
132-
if not isinstance(message, basestring):
127+
if not isinstance(message, str):
133128
value = message
134129
message = message.get('message')
135130
else:
@@ -201,7 +196,7 @@ def check_response(self, response):
201196
exception_class = WebDriverException
202197
if not value:
203198
value = response['value']
204-
if isinstance(value, basestring):
199+
if isinstance(value, str):
205200
raise exception_class(value)
206201
if message == "" and 'message' in value:
207202
message = value['message']
@@ -213,7 +208,7 @@ def check_response(self, response):
213208
stacktrace = None
214209
st_value = value.get('stackTrace') or value.get('stacktrace')
215210
if st_value:
216-
if isinstance(st_value, basestring):
211+
if isinstance(st_value, str):
217212
stacktrace = st_value.split('\n')
218213
else:
219214
stacktrace = []

py/selenium/webdriver/remote/switch_to.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@
2020
from selenium.webdriver.common.by import By
2121
from selenium.common.exceptions import NoSuchElementException, NoSuchFrameException, NoSuchWindowException
2222

23-
try:
24-
basestring
25-
except NameError:
26-
basestring = str
27-
2823

2924
class SwitchTo:
3025
def __init__(self, driver):
@@ -85,7 +80,7 @@ def frame(self, frame_reference):
8580
driver.switch_to.frame(1)
8681
driver.switch_to.frame(driver.find_elements(By.TAG_NAME, "iframe")[0])
8782
"""
88-
if isinstance(frame_reference, basestring) and self._driver.w3c:
83+
if isinstance(frame_reference, str) and self._driver.w3c:
8984
try:
9085
frame_reference = self._driver.find_element(By.ID, frame_reference)
9186
except NoSuchElementException:

py/selenium/webdriver/remote/webdriver.py

-5
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,6 @@
4949

5050
from six import add_metaclass
5151

52-
try:
53-
str = basestring
54-
except NameError:
55-
pass
56-
5752

5853
_W3C_CAPABILITY_NAMES = frozenset([
5954
'acceptInsecureCerts',

py/selenium/webdriver/remote/webelement.py

+1-12
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# under the License.
1717

1818
import os
19-
from base64 import b64decode
19+
from base64 import b64decode, encodebytes
2020
from hashlib import md5 as md5_hash
2121
import pkgutil
2222
import warnings
@@ -31,17 +31,6 @@
3131

3232
from six import add_metaclass
3333

34-
# Python 3 imports
35-
try:
36-
str = basestring
37-
except NameError:
38-
pass
39-
40-
try:
41-
from base64 import encodebytes
42-
except ImportError: # Python 2
43-
from base64 import encodestring as encodebytes
44-
4534

4635
# TODO: when dropping Python 2.7, use built in importlib_resources.files
4736
# not relying on __package__ here as it can be `None` in some situations (see #4558)

py/test/selenium/webdriver/marionette/mn_options_tests.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@
1717

1818
import pytest
1919

20-
try:
21-
basestring
22-
except NameError: # Python 3.x
23-
basestring = str
2420

2521
from selenium.webdriver.common.by import By
2622
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
@@ -110,7 +106,7 @@ def test_to_capabilities(self):
110106
caps = opts.to_capabilities()
111107
assert "moz:firefoxOptions" in caps
112108
assert "profile" in caps["moz:firefoxOptions"]
113-
assert isinstance(caps["moz:firefoxOptions"]["profile"], basestring)
109+
assert isinstance(caps["moz:firefoxOptions"]["profile"], str)
114110
assert caps["moz:firefoxOptions"]["profile"] == profile.encoded
115111

116112
opts.add_argument("--foo")
@@ -124,7 +120,7 @@ def test_to_capabilities(self):
124120
caps = opts.to_capabilities()
125121
assert "moz:firefoxOptions" in caps
126122
assert "binary" in caps["moz:firefoxOptions"]
127-
assert isinstance(caps["moz:firefoxOptions"]["binary"], basestring)
123+
assert isinstance(caps["moz:firefoxOptions"]["binary"], str)
128124
assert caps["moz:firefoxOptions"]["binary"] == binary._start_cmd
129125

130126
opts.set_preference("spam", "ham")

0 commit comments

Comments
 (0)