From ded2c2d9f1fac27d66836828959aed2bfeb58891 Mon Sep 17 00:00:00 2001 From: Roman Inflianskas Date: Mon, 16 Dec 2024 16:26:05 +0200 Subject: [PATCH] Drop leftovers from EOL Python version support --- cs/__init__.py | 21 ++++++++------------- cs/client.py | 46 +++++++++++----------------------------------- tests.py | 12 ++---------- 3 files changed, 21 insertions(+), 58 deletions(-) diff --git a/cs/__init__.py b/cs/__init__.py index ff34d37..5fff18a 100644 --- a/cs/__init__.py +++ b/cs/__init__.py @@ -3,11 +3,7 @@ import os import sys from collections import defaultdict - -try: - from configparser import NoSectionError -except ImportError: # python 2 - from ConfigParser import NoSectionError +from configparser import NoSectionError try: import pygments @@ -32,15 +28,14 @@ "CloudStackApiException", ] -if sys.version_info >= (3, 5): - try: - import aiohttp # noqa - except ImportError: - pass - else: - from ._async import AIOCloudStack # noqa +try: + import aiohttp # noqa +except ImportError: + pass +else: + from ._async import AIOCloudStack # noqa - __all__.append("AIOCloudStack") + __all__.append("AIOCloudStack") def _format_json(data, theme): diff --git a/cs/client.py b/cs/client.py index 25bce0b..4a4ec35 100644 --- a/cs/client.py +++ b/cs/client.py @@ -1,4 +1,3 @@ -#! /usr/bin/env python from __future__ import print_function import base64 @@ -8,42 +7,21 @@ import re import sys import time +from configparser import ConfigParser from datetime import datetime, timedelta from fnmatch import fnmatch - -try: - from configparser import ConfigParser -except ImportError: # python 2 - from ConfigParser import ConfigParser - -try: - from urllib.parse import quote -except ImportError: # python 2 - from urllib import quote +from urllib.parse import quote import pytz import requests from requests.structures import CaseInsensitiveDict -PY2 = sys.version_info < (3, 0) - -if PY2: - text_type = unicode # noqa - string_type = basestring # noqa - integer_types = int, long # noqa - binary_type = str -else: - text_type = str - string_type = str - integer_types = int - binary_type = bytes -if sys.version_info >= (3, 5): - try: - from . import AIOCloudStack # noqa - except ImportError: - pass +try: + from . import AIOCloudStack # noqa +except ImportError: + pass TIMEOUT = 10 @@ -124,8 +102,6 @@ def cs_encode(s): java.net.URLEncoder.encode(s).replace('+', '%20') """ - if PY2 and isinstance(s, text_type): - s = s.encode("utf-8") return quote(s, safe="*") @@ -146,11 +122,11 @@ def transform(params): params.pop(key) continue - if isinstance(value, (string_type, binary_type)): + if isinstance(value, (str, bytes)): continue - if isinstance(value, integer_types): - params[key] = text_type(value) + if isinstance(value, int): + params[key] = str(value) elif isinstance(value, (list, tuple, set, dict)): if not value: params.pop(key) @@ -166,7 +142,7 @@ def transform(params): for index, val in enumerate(value): for name, v in val.items(): k = "%s[%d].%s" % (key, index, name) - params[k] = text_type(v) + params[k] = str(v) else: raise ValueError(type(value)) @@ -606,7 +582,7 @@ def read_config(ini_group=None): # convert booleans values. bool_keys = ("dangerous_no_tls_verify",) for bool_key in bool_keys: - if isinstance(config[bool_key], string_type): + if isinstance(config[bool_key], str): try: config[bool_key] = strtobool(config[bool_key]) except ValueError: diff --git a/tests.py b/tests.py index ea18bab..eb93b98 100644 --- a/tests.py +++ b/tests.py @@ -4,16 +4,8 @@ from contextlib import contextmanager from functools import partial from unittest import TestCase - -try: - from unittest.mock import patch -except ImportError: - from mock import patch - -try: - from urllib.parse import urlparse, parse_qs -except ImportError: - from urlparse import urlparse, parse_qs +from unittest.mock import patch +from urllib.parse import urlparse, parse_qs from cs import ( CloudStack,