Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/boto3/compat.py: 48%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

33 statements  

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. 

13import sys 

14import os 

15import errno 

16import socket 

17import warnings 

18 

19from boto3.exceptions import PythonDeprecationWarning 

20 

21from s3transfer.manager import TransferConfig 

22 

23# In python3, socket.error is OSError, which is too general 

24# for what we want (i.e FileNotFoundError is a subclass of OSError). 

25# In py3 all the socket related errors are in a newly created 

26# ConnectionError 

27SOCKET_ERROR = ConnectionError 

28 

29_APPEND_MODE_CHAR = 'a' 

30 

31import collections.abc as collections_abc 

32 

33 

34TRANSFER_CONFIG_SUPPORTS_CRT = hasattr(TransferConfig, 'UNSET_DEFAULT') 

35 

36 

37if sys.platform.startswith('win'): 

38 def rename_file(current_filename, new_filename): 

39 try: 

40 os.remove(new_filename) 

41 except OSError as e: 

42 if not e.errno == errno.ENOENT: 

43 # We only want to a ignore trying to remove 

44 # a file that does not exist. If it fails 

45 # for any other reason we should be propagating 

46 # that exception. 

47 raise 

48 os.rename(current_filename, new_filename) 

49else: 

50 rename_file = os.rename 

51 

52 

53def filter_python_deprecation_warnings(): 

54 """ 

55 Invoking this filter acknowledges your runtime will soon be deprecated 

56 at which time you will stop receiving all updates to your client. 

57 """ 

58 warnings.filterwarnings( 

59 'ignore', 

60 message=".*Boto3 will no longer support Python.*", 

61 category=PythonDeprecationWarning, 

62 module=r".*boto3\.compat" 

63 ) 

64 

65 

66def _warn_deprecated_python(): 

67 """Use this template for future deprecation campaigns as needed.""" 

68 py_39_params = { 

69 'date': 'April 29, 2026', 

70 'blog_link': ( 

71 'https://aws.amazon.com/blogs/developer/' 

72 'python-support-policy-updates-for-aws-sdks-and-tools/' 

73 ) 

74 } 

75 deprecated_versions = { 

76 # Example template for future deprecations 

77 (3, 9): py_39_params, 

78 } 

79 py_version = sys.version_info[:2] 

80 

81 if py_version in deprecated_versions: 

82 params = deprecated_versions[py_version] 

83 warning = ( 

84 "Boto3 will no longer support Python {}.{} " 

85 "starting {}. To continue receiving service updates, " 

86 "bug fixes, and security updates please upgrade to Python 3.10 or " 

87 "later. More information can be found here: {}" 

88 ).format(py_version[0], py_version[1], params['date'], params['blog_link']) 

89 warnings.warn(warning, PythonDeprecationWarning) 

90 

91 

92def is_append_mode(fileobj): 

93 return ( 

94 hasattr(fileobj, 'mode') and 

95 isinstance(fileobj.mode, str) and 

96 _APPEND_MODE_CHAR in fileobj.mode 

97 )