| 1 |
# Copyright 2015 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 2 |
# |
| 3 |
# Licensed under the Apache License, Version 2.0 (the "License"). You |
| 4 |
# may not use this file except in compliance with the License. A copy of |
| 5 |
# the License is located at |
| 6 |
# |
| 7 |
# https://aws.amazon.com/apache2.0/ |
| 8 |
# |
| 9 |
# or in the "license" file accompanying this file. This file is |
| 10 |
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF |
| 11 |
# ANY KIND, either express or implied. See the License for the specific |
| 12 |
# language governing permissions and limitations under the License. |
| 13 |
import sys |
| 14 |
import os |
| 15 |
import errno |
| 16 |
import socket |
| 17 |
import warnings |
| 18 |
|
| 19 |
from boto3.exceptions import PythonDeprecationWarning |
| 20 |
|
| 21 |
# In python3, socket.error is OSError, which is too general |
| 22 |
# for what we want (i.e FileNotFoundError is a subclass of OSError). |
| 23 |
# In py3 all the socket related errors are in a newly created |
| 24 |
# ConnectionError |
| 25 |
SOCKET_ERROR = ConnectionError |
| 26 |
|
| 27 |
_APPEND_MODE_CHAR = 'a' |
| 28 |
|
| 29 |
import collections.abc as collections_abc |
| 30 |
|
| 31 |
|
| 32 |
if sys.platform.startswith('win'): |
| 33 |
def rename_file(current_filename, new_filename): |
| 34 |
try: |
| 35 |
os.remove(new_filename) |
| 36 |
except OSError as e: |
| 37 |
if not e.errno == errno.ENOENT: |
| 38 |
# We only want to a ignore trying to remove |
| 39 |
# a file that does not exist. If it fails |
| 40 |
# for any other reason we should be propagating |
| 41 |
# that exception. |
| 42 |
raise |
| 43 |
os.rename(current_filename, new_filename) |
| 44 |
else: |
| 45 |
rename_file = os.rename |
| 46 |
|
| 47 |
|
| 48 |
def filter_python_deprecation_warnings(): |
| 49 |
""" |
| 50 |
Invoking this filter acknowledges your runtime will soon be deprecated |
| 51 |
at which time you will stop receiving all updates to your client. |
| 52 |
""" |
| 53 |
warnings.filterwarnings( |
| 54 |
'ignore', |
| 55 |
message=".*Boto3 will no longer support Python.*", |
| 56 |
category=PythonDeprecationWarning, |
| 57 |
module=r".*boto3\.compat" |
| 58 |
) |
| 59 |
|
| 60 |
|
| 61 |
def _warn_deprecated_python(): |
| 62 |
"""Use this template for future deprecation campaigns as needed.""" |
| 63 |
py_39_params = { |
| 64 |
'date': 'April 29, 2026', |
| 65 |
'blog_link': ( |
| 66 |
'https://aws.amazon.com/blogs/developer/' |
| 67 |
'python-support-policy-updates-for-aws-sdks-and-tools/' |
| 68 |
) |
| 69 |
} |
| 70 |
deprecated_versions = { |
| 71 |
# Example template for future deprecations |
| 72 |
(3, 9): py_39_params, |
| 73 |
} |
| 74 |
py_version = sys.version_info[:2] |
| 75 |
|
| 76 |
if py_version in deprecated_versions: |
| 77 |
params = deprecated_versions[py_version] |
| 78 |
warning = ( |
| 79 |
"Boto3 will no longer support Python {}.{} " |
| 80 |
"starting {}. To continue receiving service updates, " |
| 81 |
"bug fixes, and security updates please upgrade to Python 3.10 or " |
| 82 |
"later. More information can be found here: {}" |
| 83 |
).format(py_version[0], py_version[1], params['date'], params['blog_link']) |
| 84 |
warnings.warn(warning, PythonDeprecationWarning) |
| 85 |
|
| 86 |
|
| 87 |
def is_append_mode(fileobj): |
| 88 |
return ( |
| 89 |
hasattr(fileobj, 'mode') and |
| 90 |
isinstance(fileobj.mode, str) and |
| 91 |
_APPEND_MODE_CHAR in fileobj.mode |
| 92 |
) |