You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.5 KiB

4 years ago
  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. # http://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. from botocore.vendored import six
  18. if six.PY3:
  19. # In python3, socket.error is OSError, which is too general
  20. # for what we want (i.e FileNotFoundError is a subclass of OSError).
  21. # In py3 all the socket related errors are in a newly created
  22. # ConnectionError
  23. SOCKET_ERROR = ConnectionError
  24. else:
  25. SOCKET_ERROR = socket.error
  26. if sys.platform.startswith('win'):
  27. def rename_file(current_filename, new_filename):
  28. try:
  29. os.remove(new_filename)
  30. except OSError as e:
  31. if not e.errno == errno.ENOENT:
  32. # We only want to a ignore trying to remove
  33. # a file that does not exist. If it fails
  34. # for any other reason we should be propagating
  35. # that exception.
  36. raise
  37. os.rename(current_filename, new_filename)
  38. else:
  39. rename_file = os.rename