Skip to content

Remove shared #12883

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Aug 7, 2020
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions sdk/tables/azure-data-tables/azure/data/tables/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from azure.data.tables._models import TableServiceStats

from ._entity import TableEntity, EntityProperty, EdmType
from ._shared.table_shared_access_signature import generate_table_sas, \
from .table_shared_access_signature import generate_table_sas, \
generate_account_sas
from ._table_client import TableClient
from ._table_service_client import TableServiceClient
Expand All @@ -16,15 +16,14 @@
Metrics,
RetentionPolicy, TableAnalyticsLogging, TableSasPermissions, CorsRule, UpdateMode, SASProtocol, Table,
)
from ._shared.models import (
from ._models import (
LocationMode,
ResourceTypes,
AccountSasPermissions,
TableErrorCode
)
from ._shared.policies import ExponentialRetry, LinearRetry
from ._policies import ExponentialRetry, LinearRetry
from ._version import VERSION

from ._deserialize import TableErrorCode
__version__ = VERSION

__all__ = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
# --------------------------------------------------------------------------

import logging
import sys
try:
from urllib.parse import urlparse
except ImportError:
Expand All @@ -16,7 +15,7 @@
from azure.core.exceptions import ClientAuthenticationError
from azure.core.pipeline.policies import SansIOHTTPPolicy

from azure.data.tables._shared._constants import (
from azure.data.tables._constants import (
DEV_ACCOUNT_NAME,
DEV_ACCOUNT_SECONDARY_NAME
)
Expand All @@ -32,21 +31,6 @@
logger = logging.getLogger(__name__)


# wraps a given exception with the desired exception type
def _wrap_exception(ex, desired_type):
msg = ""
if ex.args:
msg = ex.args[0]
if sys.version_info >= (3,):
# Automatic chaining in Python 3 means we keep the trace
return desired_type(msg)
# There isn't a good solution in 2 for keeping the stack trace
# in general, or that will not result in an error in 3
# However, we can keep the previous error type and message
# TODO: In the future we will log the trace
return desired_type('{}: {}'.format(ex.__class__.__name__, msg))


class AzureSigningError(ClientAuthenticationError):
"""
Represents a fatal error when attempting to sign a request.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
from urllib2 import quote # type: ignore

import six
from azure.data.tables._shared.shared_access_signature import QueryStringConstants
from azure.core.configuration import Configuration
from azure.core.exceptions import HttpResponseError
from azure.core.pipeline import Pipeline
Expand All @@ -41,19 +40,21 @@
UserAgentPolicy
)

from .constants import STORAGE_OAUTH_SCOPE, SERVICE_HOST_BASE, CONNECTION_TIMEOUT, READ_TIMEOUT
from .models import LocationMode
from .authentication import SharedKeyCredentialPolicy
from .policies import (
from .shared_access_signature import QueryStringConstants
from ._constants import STORAGE_OAUTH_SCOPE, SERVICE_HOST_BASE, CONNECTION_TIMEOUT, READ_TIMEOUT
from ._models import LocationMode
from ._authentication import SharedKeyCredentialPolicy
from ._policies import (
StorageHeadersPolicy,
StorageContentValidation,
StorageRequestHook,
StorageResponseHook,
StorageLoggingPolicy,
StorageHosts, ExponentialRetry,
)
from .._version import VERSION
from .response_handlers import process_table_error, PartialBatchErrorException
from ._version import VERSION
from ._deserialize import process_table_error
from ._models import PartialBatchErrorException


_LOGGER = logging.getLogger(__name__)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,54 +3,51 @@
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------

import base64
import hashlib
import hmac
from sys import version_info
import six

try:
from urllib.parse import quote, unquote
except ImportError:
from urllib2 import quote, unquote # type: ignore

import six
if 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 url_quote(url):
return quote(url)
def _to_str(value):
return _str(value) if value is not None else None


def url_unquote(url):
return unquote(url)
def _to_utc_datetime(value):
return value.strftime('%Y-%m-%dT%H:%M:%SZ')


def encode_base64(data):
def _encode_base64(data):
if isinstance(data, six.text_type):
data = data.encode('utf-8')
encoded = base64.b64encode(data)
return encoded.decode('utf-8')


def decode_base64_to_bytes(data):
def _decode_base64_to_bytes(data):
if isinstance(data, six.text_type):
data = data.encode('utf-8')
return base64.b64decode(data)


def decode_base64_to_text(data):
decoded_bytes = decode_base64_to_bytes(data)
return decoded_bytes.decode('utf-8')


def sign_string(key, string_to_sign, key_is_base64=True):
def _sign_string(key, string_to_sign, key_is_base64=True):
if key_is_base64:
key = decode_base64_to_bytes(key)
key = _decode_base64_to_bytes(key)
else:
if isinstance(key, six.text_type):
key = key.encode('utf-8')
if isinstance(string_to_sign, six.text_type):
string_to_sign = string_to_sign.encode('utf-8')
signed_hmac_sha256 = hmac.HMAC(key, string_to_sign, hashlib.sha256)
digest = signed_hmac_sha256.digest()
encoded_digest = encode_base64(digest)
encoded_digest = _encode_base64(digest)
return encoded_digest
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# --------------------------------------------------------------------------
import platform
import sys
from ._generated.version import VERSION

__author__ = 'Microsoft Corp. <[email protected]>'
__version__ = '1.4.2'
Expand Down Expand Up @@ -49,3 +50,19 @@
_AUTHORIZATION_HEADER_NAME = 'Authorization'
_COPY_SOURCE_HEADER_NAME = 'x-ms-copy-source'
_REDACTED_VALUE = 'REDACTED'


X_MS_VERSION = VERSION

# Socket timeout in seconds
CONNECTION_TIMEOUT = 20
READ_TIMEOUT = 20

# for python 3.5+, there was a change to the definition of the socket timeout (as far as socket.sendall is concerned)
# The socket timeout is now the maximum total duration to send all data.
if sys.version_info >= (3, 5):
# the timeout to connect is 20 seconds, and the read timeout is 2000 seconds
# the 2000 seconds was calculated with: 100MB (max block size)/ 50KB/s (an arbitrarily chosen minimum upload speed)
READ_TIMEOUT = 2000

STORAGE_OAUTH_SCOPE = "https://storage.azure.com/.default"
Loading