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

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

31 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 

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 

25SOCKET_ERROR = ConnectionError 

26 

27_APPEND_MODE_CHAR = 'a' 

28 

29import collections.abc as collections_abc 

30 

31 

32if 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) 

44else: 

45 rename_file = os.rename 

46 

47 

48def 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 

61def _warn_deprecated_python(): 

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

63 py_37_params = { 

64 'date': 'December 13, 2023', 

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, 7): py_37_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.8 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 

87def 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 )