Skip to content

Commit

Permalink
bump botocore dependency specification
Browse files Browse the repository at this point in the history
  • Loading branch information
jakob-keller committed Dec 16, 2024
1 parent 3ddd8db commit 1f87027
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 34 deletions.
4 changes: 2 additions & 2 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
Changes
-------

2.15.3 (2024-10-27)
2.16.0 (2024-12-16)
^^^^^^^^^^^^^^^^^^^
* relax botocore dependency specification
* bump botocore dependency specification

2.15.2 (2024-10-09)
^^^^^^^^^^^^^^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion aiobotocore/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '2.15.3'
__version__ = '2.16.0'
25 changes: 5 additions & 20 deletions aiobotocore/handlers.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from botocore.handlers import (
ETree,
XMLParseError,
_get_cross_region_presigned_url,
_get_presigned_url_source_and_destination_regions,
_looks_like_special_case_error,
logger,
)


async def check_for_200_error(response, **kwargs):
"""This function has been deprecated, but is kept for backwards compatibility."""
# From: http://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectCOPY.html
# There are two opportunities for a copy request to return an error. One
# can occur when Amazon S3 receives the copy request and the other can
Expand All @@ -28,7 +29,9 @@ async def check_for_200_error(response, **kwargs):
# trying to retrieve the response. See Endpoint._get_response().
return
http_response, parsed = response
if await _looks_like_special_case_error(http_response):
if _looks_like_special_case_error(
http_response.status_code, await http_response.content
):
logger.debug(
"Error found for response with 200 status code, "
"errors: %s, changing status code to "
Expand All @@ -38,24 +41,6 @@ async def check_for_200_error(response, **kwargs):
http_response.status_code = 500


async def _looks_like_special_case_error(http_response):
if http_response.status_code == 200:
try:
parser = ETree.XMLParser(
target=ETree.TreeBuilder(), encoding='utf-8'
)
parser.feed(await http_response.content)
root = parser.close()
except XMLParseError:
# In cases of network disruptions, we may end up with a partial
# streamed response from S3. We need to treat these cases as
# 500 Service Errors and try again.
return True
if root.tag == 'Error':
return True
return False


async def inject_presigned_url_ec2(params, request_signer, model, **kwargs):
# The customer can still provide this, so we should pass if they do.
if 'PresignedUrl' in params['body']:
Expand Down
3 changes: 0 additions & 3 deletions aiobotocore/hooks.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from botocore.handlers import check_for_200_error as boto_check_for_200_error
from botocore.handlers import (
inject_presigned_url_ec2 as boto_inject_presigned_url_ec2,
)
Expand All @@ -21,7 +20,6 @@

from ._helpers import resolve_awaitable
from .handlers import (
check_for_200_error,
inject_presigned_url_ec2,
inject_presigned_url_rds,
parse_get_bucket_location,
Expand All @@ -39,7 +37,6 @@
boto_add_generate_presigned_post: add_generate_presigned_post,
boto_add_generate_db_auth_token: add_generate_db_auth_token,
boto_parse_get_bucket_location: parse_get_bucket_location,
boto_check_for_200_error: check_for_200_error,
}


Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@ classifiers = [
dynamic = ["version", "readme"]

dependencies = [
"botocore >=1.35.16, <1.35.45", # NOTE: When updating, always keep `project.optional-dependencies` aligned
"botocore >=1.35.47, <1.35.67", # NOTE: When updating, always keep `project.optional-dependencies` aligned
"aiohttp >=3.9.2, <4.0.0",
"wrapt >=1.10.10, <2.0.0",
"aioitertools >=0.5.1, <1.0.0",
]

[project.optional-dependencies]
awscli = [
"awscli >=1.34.16, <1.35.11",
"awscli >=1.35.13, <1.36.8",
]
boto3 = [
"boto3 >=1.35.16, <1.35.45",
"boto3 >=1.35.47, <1.35.67",
]

[project.urls]
Expand Down
53 changes: 53 additions & 0 deletions tests/boto_tests/unit/test_handlers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Copyright 2012-2014 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You
# may not use this file except in compliance with the License. A copy of
# the License is located at
#
# http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.

from unittest import mock

from aiobotocore import handlers


class TestHandlers:
async def test_500_status_code_set_for_200_response(self):
http_response = mock.Mock()
http_response.status_code = 200

async def content():
return """
<Error>
<Code>AccessDenied</Code>
<Message>Access Denied</Message>
<RequestId>id</RequestId>
<HostId>hostid</HostId>
</Error>
"""

http_response.content = content()
await handlers.check_for_200_error((http_response, {}))
assert http_response.status_code == 500

async def test_200_response_with_no_error_left_untouched(self):
http_response = mock.Mock()
http_response.status_code = 200

async def content():
return "<NotAnError></NotAnError>"

http_response.content = content()
await handlers.check_for_200_error((http_response, {}))
# We don't touch the status code since there are no errors present.
assert http_response.status_code == 200

async def test_500_response_can_be_none(self):
# A 500 response can raise an exception, which means the response
# object is None. We need to handle this case.
await handlers.check_for_200_error(None)
11 changes: 6 additions & 5 deletions tests/test_patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
)
from botocore.eventstream import EventStream
from botocore.handlers import (
_looks_like_special_case_error,
check_for_200_error,
inject_presigned_url_ec2,
inject_presigned_url_rds,
Expand Down Expand Up @@ -202,6 +201,7 @@
Config.merge: {'c3dd8c3ffe0da86953ceba4a35267dfb79c6a2c8'},
Config: {
'823f8d031fc7218a600a56268a369aaa878f46c8',
'b1bd1c2cb9a20afa98db306c803617543ffecbf4',
},
# credentials.py
create_mfa_serial_refresher: {'9b5e98782fcacdcea5899a6d0d29d1b9de348bb0'},
Expand Down Expand Up @@ -487,11 +487,13 @@
'd03631d6810e2453b8874bc76619927b694a4207',
},
S3PostPresigner.generate_presigned_post: {
'269efc9af054a2fd2728d5b0a27db82c48053d7f'
'269efc9af054a2fd2728d5b0a27db82c48053d7f',
'48418dc6c9b04fdc8689c7cb5b6eb987321a84e3',
},
add_generate_presigned_post: {'e30360f2bd893fabf47f5cdb04b0de420ccd414d'},
generate_presigned_post: {
'a3a834a08be2cf76c20ea137ba6b28e7a12f58ed',
'd93240c58dcda7b63cf2b7144ee0fea110f0e762',
},
add_generate_db_auth_token: {'f61014e6fac4b5c7ee7ac2d2bec15fb16fa9fbe5'},
generate_db_auth_token: {'1f37e1e5982d8528841ce6b79f229b3e23a18959'},
Expand Down Expand Up @@ -623,9 +625,8 @@
inject_presigned_url_rds: {'b5d45b339686346e81b255d4e8c36e76d3fe6a78'},
inject_presigned_url_ec2: {'48e09a5e4e95577e716be30f2d2706949261a07f'},
parse_get_bucket_location: {'64ffbf5c6aa6ebd083f49371000fa046d0de1fc6'},
check_for_200_error: {'ded7f3aaef7b1a5d047c4dac86692ab55cbd7a13'},
_looks_like_special_case_error: {
'86946722d10a72b593483fca0abf30100c609178'
check_for_200_error: {
'3a00f0bea409528f8457d6569aecf05998094386',
},
# httpsession.py
URLLib3Session: {
Expand Down

0 comments on commit 1f87027

Please sign in to comment.