Skip to content

Commit 6a849ee

Browse files
committed
{Misc} Remove misc Python 2.7 fallbacks.
1 parent f92f723 commit 6a849ee

File tree

8 files changed

+12
-69
lines changed

8 files changed

+12
-69
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1391,7 +1391,7 @@ def test_helm_push(self, mock_requests_get, mock_get_access_credentials):
13911391

13921392
mock_get_access_credentials.return_value = 'testregistry.azurecr.io', EMPTY_GUID, 'password'
13931393

1394-
builtins_open = '__builtin__.open' if sys.version_info[0] < 3 else 'builtins.open'
1394+
builtins_open = 'builtins.open'
13951395

13961396
# Push a chart
13971397
with mock.patch(builtins_open) as mock_open:

src/azure-cli/azure/cli/command_modules/ams/tests/latest/test_ams_streaming_endpoint_scenarios.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
# --------------------------------------------------------------------------------------------
55

66
import os
7-
import sys
87

98
from azure.cli.core.util import CLIError
109
from azure.cli.testsdk import ScenarioTest, ResourceGroupPreparer, StorageAccountPreparer
@@ -383,8 +382,6 @@ def test_ams_streaming_endpoint_start_async(self, storage_account_for_create):
383382
@ResourceGroupPreparer()
384383
@StorageAccountPreparer(parameter_name='storage_account_for_create')
385384
def test_ams_streaming_endpoint_stop_async(self, storage_account_for_create):
386-
if sys.version_info.major == 2: # azure-cli/issues/9386
387-
return
388385
amsname = self.create_random_name(prefix='ams', length=12)
389386
streaming_endpoint_name = self.create_random_name(prefix="strep", length=12)
390387

