diff --git a/sdk/eventhub/azure-eventhub-checkpointstoreblob-aio/azure/eventhub/extensions/checkpointstoreblobaio/_vendor/storage/blob/_shared/avro/schema.py b/sdk/eventhub/azure-eventhub-checkpointstoreblob-aio/azure/eventhub/extensions/checkpointstoreblobaio/_vendor/storage/blob/_shared/avro/schema.py index ffe28530167f..d496f6457568 100644 --- a/sdk/eventhub/azure-eventhub-checkpointstoreblob-aio/azure/eventhub/extensions/checkpointstoreblobaio/_vendor/storage/blob/_shared/avro/schema.py +++ b/sdk/eventhub/azure-eventhub-checkpointstoreblob-aio/azure/eventhub/extensions/checkpointstoreblobaio/_vendor/storage/blob/_shared/avro/schema.py @@ -25,19 +25,10 @@ - Null. """ -import abc +from abc import ABCMeta, abstractmethod import json import logging import re -import sys -from six import with_metaclass - -PY2 = sys.version_info[0] == 2 - -if PY2: - _str = unicode # pylint: disable=undefined-variable -else: - _str = str logger = logging.getLogger(__name__) @@ -140,7 +131,7 @@ class SchemaParseException(AvroException): """Error while parsing a JSON schema descriptor.""" -class Schema(with_metaclass(abc.ABCMeta, object)): +class Schema(metaclass=ABCMeta): """Abstract base class for all Schema classes.""" def __init__(self, data_type, other_props=None): @@ -198,7 +189,7 @@ def __str__(self): """Returns: the JSON representation of this schema.""" return json.dumps(self.to_json(names=None)) - @abc.abstractmethod + @abstractmethod def to_json(self, names): """Converts the schema object into its AVRO specification representation. @@ -286,7 +277,7 @@ def fullname(self): # ------------------------------------------------------------------------------ -class Names(object): +class Names: """Tracks Avro named schemas and default namespace during parsing.""" def __init__(self, default_namespace=None, names=None): @@ -447,7 +438,7 @@ def name_ref(self, names): return self.name return self.fullname - @abc.abstractmethod + @abstractmethod def to_json(self, names): """Converts the schema object into its AVRO specification representation. @@ -489,7 +480,7 @@ def __init__( doc: other_props: """ - if (not isinstance(name, _str)) or (not name): + if (not isinstance(name, str)) or (not name): raise SchemaParseException('Invalid record field name: %r.' % name) if (order is not None) and (order not in VALID_FIELD_SORT_ORDERS): raise SchemaParseException('Invalid record field order: %r.' % order) @@ -564,8 +555,8 @@ def to_json(self, names=None): return to_dump def __eq__(self, that): - to_cmp = json.loads(_str(self)) - return to_cmp == json.loads(_str(that)) + to_cmp = json.loads(str(self)) + return to_cmp == json.loads(str(that)) # ------------------------------------------------------------------------------ @@ -679,7 +670,7 @@ def __init__( symbols = tuple(symbols) symbol_set = frozenset(symbols) if (len(symbol_set) != len(symbols) - or not all(map(lambda symbol: isinstance(symbol, _str), symbols))): + or not all(map(lambda symbol: isinstance(symbol, str), symbols))): raise AvroException( 'Invalid symbols for enum schema: %r.' % (symbols,)) @@ -747,8 +738,8 @@ def to_json(self, names=None): return to_dump def __eq__(self, that): - to_cmp = json.loads(_str(self)) - return to_cmp == json.loads(_str(that)) + to_cmp = json.loads(str(self)) + return to_cmp == json.loads(str(that)) # ------------------------------------------------------------------------------ @@ -784,8 +775,8 @@ def to_json(self, names=None): return to_dump def __eq__(self, that): - to_cmp = json.loads(_str(self)) - return to_cmp == json.loads(_str(that)) + to_cmp = json.loads(str(self)) + return to_cmp == json.loads(str(that)) # ------------------------------------------------------------------------------ @@ -841,8 +832,8 @@ def to_json(self, names=None): return to_dump def __eq__(self, that): - to_cmp = json.loads(_str(self)) - return to_cmp == json.loads(_str(that)) + to_cmp = json.loads(str(self)) + return to_cmp == json.loads(str(that)) # ------------------------------------------------------------------------------ @@ -1031,8 +1022,8 @@ def to_json(self, names=None): return to_dump def __eq__(self, that): - to_cmp = json.loads(_str(self)) - return to_cmp == json.loads(_str(that)) + to_cmp = json.loads(str(self)) + return to_cmp == json.loads(str(that)) # ------------------------------------------------------------------------------ @@ -1164,7 +1155,7 @@ def MakeFields(names): # Parsers for the JSON data types: _JSONDataParserTypeMap = { - _str: _schema_from_json_string, + str: _schema_from_json_string, list: _schema_from_json_array, dict: _schema_from_json_object, } diff --git a/sdk/eventhub/azure-eventhub-checkpointstoreblob-aio/azure/eventhub/extensions/checkpointstoreblobaio/_vendor/storage/blob/_shared/parser.py b/sdk/eventhub/azure-eventhub-checkpointstoreblob-aio/azure/eventhub/extensions/checkpointstoreblobaio/_vendor/storage/blob/_shared/parser.py index c6feba8a6393..0b45774face0 100644 --- a/sdk/eventhub/azure-eventhub-checkpointstoreblob-aio/azure/eventhub/extensions/checkpointstoreblobaio/_vendor/storage/blob/_shared/parser.py +++ b/sdk/eventhub/azure-eventhub-checkpointstoreblob-aio/azure/eventhub/extensions/checkpointstoreblobaio/_vendor/storage/blob/_shared/parser.py @@ -6,15 +6,6 @@ import sys -if sys.version_info < (3,): - def _str(value): - if isinstance(value, unicode): # pylint: disable=undefined-variable - return value.encode('utf-8') - - return str(value) -else: - _str = str - def _to_utc_datetime(value): return value.strftime('%Y-%m-%dT%H:%M:%SZ') diff --git a/sdk/eventhub/azure-eventhub-checkpointstoreblob-aio/azure/eventhub/extensions/checkpointstoreblobaio/_vendor/storage/blob/_shared/policies.py b/sdk/eventhub/azure-eventhub-checkpointstoreblob-aio/azure/eventhub/extensions/checkpointstoreblobaio/_vendor/storage/blob/_shared/policies.py index 2db5048b67ef..695bc35ded70 100644 --- a/sdk/eventhub/azure-eventhub-checkpointstoreblob-aio/azure/eventhub/extensions/checkpointstoreblobaio/_vendor/storage/blob/_shared/policies.py +++ b/sdk/eventhub/azure-eventhub-checkpointstoreblob-aio/azure/eventhub/extensions/checkpointstoreblobaio/_vendor/storage/blob/_shared/policies.py @@ -15,20 +15,12 @@ import types from typing import Any, TYPE_CHECKING from wsgiref.handlers import format_date_time -try: - from urllib.parse import ( - urlparse, - parse_qsl, - urlunparse, - urlencode, - ) -except ImportError: - from urllib import urlencode # type: ignore - from urlparse import ( # type: ignore - urlparse, - parse_qsl, - urlunparse, - ) +from urllib.parse import ( + urlparse, + parse_qsl, + urlunparse, + urlencode, +) from azure.core.pipeline.policies import ( HeadersPolicy, @@ -41,10 +33,6 @@ from .models import LocationMode -try: - _unicode_type = unicode # type: ignore -except NameError: - _unicode_type = str if TYPE_CHECKING: from azure.core.pipeline import PipelineRequest, PipelineResponse @@ -54,8 +42,6 @@ def encode_base64(data): - if isinstance(data, _unicode_type): - data = data.encode('utf-8') encoded = base64.b64encode(data) return encoded.decode('utf-8') diff --git a/sdk/eventhub/azure-eventhub-checkpointstoreblob-aio/azure/eventhub/extensions/checkpointstoreblobaio/_vendor/storage/blob/_shared/shared_access_signature.py b/sdk/eventhub/azure-eventhub-checkpointstoreblob-aio/azure/eventhub/extensions/checkpointstoreblobaio/_vendor/storage/blob/_shared/shared_access_signature.py index 07aad5ffa1c8..cb0438f1d311 100644 --- a/sdk/eventhub/azure-eventhub-checkpointstoreblob-aio/azure/eventhub/extensions/checkpointstoreblobaio/_vendor/storage/blob/_shared/shared_access_signature.py +++ b/sdk/eventhub/azure-eventhub-checkpointstoreblob-aio/azure/eventhub/extensions/checkpointstoreblobaio/_vendor/storage/blob/_shared/shared_access_signature.py @@ -6,7 +6,7 @@ from datetime import date -from .parser import _str, _to_utc_datetime +from .parser import _to_utc_datetime from .constants import X_MS_VERSION from . import sign_string, url_quote diff --git a/sdk/eventhub/azure-eventhub-checkpointstoreblob/azure/eventhub/extensions/checkpointstoreblob/_vendor/storage/blob/_shared/avro/schema.py b/sdk/eventhub/azure-eventhub-checkpointstoreblob/azure/eventhub/extensions/checkpointstoreblob/_vendor/storage/blob/_shared/avro/schema.py index 34fa5980a5f5..18027e3c82c7 100644 --- a/sdk/eventhub/azure-eventhub-checkpointstoreblob/azure/eventhub/extensions/checkpointstoreblob/_vendor/storage/blob/_shared/avro/schema.py +++ b/sdk/eventhub/azure-eventhub-checkpointstoreblob/azure/eventhub/extensions/checkpointstoreblob/_vendor/storage/blob/_shared/avro/schema.py @@ -29,15 +29,7 @@ import json import logging import re -import sys -from six import with_metaclass -PY2 = sys.version_info[0] == 2 - -if PY2: - _str = unicode # pylint: disable=undefined-variable -else: - _str = str logger = logging.getLogger(__name__) @@ -140,7 +132,7 @@ class SchemaParseException(AvroException): """Error while parsing a JSON schema descriptor.""" -class Schema(with_metaclass(abc.ABCMeta, object)): +class Schema(metaclass=abc.ABCMeta): """Abstract base class for all Schema classes.""" def __init__(self, data_type, other_props=None): @@ -154,9 +146,8 @@ def __init__(self, data_type, other_props=None): raise SchemaParseException('%r is not a valid Avro type.' % data_type) # All properties of this schema, as a map: property name -> property value - self._props = {} + self._props = {'type': data_type} - self._props['type'] = data_type self._type = data_type if other_props: @@ -222,7 +213,7 @@ def to_json(self, names): ) -class Name(object): +class Name: """Representation of an Avro name.""" def __init__(self, name, namespace=None): @@ -489,9 +480,9 @@ def __init__( doc: other_props: """ - if (not isinstance(name, _str)) or (not name): + if not isinstance(name, str) or not name: raise SchemaParseException('Invalid record field name: %r.' % name) - if (order is not None) and (order not in VALID_FIELD_SORT_ORDERS): + if order is not None and order not in VALID_FIELD_SORT_ORDERS: raise SchemaParseException('Invalid record field order: %r.' % order) # All properties of this record field: @@ -564,8 +555,8 @@ def to_json(self, names=None): return to_dump def __eq__(self, that): - to_cmp = json.loads(_str(self)) - return to_cmp == json.loads(_str(that)) + to_cmp = json.loads(str(self)) + return to_cmp == json.loads(str(that)) # ------------------------------------------------------------------------------ @@ -679,7 +670,7 @@ def __init__( symbols = tuple(symbols) symbol_set = frozenset(symbols) if (len(symbol_set) != len(symbols) - or not all(map(lambda symbol: isinstance(symbol, _str), symbols))): + or not all(map(lambda symbol: isinstance(symbol, str), symbols))): raise AvroException( 'Invalid symbols for enum schema: %r.' % (symbols,)) @@ -747,8 +738,8 @@ def to_json(self, names=None): return to_dump def __eq__(self, that): - to_cmp = json.loads(_str(self)) - return to_cmp == json.loads(_str(that)) + to_cmp = json.loads(str(self)) + return to_cmp == json.loads(str(that)) # ------------------------------------------------------------------------------ @@ -784,8 +775,8 @@ def to_json(self, names=None): return to_dump def __eq__(self, that): - to_cmp = json.loads(_str(self)) - return to_cmp == json.loads(_str(that)) + to_cmp = json.loads(str(self)) + return to_cmp == json.loads(str(that)) # ------------------------------------------------------------------------------ @@ -841,8 +832,8 @@ def to_json(self, names=None): return to_dump def __eq__(self, that): - to_cmp = json.loads(_str(self)) - return to_cmp == json.loads(_str(that)) + to_cmp = json.loads(str(self)) + return to_cmp == json.loads(str(that)) # ------------------------------------------------------------------------------ @@ -1031,8 +1022,8 @@ def to_json(self, names=None): return to_dump def __eq__(self, that): - to_cmp = json.loads(_str(self)) - return to_cmp == json.loads(_str(that)) + to_cmp = json.loads(str(self)) + return to_cmp == json.loads(str(that)) # ------------------------------------------------------------------------------ @@ -1164,7 +1155,7 @@ def MakeFields(names): # Parsers for the JSON data types: _JSONDataParserTypeMap = { - _str: _schema_from_json_string, + str: _schema_from_json_string, list: _schema_from_json_array, dict: _schema_from_json_object, } diff --git a/sdk/eventhub/azure-eventhub-checkpointstoreblob/azure/eventhub/extensions/checkpointstoreblob/_vendor/storage/blob/_shared/policies.py b/sdk/eventhub/azure-eventhub-checkpointstoreblob/azure/eventhub/extensions/checkpointstoreblob/_vendor/storage/blob/_shared/policies.py index d582b36a3c8e..377007f5ff2b 100644 --- a/sdk/eventhub/azure-eventhub-checkpointstoreblob/azure/eventhub/extensions/checkpointstoreblob/_vendor/storage/blob/_shared/policies.py +++ b/sdk/eventhub/azure-eventhub-checkpointstoreblob/azure/eventhub/extensions/checkpointstoreblob/_vendor/storage/blob/_shared/policies.py @@ -14,21 +14,13 @@ import uuid import types from typing import Any, TYPE_CHECKING +from urllib.parse import ( + urlparse, + parse_qsl, + urlunparse, + urlencode, +) from wsgiref.handlers import format_date_time -try: - from urllib.parse import ( - urlparse, - parse_qsl, - urlunparse, - urlencode, - ) -except ImportError: - from urllib import urlencode # type: ignore - from urlparse import ( # type: ignore - urlparse, - parse_qsl, - urlunparse, - ) from azure.core.pipeline.policies import ( HeadersPolicy, @@ -41,10 +33,6 @@ from .models import LocationMode -try: - _unicode_type = unicode # type: ignore -except NameError: - _unicode_type = str if TYPE_CHECKING: from azure.core.pipeline import PipelineRequest, PipelineResponse @@ -54,8 +42,6 @@ def encode_base64(data): - if isinstance(data, _unicode_type): - data = data.encode('utf-8') encoded = base64.b64encode(data) return encoded.decode('utf-8') diff --git a/sdk/ml/azure-ai-ml/tests/internal_utils/unittests/test_ml_client.py b/sdk/ml/azure-ai-ml/tests/internal_utils/unittests/test_ml_client.py index 00324e331772..2bdba3b305b0 100644 --- a/sdk/ml/azure-ai-ml/tests/internal_utils/unittests/test_ml_client.py +++ b/sdk/ml/azure-ai-ml/tests/internal_utils/unittests/test_ml_client.py @@ -1,8 +1,8 @@ import logging import os +from unittest import mock from unittest.mock import Mock, patch -import mock import pytest from test_utilities.constants import Test_Resource_Group, Test_Subscription diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/_pyamqp/_platform.py b/sdk/servicebus/azure-servicebus/azure/servicebus/_pyamqp/_platform.py index b547a8012fbd..9289fb1e34f3 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/_pyamqp/_platform.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/_pyamqp/_platform.py @@ -83,25 +83,10 @@ def _versionatom(s): KNOWN_TCP_OPTS.remove("TCP_MAXSEG") KNOWN_TCP_OPTS.remove("TCP_USER_TIMEOUT") -if sys.version_info < (2, 7, 7): # pragma: no cover - import functools - - def _to_bytes_arg(fun): - @functools.wraps(fun) - def _inner(s, *args, **kwargs): - return fun(s.encode(), *args, **kwargs) - - return _inner - - pack = _to_bytes_arg(struct.pack) - pack_into = _to_bytes_arg(struct.pack_into) - unpack = _to_bytes_arg(struct.unpack) - unpack_from = _to_bytes_arg(struct.unpack_from) -else: - pack = struct.pack - pack_into = struct.pack_into - unpack = struct.unpack - unpack_from = struct.unpack_from +pack = struct.pack +pack_into = struct.pack_into +unpack = struct.unpack +unpack_from = struct.unpack_from __all__ = [ "LINUX_VERSION", diff --git a/sdk/storage/azure-storage-blob/azure/storage/blob/_shared/parser.py b/sdk/storage/azure-storage-blob/azure/storage/blob/_shared/parser.py index cd59cfe104ca..112c1984f4fb 100644 --- a/sdk/storage/azure-storage-blob/azure/storage/blob/_shared/parser.py +++ b/sdk/storage/azure-storage-blob/azure/storage/blob/_shared/parser.py @@ -4,26 +4,17 @@ # license information. # -------------------------------------------------------------------------- -import sys from datetime import datetime, timezone from typing import Optional EPOCH_AS_FILETIME = 116444736000000000 # January 1, 1970 as MS filetime HUNDREDS_OF_NANOSECONDS = 10000000 -if sys.version_info < (3,): - def _str(value): - if isinstance(value, unicode): # pylint: disable=undefined-variable - return value.encode('utf-8') - - return str(value) -else: - _str = str - def _to_utc_datetime(value: datetime) -> str: return value.strftime('%Y-%m-%dT%H:%M:%SZ') + def _rfc_1123_to_datetime(rfc_1123: str) -> Optional[datetime]: """Converts an RFC 1123 date string to a UTC datetime. @@ -36,6 +27,7 @@ def _rfc_1123_to_datetime(rfc_1123: str) -> Optional[datetime]: return datetime.strptime(rfc_1123, "%a, %d %b %Y %H:%M:%S %Z") + def _filetime_to_datetime(filetime: str) -> Optional[datetime]: """Converts an MS filetime string to a UTC datetime. "0" indicates None. If parsing MS Filetime fails, tries RFC 1123 as backup. diff --git a/sdk/storage/azure-storage-blob/azure/storage/blob/_shared/shared_access_signature.py b/sdk/storage/azure-storage-blob/azure/storage/blob/_shared/shared_access_signature.py index 21ba30240cb6..df29222b873e 100644 --- a/sdk/storage/azure-storage-blob/azure/storage/blob/_shared/shared_access_signature.py +++ b/sdk/storage/azure-storage-blob/azure/storage/blob/_shared/shared_access_signature.py @@ -7,7 +7,7 @@ from datetime import date -from .parser import _str, _to_utc_datetime +from .parser import _to_utc_datetime from .constants import X_MS_VERSION from . import sign_string, url_quote @@ -187,7 +187,7 @@ def __init__(self): def _add_query(self, name, val): if val: - self.query_dict[name] = _str(val) if val is not None else None + self.query_dict[name] = str(val) if val is not None else None def add_encryption_scope(self, **kwargs): self._add_query(QueryStringConstants.SIGNED_ENCRYPTION_SCOPE, kwargs.pop('encryption_scope', None)) diff --git a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_shared/parser.py b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_shared/parser.py index cd59cfe104ca..112c1984f4fb 100644 --- a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_shared/parser.py +++ b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_shared/parser.py @@ -4,26 +4,17 @@ # license information. # -------------------------------------------------------------------------- -import sys from datetime import datetime, timezone from typing import Optional EPOCH_AS_FILETIME = 116444736000000000 # January 1, 1970 as MS filetime HUNDREDS_OF_NANOSECONDS = 10000000 -if sys.version_info < (3,): - def _str(value): - if isinstance(value, unicode): # pylint: disable=undefined-variable - return value.encode('utf-8') - - return str(value) -else: - _str = str - def _to_utc_datetime(value: datetime) -> str: return value.strftime('%Y-%m-%dT%H:%M:%SZ') + def _rfc_1123_to_datetime(rfc_1123: str) -> Optional[datetime]: """Converts an RFC 1123 date string to a UTC datetime. @@ -36,6 +27,7 @@ def _rfc_1123_to_datetime(rfc_1123: str) -> Optional[datetime]: return datetime.strptime(rfc_1123, "%a, %d %b %Y %H:%M:%S %Z") + def _filetime_to_datetime(filetime: str) -> Optional[datetime]: """Converts an MS filetime string to a UTC datetime. "0" indicates None. If parsing MS Filetime fails, tries RFC 1123 as backup. diff --git a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_shared/shared_access_signature.py b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_shared/shared_access_signature.py index 21ba30240cb6..df29222b873e 100644 --- a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_shared/shared_access_signature.py +++ b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_shared/shared_access_signature.py @@ -7,7 +7,7 @@ from datetime import date -from .parser import _str, _to_utc_datetime +from .parser import _to_utc_datetime from .constants import X_MS_VERSION from . import sign_string, url_quote @@ -187,7 +187,7 @@ def __init__(self): def _add_query(self, name, val): if val: - self.query_dict[name] = _str(val) if val is not None else None + self.query_dict[name] = str(val) if val is not None else None def add_encryption_scope(self, **kwargs): self._add_query(QueryStringConstants.SIGNED_ENCRYPTION_SCOPE, kwargs.pop('encryption_scope', None)) diff --git a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_directory_client.py b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_directory_client.py index 966d5c4259e1..832830ae7537 100644 --- a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_directory_client.py +++ b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_directory_client.py @@ -31,7 +31,6 @@ from ._parser import _datetime_to_str, _get_file_permission, _parse_snapshot from ._serialize import get_api_version, get_dest_access_conditions, get_rename_smb_properties from ._shared.base_client import parse_connection_str, parse_query, StorageAccountHostsMixin, TransportWrapper -from ._shared.parser import _str from ._shared.request_handlers import add_metadata_headers from ._shared.response_handlers import process_storage_error, return_response_headers @@ -811,7 +810,7 @@ def set_http_headers( file_change_time = kwargs.pop('file_change_time', None) try: return cast(Dict[str, Any], self._client.directory.set_properties( - file_attributes=_str(file_attributes), + file_attributes=str(file_attributes), file_creation_time=_datetime_to_str(file_creation_time), file_last_write_time=_datetime_to_str(file_last_write_time), file_change_time=_datetime_to_str(file_change_time), diff --git a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_file_client.py b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_file_client.py index 9610b070fc98..7b630a5bb750 100644 --- a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_file_client.py +++ b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_file_client.py @@ -42,7 +42,6 @@ get_source_access_conditions ) from ._shared.base_client import StorageAccountHostsMixin, parse_connection_str, parse_query -from ._shared.parser import _str from ._shared.request_handlers import add_metadata_headers, get_length from ._shared.response_handlers import return_response_headers, process_storage_error from ._shared.uploads import IterStreamer, FileChunkUploader, upload_data_chunks @@ -457,7 +456,7 @@ def create_file( return cast(Dict[str, Any], self._client.file.create( file_content_length=size, metadata=metadata, - file_attributes=_str(file_attributes), + file_attributes=str(file_attributes), file_creation_time=_datetime_to_str(file_creation_time), file_last_write_time=_datetime_to_str(file_last_write_time), file_change_time=_datetime_to_str(file_change_time), @@ -1148,7 +1147,7 @@ def set_http_headers( return cast(Dict[str, Any], self._client.file.set_http_headers( file_content_length=file_content_length, file_http_headers=file_http_headers, - file_attributes=_str(file_attributes), + file_attributes=str(file_attributes), file_creation_time=_datetime_to_str(file_creation_time), file_last_write_time=_datetime_to_str(file_last_write_time), file_change_time=_datetime_to_str(file_change_time), diff --git a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_shared/parser.py b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_shared/parser.py index cd59cfe104ca..112c1984f4fb 100644 --- a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_shared/parser.py +++ b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_shared/parser.py @@ -4,26 +4,17 @@ # license information. # -------------------------------------------------------------------------- -import sys from datetime import datetime, timezone from typing import Optional EPOCH_AS_FILETIME = 116444736000000000 # January 1, 1970 as MS filetime HUNDREDS_OF_NANOSECONDS = 10000000 -if sys.version_info < (3,): - def _str(value): - if isinstance(value, unicode): # pylint: disable=undefined-variable - return value.encode('utf-8') - - return str(value) -else: - _str = str - def _to_utc_datetime(value: datetime) -> str: return value.strftime('%Y-%m-%dT%H:%M:%SZ') + def _rfc_1123_to_datetime(rfc_1123: str) -> Optional[datetime]: """Converts an RFC 1123 date string to a UTC datetime. @@ -36,6 +27,7 @@ def _rfc_1123_to_datetime(rfc_1123: str) -> Optional[datetime]: return datetime.strptime(rfc_1123, "%a, %d %b %Y %H:%M:%S %Z") + def _filetime_to_datetime(filetime: str) -> Optional[datetime]: """Converts an MS filetime string to a UTC datetime. "0" indicates None. If parsing MS Filetime fails, tries RFC 1123 as backup. diff --git a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_shared/shared_access_signature.py b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_shared/shared_access_signature.py index 8a5ebf699c6c..2ef9921de1fc 100644 --- a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_shared/shared_access_signature.py +++ b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_shared/shared_access_signature.py @@ -6,7 +6,7 @@ from datetime import date -from .parser import _str, _to_utc_datetime +from .parser import _to_utc_datetime from .constants import X_MS_VERSION from . import sign_string, url_quote @@ -181,7 +181,7 @@ def __init__(self): def _add_query(self, name, val): if val: - self.query_dict[name] = _str(val) if val is not None else None + self.query_dict[name] = str(val) if val is not None else None def add_base(self, permission, expiry, start, ip, protocol, x_ms_version): if isinstance(start, date): diff --git a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_directory_client_async.py b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_directory_client_async.py index e2e5cc1ed986..0f38ff338068 100644 --- a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_directory_client_async.py +++ b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_directory_client_async.py @@ -32,7 +32,6 @@ from .._serialize import get_api_version, get_dest_access_conditions, get_rename_smb_properties from .._shared.base_client import parse_query, StorageAccountHostsMixin from .._shared.base_client_async import parse_connection_str, AsyncStorageAccountHostsMixin, AsyncTransportWrapper -from .._shared.parser import _str from .._shared.policies_async import ExponentialRetry from .._shared.request_handlers import add_metadata_headers from .._shared.response_handlers import process_storage_error, return_response_headers @@ -816,7 +815,7 @@ async def set_http_headers( file_change_time = kwargs.pop('file_change_time', None) try: return cast(Dict[str, Any], await self._client.directory.set_properties( - file_attributes=_str(file_attributes), + file_attributes=str(file_attributes), file_creation_time=_datetime_to_str(file_creation_time), file_last_write_time=_datetime_to_str(file_last_write_time), file_change_time=_datetime_to_str(file_change_time), diff --git a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_file_client_async.py b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_file_client_async.py index 09a353ac2d5f..c01cbae44ad7 100644 --- a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_file_client_async.py +++ b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_file_client_async.py @@ -43,7 +43,6 @@ ) from .._shared.base_client import StorageAccountHostsMixin, parse_query from .._shared.base_client_async import AsyncStorageAccountHostsMixin, parse_connection_str -from .._shared.parser import _str from .._shared.policies_async import ExponentialRetry from .._shared.request_handlers import add_metadata_headers, get_length from .._shared.response_handlers import process_storage_error, return_response_headers @@ -453,7 +452,7 @@ async def create_file( return cast(Dict[str, Any], await self._client.file.create( file_content_length=size, metadata=metadata, - file_attributes=_str(file_attributes), + file_attributes=str(file_attributes), file_creation_time=_datetime_to_str(file_creation_time), file_last_write_time=_datetime_to_str(file_last_write_time), file_change_time=_datetime_to_str(file_change_time), @@ -1154,7 +1153,7 @@ async def set_http_headers( return cast(Dict[str, Any], await self._client.file.set_http_headers( file_content_length=file_content_length, file_http_headers=file_http_headers, - file_attributes=_str(file_attributes), + file_attributes=str(file_attributes), file_creation_time=_datetime_to_str(file_creation_time), file_last_write_time=_datetime_to_str(file_last_write_time), file_change_time=_datetime_to_str(file_change_time), diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/parser.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/parser.py index cd59cfe104ca..112c1984f4fb 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/parser.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/parser.py @@ -4,26 +4,17 @@ # license information. # -------------------------------------------------------------------------- -import sys from datetime import datetime, timezone from typing import Optional EPOCH_AS_FILETIME = 116444736000000000 # January 1, 1970 as MS filetime HUNDREDS_OF_NANOSECONDS = 10000000 -if sys.version_info < (3,): - def _str(value): - if isinstance(value, unicode): # pylint: disable=undefined-variable - return value.encode('utf-8') - - return str(value) -else: - _str = str - def _to_utc_datetime(value: datetime) -> str: return value.strftime('%Y-%m-%dT%H:%M:%SZ') + def _rfc_1123_to_datetime(rfc_1123: str) -> Optional[datetime]: """Converts an RFC 1123 date string to a UTC datetime. @@ -36,6 +27,7 @@ def _rfc_1123_to_datetime(rfc_1123: str) -> Optional[datetime]: return datetime.strptime(rfc_1123, "%a, %d %b %Y %H:%M:%S %Z") + def _filetime_to_datetime(filetime: str) -> Optional[datetime]: """Converts an MS filetime string to a UTC datetime. "0" indicates None. If parsing MS Filetime fails, tries RFC 1123 as backup. diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/shared_access_signature.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/shared_access_signature.py index 1fa72d1b7caa..f0e57d6f337d 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/shared_access_signature.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/shared_access_signature.py @@ -6,7 +6,7 @@ from datetime import date -from .parser import _str, _to_utc_datetime +from .parser import _to_utc_datetime from .constants import X_MS_VERSION from . import sign_string, url_quote @@ -181,7 +181,7 @@ def __init__(self): def _add_query(self, name, val): if val: - self.query_dict[name] = _str(val) if val is not None else None + self.query_dict[name] = str(val) if val is not None else None def add_base(self, permission, expiry, start, ip, protocol, x_ms_version): if isinstance(start, date): diff --git a/tools/azure-sdk-tools/testutils/common_extendedtestcase.py b/tools/azure-sdk-tools/testutils/common_extendedtestcase.py index d123b00deea7..3528001610e2 100644 --- a/tools/azure-sdk-tools/testutils/common_extendedtestcase.py +++ b/tools/azure-sdk-tools/testutils/common_extendedtestcase.py @@ -5,11 +5,10 @@ # -------------------------------------------------------------------------- import sys import unittest -from contextlib import contextmanager class ExtendedTestCase(unittest.TestCase): - """Backport some asserts to Python 2.6 and earlier.""" + """Extended tests method for Azure SDK""" def assertNamedItemInContainer(self, container, item_name, msg=None): for item in container: @@ -24,44 +23,3 @@ def assertNamedItemNotInContainer(self, container, item_name, msg=None): if item.name == item_name: standardMsg = "{0} unexpectedly found in {1}".format(repr(item_name), repr(container)) self.fail(self._formatMessage(msg, standardMsg)) - - if sys.version_info < (2, 7): - - def assertIsNone(self, obj): - self.assertEqual(obj, None) - - def assertIsNotNone(self, obj): - self.assertNotEqual(obj, None) - - def assertIsInstance(self, obj, type): - self.assertTrue(isinstance(obj, type)) - - def assertGreater(self, a, b): - self.assertTrue(a > b) - - def assertGreaterEqual(self, a, b): - self.assertTrue(a >= b) - - def assertLess(self, a, b): - self.assertTrue(a < b) - - def assertLessEqual(self, a, b): - self.assertTrue(a <= b) - - def assertIn(self, member, container): - if member not in container: - self.fail("{0} not found in {1}.".format(safe_repr(member), safe_repr(container))) - - @contextmanager - def _assertRaisesContextManager(self, excClass): - try: - yield - self.fail("{0} was not raised".format(safe_repr(excClass))) - except excClass: - pass - - def assertRaises(self, excClass, callableObj=None, *args, **kwargs): - if callableObj: - super(ExtendedTestCase, self).assertRaises(excClass, callableObj, *args, **kwargs) - else: - return self._assertRaisesContextManager(excClass)