Skip to content
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

Remove shared #12883

Merged
merged 15 commits into from
Aug 7, 2020
Merged
Show file tree
Hide file tree
Changes from 10 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
17 changes: 10 additions & 7 deletions sdk/tables/azure-data-tables/azure/data/tables/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,27 @@
from azure.data.tables._models import TableServiceStats
seankane-msft marked this conversation as resolved.
Show resolved Hide resolved

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

from ._models import (
AccessPolicy,
Metrics,
RetentionPolicy, TableAnalyticsLogging, TableSasPermissions, CorsRule, UpdateMode, SASProtocol, Table,
)
from ._shared.models import (
RetentionPolicy,
TableAnalyticsLogging,
TableSasPermissions,
CorsRule,
UpdateMode,
SASProtocol,
Table,
LocationMode,
ResourceTypes,
AccountSasPermissions,
TableErrorCode
)
from ._shared.policies import ExponentialRetry, LinearRetry
from ._policies import ExponentialRetry, LinearRetry
from ._version import VERSION
from ._deserialize import TableErrorCode
seankane-msft marked this conversation as resolved.
Show resolved Hide resolved

__version__ = VERSION

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 ._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 Expand Up @@ -126,13 +110,3 @@ def _get_canonicalized_resource_query(self, request):
if name == 'comp':
return '?comp=' + value
return ''

# def _get_canonicalized_resource_query(self, request):
# sorted_queries = [(name, value) for name, value in request.query.items()]
# sorted_queries.sort()
#
# string_to_sign = ''
# for name, value in sorted_queries:
# if value is not None:
# string_to_sign += '\n' + name.lower() + ':' + value
# return string_to_sign
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 Expand Up @@ -296,7 +297,7 @@ def _batch_send(
return iter(parts)
return parts
except HttpResponseError as error:
process_table_error(error)
_process_table_error(error)

class TransportWrapper(HttpTransport):
"""Wrapper class that ensures that an inner client created
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
seankane-msft marked this conversation as resolved.
Show resolved Hide resolved

__author__ = 'Microsoft Corp. <[email protected]>'
__version__ = '1.4.2'
seankane-msft marked this conversation as resolved.
Show resolved Hide resolved
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