Skip to content

Commit cc9d491

Browse files
author
wallisyan
committed
modify import
1 parent f5ff3b9 commit cc9d491

File tree

18 files changed

+163
-116
lines changed

18 files changed

+163
-116
lines changed

aliyun-python-sdk-core/alibabacloud/compat.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1+
import sys
12
from alibabacloud.vendored import six
23

34
if six.PY2:
5+
from base64 import encodestring as b64_encode_bytes
6+
from base64 import decodestring as b64_decode_bytes
7+
from urllib import urlencode
8+
49

510
def ensure_bytes(s, encoding='utf-8', errors='strict'):
611
if isinstance(s, unicode):
@@ -17,6 +22,10 @@ def ensure_string(s, encoding='utf-8', errors='strict'):
1722
raise ValueError("Expected str or unicode, received %s." % type(s))
1823

1924
else:
25+
from base64 import encodebytes as b64_encode_bytes
26+
from base64 import decodebytes as b64_decode_bytes
27+
from urllib.parse import urlencode
28+
2029

2130
def ensure_bytes(s, encoding='utf-8', errors='strict'):
2231
if isinstance(s, str):

aliyun-python-sdk-core/alibabacloud/credentials/provider.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import os
33
import time
44

5-
from alibabacloud.exception import ClientException
5+
from alibabacloud.exceptions import ClientException
66
from alibabacloud.credentials import AccessKeyCredentials
77
from alibabacloud.credentials import BearerTokenCredentials
88
from alibabacloud.credentials import SecurityCredentials

aliyun-python-sdk-core/alibabacloud/endpoint/chained_endpoint_resolver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
# under the License.
1818
#
1919

20-
from aliyunsdkcore.acs_exception.exceptions import ClientException
20+
from alibabacloud.exceptions import ClientException
2121
from alibabacloud.endpoint import EndpointResolver
2222

2323
import aliyunsdkcore.acs_exception.error_code as error_code

aliyun-python-sdk-core/alibabacloud/endpoint/location_service_endpoint_resolver.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import threading
2121
import json
2222

23-
from aliyunsdkcore.acs_exception.exceptions import ServerException
23+
from alibabacloud.exceptions import ServerException
2424
from alibabacloud.endpoint.endpoint_resolver_base import EndpointResolverBase
2525
from alibabacloud.endpoint.location_endpoint_caller import DescribeEndpointCaller
2626
DEFAULT_LOCATION_SERVICE_ENDPOINT = "location-readonly.aliyuncs.com"
@@ -78,14 +78,14 @@ def _call_location_service(self, key, raw_request):
7878
location_endpoint=self._location_service_endpoint)
7979

8080
except ServerException as e:
81-
if "InvalidRegionId" == e.get_error_code() and \
82-
"The specified region does not exist." == e.get_error_msg():
81+
if "InvalidRegionId" == e.error_code and \
82+
"The specified region does not exist." == e.error_message:
8383
# No such region`
8484
self._invalid_region_ids.add(raw_request.region_id)
8585
self.put_endpoint_entry(key, None)
8686
return
87-
elif "Illegal Parameter" == e.get_error_code() and \
88-
"Please check the parameters" == e.get_error_msg():
87+
elif "Illegal Parameter" == e.error_code and \
88+
"Please check the parameters" == e.error_message:
8989
# No such product
9090
self._invalid_product_codes.add(raw_request.product_code_lower)
9191
self.put_endpoint_entry(key, None)

aliyun-python-sdk-core/alibabacloud/exception.py

Lines changed: 0 additions & 28 deletions
This file was deleted.
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Copyright 2019 Alibaba Cloud Inc. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
SDK_INVALID_REGION_ID = 'SDK.InvalidRegionId'
16+
SDK_SERVER_UNREACHABLE = 'SDK.ServerUnreachable'
17+
SDK_INVALID_REQUEST = 'SDK.InvalidRequest'
18+
SDK_MISSING_ENDPOINTS_FILER = 'SDK.MissingEndpointsFiler'
19+
SDK_UNKNOWN_SERVER_ERROR = 'SDK.UnknownServerError'
20+
SDK_INVALID_CREDENTIAL = 'SDK.InvalidCredential'
21+
SDK_INVALID_SESSION_EXPIRATION = 'SDK.InvalidSessionExpiration'
22+
SDK_GET_SESSION_CREDENTIAL_FAILED = 'SDK.GetSessionCredentialFailed'
23+
SDK_INVALID_PARAMS = 'SDK.InvalidParams'
24+
SDK_NOT_SUPPORT = 'SDK.NotSupport'
25+
SDK_ENDPOINT_RESOLVING_ERROR = 'SDK.EndpointResolvingError'
26+
SDK_ENDPOINT_TESTABILITY = 'SDK.EndpointTestability'
27+
SDK_HTTP_ERROR = 'SDK.HttpError'
28+
SDK_INVALID_PARAMETER = "SDK.InvalidParameter"
29+
30+
31+
class ClientException(Exception):
32+
"""client exception"""
33+
34+
def __init__(self, error_code, error_message,):
35+
"""
36+
37+
:param error_code: error code
38+
:param error_message: error message
39+
:return:
40+
"""
41+
Exception.__init__(self)
42+
self.__error_type = 'Client'
43+
self.error_code = error_code
44+
self.error_message = error_message
45+
46+
def __str__(self):
47+
return "%s %s" % (
48+
self.error_code,
49+
self.error_message,
50+
)
51+
52+
53+
class ServerException(Exception):
54+
55+
def __init__(self, error_code, error_message, endpoint=None, http_status=None, request_id=None, service_name= None):
56+
self.error_code = error_code
57+
self.error_message = error_message
58+
self.endpoint = endpoint
59+
self.http_status = http_status
60+
self.request_id = request_id
61+
# TODO service_name
62+
self.service_name = service_name
63+
64+
def __str__(self):
65+
return "HTTP Status: %s Error:%s %s RequestID: %s" % (
66+
str(self.http_status),
67+
self.error_code,
68+
self.error_message,
69+
self.request_id
70+
)
71+

