Skip to content

Commit f92f723

Browse files
authored
{Misc} Remove various Python 2.7 ImportError (#30451)
1 parent 731bd8d commit f92f723

File tree

25 files changed

+37
-135
lines changed

25 files changed

+37
-135
lines changed

scripts/curl_install_pypi/install.py

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,7 @@
2323
import shutil
2424
import subprocess
2525
import hashlib
26-
try:
27-
# Attempt to load python 3 module
28-
from urllib.request import urlopen
29-
except ImportError:
30-
# Import python 2 version
31-
from urllib2 import urlopen
32-
33-
try:
34-
# Rename raw_input to input to support Python 2
35-
input = raw_input
36-
except NameError:
37-
# Python 3 doesn't have raw_input
38-
pass
26+
from urllib.request import urlopen
3927

4028
AZ_DISPATCH_TEMPLATE = """#!/usr/bin/env bash
4129
{install_dir}/bin/python -m azure.cli "$@"

src/azure-cli-core/azure/cli/core/aaz/_operation.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55

66
# pylint: disable=too-few-public-methods, protected-access, too-many-nested-blocks, too-many-branches
77

8+
from urllib.parse import parse_qs, urljoin, urlparse, quote
89
import json
910

1011
from azure.core.exceptions import ClientAuthenticationError, ResourceExistsError, ResourceNotFoundError, \
1112
HttpResponseError
1213
from azure.cli.core.azclierror import InvalidArgumentValueError
13-
from urllib.parse import parse_qs, urljoin, urlparse
1414

1515
from ._arg_browser import AAZArgBrowser
1616
from ._base import AAZUndefined, AAZBaseValue, AAZBaseType, has_value
@@ -19,11 +19,6 @@
1919
from ._field_value import AAZList, AAZObject, AAZBaseDictValue
2020
from .exceptions import AAZInvalidValueError
2121

22-
try:
23-
from urllib import quote # type: ignore
24-
except ImportError:
25-
from urllib.parse import quote # type: ignore
26-
2722

2823
class AAZOperation:
2924

src/azure-cli-core/azure/cli/core/keys.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,7 @@ def is_valid_ssh_rsa_public_key(openssh_pubkey):
1616
# http://stackoverflow.com/questions/2494450/ssh-rsa-public-key-validation-using-a-regular-expression # pylint: disable=line-too-long
1717
# A "good enough" check is to see if the key starts with the correct header.
1818
import struct
19-
try:
20-
from base64 import decodebytes as base64_decode
21-
except ImportError:
22-
# deprecated and redirected to decodebytes in Python 3
23-
from base64 import decodestring as base64_decode
19+
from base64 import decodebytes as base64_decode
2420

2521
parts = openssh_pubkey.split()
2622
if len(parts) < 2:

src/azure-cli-telemetry/azure/cli/telemetry/__init__.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,9 @@ def _start(config_dir, cache_dir):
3737
startupinfo.wShowWindow = subprocess.SW_HIDE
3838
kwargs['startupinfo'] = startupinfo
3939
else:
40-
if sys.version_info >= (3, 3):
41-
kwargs['stdin'] = subprocess.DEVNULL
42-
kwargs['stdout'] = subprocess.DEVNULL
43-
kwargs['stderr'] = subprocess.STDOUT
40+
kwargs['stdin'] = subprocess.DEVNULL
41+
kwargs['stdout'] = subprocess.DEVNULL
42+
kwargs['stderr'] = subprocess.STDOUT
4443

4544
process = subprocess.Popen(**kwargs)
4645
logger.info('Return from creating process %s', process.pid)

src/azure-cli-telemetry/azure/cli/telemetry/components/telemetry_client.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,12 @@
66
import json
77
import datetime
88

9+
import urllib.request as http_client_t
10+
from urllib.error import HTTPError
11+
912
from applicationinsights import TelemetryClient
1013
from applicationinsights.channel import SynchronousSender, SynchronousQueue, TelemetryChannel
1114

12-
try:
13-
# Python 2.x
14-
import urllib2 as http_client_t
15-
from urllib2 import HTTPError
16-
except ImportError:
17-
# Python 3.x
18-
import urllib.request as http_client_t
19-
from urllib.error import HTTPError
20-
2115

2216
class CliTelemetryClient:
2317
def __init__(self, batch=100, sender=None):

src/azure-cli-telemetry/azure/cli/telemetry/tests/test_telemetry_client.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,13 @@
88
import os
99
import unittest
1010

11+
import urllib.request as http_client_t
12+
from urllib.error import HTTPError
13+
1114
from applicationinsights.channel import SynchronousSender
1215

13-
try:
14-
# Python 2.x
15-
import urllib2 as http_client_t
16-
from urllib2 import HTTPError
17-
except ImportError:
18-
# Python 3.x
19-
import urllib.request as http_client_t
20-
from urllib.error import HTTPError
2116

22-
from azure.cli.telemetry.components.telemetry_client import (CliTelemetryClient, _NoRetrySender, http_client_t)
17+
from azure.cli.telemetry.components.telemetry_client import CliTelemetryClient, _NoRetrySender
2318

2419
TEST_RESOURCE_FOLDER = os.path.join(os.path.dirname(__file__), 'resources')
2520

src/azure-cli/azure/cli/command_modules/acr/_docker_utils.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33
# Licensed under the MIT License. See License.txt in the project root for license information.
44
# --------------------------------------------------------------------------------------------
55

6-
try:
7-
from urllib.parse import urlencode, urlparse, urlunparse
8-
except ImportError:
9-
from urllib import urlencode
6+
from urllib.parse import urlencode, urlparse, urlunparse
107

118
import time
129
from json import loads

src/azure-cli/azure/cli/command_modules/acr/manifest.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@
55

66
from datetime import datetime, timedelta
77

8-
try:
9-
from urllib.parse import unquote
10-
except ImportError:
11-
from urllib import unquote
8+
from urllib.parse import unquote
129

1310
from knack.log import get_logger
1411
from azure.cli.core.util import user_confirmation

src/azure-cli/azure/cli/command_modules/acr/repository.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33
# Licensed under the MIT License. See License.txt in the project root for license information.
44
# --------------------------------------------------------------------------------------------
55

6-
try:
7-
from urllib.parse import unquote
8-
except ImportError:
9-
from urllib import unquote
6+
from urllib.parse import unquote
107

118
from knack.util import CLIError
129
from knack.log import get_logger

src/azure-cli/azure/cli/command_modules/acr/tests/hybrid_2020_09_01/test_acr_commands_mock.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33
# Licensed under the MIT License. See License.txt in the project root for license information.
44
# --------------------------------------------------------------------------------------------
55

6-
try:
7-
from urllib.parse import urlencode
8-
except ImportError:
9-
from urllib import urlencode
6+
from urllib.parse import urlencode
107
import json
118
import unittest
129
from unittest import mock

0 commit comments

Comments
 (0)