Recursively delete a directory tree. If dir_fd is not None, it should be a file descriptor open to a directory; path will then be relative to that directory. dir_fd may not be implemented on your platform. If it is unavailable, using it will raise a NotImplementedError. If igno
(path, ignore_errors=False, onerror=None, *, onexc=None, dir_fd=None)
| 808 | _rmtree_impl = _rmtree_safe_fd if _use_fd_functions else _rmtree_unsafe |
| 809 | |
| 810 | def rmtree(path, ignore_errors=False, onerror=None, *, onexc=None, dir_fd=None): |
| 811 | """Recursively delete a directory tree. |
| 812 | |
| 813 | If dir_fd is not None, it should be a file descriptor open to a directory; |
| 814 | path will then be relative to that directory. |
| 815 | dir_fd may not be implemented on your platform. |
| 816 | If it is unavailable, using it will raise a NotImplementedError. |
| 817 | |
| 818 | If ignore_errors is set, errors are ignored; otherwise, if onexc or |
| 819 | onerror is set, it is called to handle the error with arguments (func, |
| 820 | path, exc_info) where func is platform and implementation dependent; |
| 821 | path is the argument to that function that caused it to fail; and |
| 822 | the value of exc_info describes the exception. For onexc it is the |
| 823 | exception instance, and for onerror it is a tuple as returned by |
| 824 | sys.exc_info(). If ignore_errors is false and both onexc and |
| 825 | onerror are None, the exception is reraised. |
| 826 | |
| 827 | onerror is deprecated and only remains for backwards compatibility. |
| 828 | If both onerror and onexc are set, onerror is ignored and onexc is used. |
| 829 | """ |
| 830 | |
| 831 | sys.audit("shutil.rmtree", path, dir_fd) |
| 832 | if ignore_errors: |
| 833 | def onexc(*args): |
| 834 | pass |
| 835 | elif onerror is None and onexc is None: |
| 836 | def onexc(*args): |
| 837 | raise |
| 838 | elif onexc is None: |
| 839 | if onerror is None: |
| 840 | def onexc(*args): |
| 841 | raise |
| 842 | else: |
| 843 | # delegate to onerror |
| 844 | def onexc(*args): |
| 845 | func, path, exc = args |
| 846 | if exc is None: |
| 847 | exc_info = None, None, None |
| 848 | else: |
| 849 | exc_info = type(exc), exc, exc.__traceback__ |
| 850 | return onerror(func, path, exc_info) |
| 851 | |
| 852 | _rmtree_impl(path, dir_fd, onexc) |
| 853 | |
| 854 | # Allow introspection of whether or not the hardening against symlink |
| 855 | # attacks is supported on the current platform |