aliyun-python-sdk-core/alibabacloud/handlers/http_handler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
from alibabacloud.handlers import RequestHandler
1616

17-
from alibabacloud.vendored import Request, Session
17+
from alibabacloud.vendored.requests import Request, Session
1818
from alibabacloud.vendored.requests.packages import urllib3
1919

2020

@@ -54,7 +54,7 @@ def _do_request(self, context):
5454

5555
# requests.adapters.DEFAULT_RETRIES = 0
5656
except IOError as e:
57-
from aliyunsdkcore.acs_exception.exceptions import ClientException
57+
from alibabacloud.exceptions import ClientException
5858
from aliyunsdkcore.acs_exception import error_code
5959
exception = ClientException(error_code.SDK_HTTP_ERROR, str(e))
6060

aliyun-python-sdk-core/alibabacloud/handlers/server_error_handler.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import json
1515

1616
from alibabacloud.handlers import RequestHandler
17-
from alibabacloud.vendored import codes
17+
from alibabacloud.vendored.requests import codes
1818

1919

2020
class ServerErrorHandler(RequestHandler):
@@ -46,12 +46,9 @@ def handle_response(self, context):
4646
server_error_code = 'InvalidAccessKeySecret'
4747
server_error_message = 'The AccessKeySecret is incorrect. ' \
4848
'Please check your AccessKeyId and AccessKeySecret.'
49-
from aliyunsdkcore.acs_exception.exceptions import ServerException
50-
exception = ServerException(
51-
server_error_code,
52-
server_error_message,
53-
http_status=response.status_code,
54-
request_id=request_id)
49+
from alibabacloud.exceptions import ServerException
50+
exception = ServerException(server_error_code, server_error_message,
51+
context.endpoint, response.status_code, request_id)
5552
context.exception = exception
5653

5754
@staticmethod

aliyun-python-sdk-core/alibabacloud/retry/retry_condition.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
from alibabacloud.utils.load_json_from_data_dir import _load_json_from_data_dir
1919
import alibabacloud.utils.validation as validation
20-
from aliyunsdkcore.acs_exception.exceptions import ClientException, ServerException
20+
from alibabacloud.exceptions import ServerException, ClientException
2121
import aliyunsdkcore.acs_exception.error_code as error_code
2222

2323
logger = logging.getLogger(__name__)
@@ -77,14 +77,14 @@ def should_retry(self, retry_policy_context):
7777
exception = retry_policy_context.exception
7878

7979
if isinstance(exception, ClientException):
80-
if exception.get_error_code() == error_code.SDK_HTTP_ERROR:
80+
if exception.error_code == error_code.SDK_HTTP_ERROR:
8181

8282
logger.debug("Retryable ClientException occurred. ClientException:%s",
8383
exception)
8484
return RetryCondition.SHOULD_RETRY
8585

8686
if isinstance(exception, ServerException):
87-
error_code_ = exception.get_error_code()
87+
error_code_ = exception.error_code
8888
normal_errors = _find_data_in_retry_config("RetryableNormalErrors",
8989
client,
9090
self.retry_config)

aliyun-python-sdk-core/alibabacloud/signer/composer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
from alibabacloud.utils import format_type as FormatType, parameter_helper as helper
2222
from alibabacloud.signer.algorithm import ShaHmac1 as mac1
2323
from alibabacloud.vendored.six import iteritems
24-
from alibabacloud.vendored.six import pathname2url
24+
from alibabacloud.vendored.six.moves.urllib.request import pathname2url
2525
from alibabacloud.compat import urlencode
26-
from aliyunsdkcore.acs_exception.exceptions import ClientException
26+
from alibabacloud.exceptions import ClientException
2727
from alibabacloud.utils.parameter_helper import md5_sum
2828

2929
FORMAT_ISO_8601 = "%Y-%m-%dT%H:%M:%SZ"

0 commit comments

Comments
 (0)