Skip to content

Commit

Permalink
[py] remove py2 import code
Browse files Browse the repository at this point in the history
  • Loading branch information
AutomatedTester committed Oct 22, 2021
1 parent 5f57224 commit adeca5c
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 41 deletions.
18 changes: 5 additions & 13 deletions py/selenium/webdriver/common/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
from subprocess import DEVNULL

import errno
import os
Expand All @@ -24,12 +25,8 @@
from selenium.common.exceptions import WebDriverException
from selenium.webdriver.common import utils

try:
from subprocess import DEVNULL
_HAS_NATIVE_DEVNULL = True
except ImportError:
DEVNULL = -3
_HAS_NATIVE_DEVNULL = False

_HAS_NATIVE_DEVNULL = True


class Service(object):
Expand Down Expand Up @@ -119,13 +116,8 @@ def is_connectable(self):
return utils.is_connectable(self.port)

def send_remote_shutdown_command(self):
try:
from urllib import request as url_request
URLError = url_request.URLError
except ImportError:
import urllib2 as url_request
import urllib2
URLError = urllib2.URLError
from urllib import request as url_request
URLError = url_request.URLError

try:
url_request.urlopen("%s/shutdown" % self.service_url)
Expand Down
5 changes: 1 addition & 4 deletions py/selenium/webdriver/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,7 @@ def is_url_connectable(port: Union[int, str]) -> bool:
:Args:
- port - The port to connect.
"""
try:
from urllib import request as url_request
except ImportError:
import urllib2 as url_request # type: ignore # python2 stuff
from urllib import request as url_request

try:
res = url_request.urlopen("http://127.0.0.1:%s/status" % port)
Expand Down
6 changes: 2 additions & 4 deletions py/selenium/webdriver/safari/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@
# specific language governing permissions and limitations
# under the License.

try:
import http.client as http_client
except ImportError:
import httplib as http_client
import http.client as http_client


import warnings

Expand Down
6 changes: 2 additions & 4 deletions py/selenium/webdriver/webkitgtk/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@
# specific language governing permissions and limitations
# under the License.

try:
import http.client as http_client
except ImportError:
import httplib as http_client
import http.client as http_client


from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver
from .service import Service
Expand Down
6 changes: 2 additions & 4 deletions py/selenium/webdriver/wpewebkit/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@
# specific language governing permissions and limitations
# under the License.

try:
import http.client as http_client
except ImportError:
import httplib as http_client
import http.client as http_client


from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver
Expand Down
5 changes: 1 addition & 4 deletions py/test/selenium/webdriver/common/window_switching_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@
def close_windows(driver):
main_windows_handle = driver.current_window_handle
yield
try:
from urllib import request as url_request
except ImportError:
import urllib2 as url_request
from urllib import request as url_request
URLError = url_request.URLError

try:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@
# specific language governing permissions and limitations
# under the License.

try:
from io import BytesIO
except ImportError:
from cStringIO import StringIO as BytesIO

from io import BytesIO

import pytest

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@
import urllib3
import pytest

try:
from urllib import parse
except ImportError: # above is available in py3+, below is py2.7
import urlparse as parse

from urllib import parse


from selenium import __version__
from selenium.webdriver.remote.remote_connection import (
Expand Down

0 comments on commit adeca5c

Please sign in to comment.