src/azure-cli/azure/cli/command_modules/appconfig/tests/latest/test_appconfig_commands.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2016,7 +2016,7 @@ def test_azconfig_json_content_type(self, resource_group, location):
20162016
entry_feature = 'Beta'
20172017
internal_feature_key = FeatureFlagConstants.FEATURE_FLAG_PREFIX + entry_feature
20182018
default_description = ""
2019-
default_conditions = "{{u\'client_filters\': []}}" if sys.version_info[0] < 3 else "{{\'client_filters\': []}}"
2019+
default_conditions = "{{\'client_filters\': []}}"
20202020
default_locked = False
20212021
default_state = "off"
20222022
self.kwargs.update({
@@ -2201,7 +2201,7 @@ def test_azconfig_feature(self, resource_group, location):
22012201
internal_feature_key = FeatureFlagConstants.FEATURE_FLAG_PREFIX + entry_feature
22022202
entry_label = 'v1'
22032203
default_description = ""
2204-
default_conditions = "{{u\'client_filters\': []}}" if sys.version_info[0] < 3 else "{{\'client_filters\': []}}"
2204+
default_conditions = "{{\'client_filters\': []}}"
22052205
default_locked = False
22062206
default_state = "off"
22072207

@@ -2513,7 +2513,7 @@ def test_azconfig_feature_namespacing(self, resource_group, location):
25132513
feature_key = FeatureFlagConstants.FEATURE_FLAG_PREFIX + feature_prefix + feature_name
25142514
entry_label = 'v1'
25152515
default_description = ""
2516-
default_conditions = "{{u\'client_filters\': []}}" if sys.version_info[0] < 3 else "{{\'client_filters\': []}}"
2516+
default_conditions = "{{\'client_filters\': []}}"
25172517
default_locked = False
25182518
default_state = "off"
25192519

@@ -2618,7 +2618,7 @@ def test_azconfig_feature_filter(self, resource_group, location):
26182618
internal_feature_key = FeatureFlagConstants.FEATURE_FLAG_PREFIX + entry_feature
26192619
entry_label = 'Standard'
26202620
default_description = ""
2621-
default_conditions = "{{u\'client_filters\': []}}" if sys.version_info[0] < 3 else "{{\'client_filters\': []}}"
2621+
default_conditions = "{{\'client_filters\': []}}"
26222622
default_locked = False
26232623
default_state = "off"
26242624

@@ -2986,7 +2986,7 @@ def test_azconfig_aad_auth(self, resource_group, location):
29862986
entry_feature = 'Beta'
29872987
internal_feature_key = FeatureFlagConstants.FEATURE_FLAG_PREFIX + entry_feature
29882988
default_description = ""
2989-
default_conditions = "{{u\'client_filters\': []}}" if sys.version_info[0] < 3 else "{{\'client_filters\': []}}"
2989+
default_conditions = "{{\'client_filters\': []}}"
29902990
default_locked = False
29912991
default_state = "off"
29922992
self.kwargs.update({

src/azure-cli/azure/cli/command_modules/botservice/bot_json_formatter.py

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import base64
77
from collections import Counter
8-
import sys
98
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
109
from cryptography.hazmat.backends import default_backend
1110
from azure.cli.core._profile import Profile
@@ -107,10 +106,7 @@ def __decrypt_bot_file(bot_file_data, bot_file_secret, logger, password_only=Tru
107106
"""
108107
services = bot_file_data['services']
109108

110-
if sys.version_info.major >= 3:
111-
decrypt = BotJsonFormatter.__decrypt_py3
112-
else:
113-
decrypt = BotJsonFormatter.__decrypt_py2
109+
decrypt = BotJsonFormatter.__decrypt
114110

115111
if password_only:
116112
# Get all endpoints that have potentially valid appPassword values
@@ -171,7 +167,7 @@ def __decrypt_bot_file(bot_file_data, bot_file_secret, logger, password_only=Tru
171167
return services
172168

173169
@staticmethod
174-
def __decrypt_py3(secret, encrypted_value, logger):
170+
def __decrypt(secret, encrypted_value, logger):
175171
# If the string length is 0 or no secret was passed in, return the empty string.
176172
if not encrypted_value or not secret:
177173
return encrypted_value
@@ -199,33 +195,3 @@ def __decrypt_py3(secret, encrypted_value, logger):
199195

200196
decrypted_string = decrypted_bytes.decode('utf-8')
201197
return ''.join([char for char in decrypted_string if ord(char) > 31])
202-
203-
@staticmethod
204-
def __decrypt_py2(secret, encrypted_value, logger):
205-
# If the string length is 0 or no secret was passed in, return the empty string.
206-
if not encrypted_value or not secret:
207-
return encrypted_value
208-
209-
parts = encrypted_value.split("!")
210-
if len(parts) != 2:
211-
logger.warn('Encrypted value "%s" not in standard encrypted format, decryption skipped.' % encrypted_value)
212-
return encrypted_value
213-
214-
iv_text = parts[0]
215-
encrypted_text = parts[1]
216-
iv_bytes = base64.standard_b64decode(iv_text)
217-
secret_bytes = base64.standard_b64decode(secret)
218-
219-
if len(iv_bytes) != 16:
220-
logger.warn('Initialization Vector for "%s" not valid, decryption skipped.' % encrypted_value)
221-
return encrypted_value
222-
if len(secret_bytes) != 32:
223-
logger.warn('Passed in secret length is invalid, decryption skipped.')
224-
return encrypted_value
225-
226-
cipher = Cipher(algorithms.AES(secret_bytes), modes.CBC(iv_bytes), backend=default_backend())
227-
decryptor = cipher.decryptor()
228-
decrypted_bytes = decryptor.update(base64.standard_b64decode(encrypted_text)) + decryptor.finalize()
229-
230-
decrypted_string = decrypted_bytes.encode('utf-8')
231-
return ''.join([char for char in decrypted_string if ord(char) > 31])

src/azure-cli/azure/cli/command_modules/botservice/bot_publish_prep.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
# --------------------------------------------------------------------------------------------
55

66
import os
7-
import sys
87
import zipfile
98
import requests
109

@@ -99,12 +98,8 @@ def __retrieve_node_v4_publish_zip():
9998
:return: zipfile.ZipFile instance
10099
"""
101100
response = requests.get('https://icscratch.blob.core.windows.net/bot-packages/node_v4_publish.zip')
102-
if sys.version_info.major >= 3:
103-
import io
104-
return zipfile.ZipFile(io.BytesIO(response.content))
105-
# If Python version is 2.X, use StringIO instead.
106-
import StringIO # pylint: disable=import-error
107-
return zipfile.ZipFile(StringIO.StringIO(response.content))
101+
import io
102+
return zipfile.ZipFile(io.BytesIO(response.content))
108103

109104
@staticmethod
110105
def __extract_specific_file_from_zip(logger, zip_file, web_config_exists, iisnode_yml_exists):

src/azure-cli/azure/cli/command_modules/monitor/grammar/autoscale/AutoscaleConditionParser.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@
88
from antlr4 import *
99
from io import StringIO
1010
import sys
11-
if sys.version_info[1] > 5:
12-
from typing import TextIO
13-
else:
14-
from typing.io import TextIO
11+
from typing import TextIO
1512

1613
def serializedATN():
1714
return [
@@ -1096,8 +1093,3 @@ def dim_value(self):
10961093
finally:
10971094
self.exitRule()
10981095
return localctx
1099-
1100-
1101-
1102-
1103-

src/azure-cli/azure/cli/command_modules/monitor/grammar/metric_alert/MetricAlertConditionParser.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,8 @@
66
# encoding: utf-8
77
# pylint: disable=all
88
from antlr4 import *
9-
from io import StringIO
109
import sys
11-
if sys.version_info[1] > 5:
12-
from typing import TextIO
13-
else:
14-
from typing.io import TextIO
10+
from typing import TextIO
1511

1612
def serializedATN():
1713
return [

src/azure-cli/azure/cli/command_modules/resource/custom.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,9 +341,6 @@ def _is_bicepparam_file_provided(parameters):
341341

342342

343343
def _ssl_context():
344-
if sys.version_info < (3, 4):
345-
return ssl.SSLContext(ssl.PROTOCOL_TLSv1)
346-
347344
return ssl.create_default_context()
348345

349346

0 commit comments

Comments
 (0)