diff --git a/send2trash/IFileOperationProgressSink.py b/send2trash/IFileOperationProgressSink.py index 24359ea..c8f5234 100644 --- a/send2trash/IFileOperationProgressSink.py +++ b/send2trash/IFileOperationProgressSink.py @@ -35,9 +35,7 @@ class FileOperationProgressSink(DesignatedWrapPolicy): # Can detect cases where to stop via flags and condition below, however the operation # does not actual stop, we can resort to raising an exception as that does stop things # but that may need some additional considerations before implementing. - return ( - 0 if flags & shellcon.TSF_DELETE_RECYCLE_IF_POSSIBLE else 0x80004005 - ) # S_OK, or E_FAIL + return 0 if flags & shellcon.TSF_DELETE_RECYCLE_IF_POSSIBLE else 0x80004005 # S_OK, or E_FAIL def PostDeleteItem(self, flags, item, hrDelete, newlyCreated): if newlyCreated: @@ -58,31 +56,20 @@ class FileOperationProgressSink(DesignatedWrapPolicy): def PreMoveItem(self, Flags, Item, DestinationFolder, NewName): pass - def PostMoveItem( - self, Flags, Item, DestinationFolder, NewName, hrMove, NewlyCreated - ): + def PostMoveItem(self, Flags, Item, DestinationFolder, NewName, hrMove, NewlyCreated): pass def PreCopyItem(self, Flags, Item, DestinationFolder, NewName): pass - def PostCopyItem( - self, Flags, Item, DestinationFolder, NewName, hrCopy, NewlyCreated - ): + def PostCopyItem(self, Flags, Item, DestinationFolder, NewName, hrCopy, NewlyCreated): pass def PreNewItem(self, Flags, DestinationFolder, NewName): pass def PostNewItem( - self, - Flags, - DestinationFolder, - NewName, - TemplateName, - FileAttributes, - hrNew, - NewItem, + self, Flags, DestinationFolder, NewName, TemplateName, FileAttributes, hrNew, NewItem, ): pass @@ -100,6 +87,4 @@ class FileOperationProgressSink(DesignatedWrapPolicy): def CreateSink(): - return pythoncom.WrapObject( - FileOperationProgressSink(), shell.IID_IFileOperationProgressSink - ) + return pythoncom.WrapObject(FileOperationProgressSink(), shell.IID_IFileOperationProgressSink) diff --git a/send2trash/__main__.py b/send2trash/__main__.py index 0f73a64..a733e82 100644 --- a/send2trash/__main__.py +++ b/send2trash/__main__.py @@ -14,20 +14,20 @@ from send2trash import send2trash def main(args=None): - parser = ArgumentParser(description='Tool to send files to trash') - parser.add_argument('files', nargs='+') - parser.add_argument('-v', '--verbose', action='store_true', help='Print deleted files') + parser = ArgumentParser(description="Tool to send files to trash") + parser.add_argument("files", nargs="+") + parser.add_argument("-v", "--verbose", action="store_true", help="Print deleted files") args = parser.parse_args(args) for filename in args.files: try: send2trash(filename) if args.verbose: - print('Trashed «' + filename + '»') + print("Trashed «" + filename + "»") except OSError as e: print(str(e), file=sys.stderr) sys.exit(1) -if __name__ == '__main__': +if __name__ == "__main__": main() diff --git a/send2trash/plat_osx_ctypes.py b/send2trash/plat_osx_ctypes.py index 05a70eb..4b8c2b3 100644 --- a/send2trash/plat_osx_ctypes.py +++ b/send2trash/plat_osx_ctypes.py @@ -42,10 +42,7 @@ def check_op_result(op_result): def send2trash(paths): paths = preprocess_paths(paths) - paths = [ - path.encode("utf-8") if not isinstance(path, binary_type) else path - for path in paths - ] + paths = [path.encode("utf-8") if not isinstance(path, binary_type) else path for path in paths] for path in paths: fp = FSRef() opts = kFSPathMakeRefDoNotFollowLeafSymlink diff --git a/send2trash/plat_osx_pyobjc.py b/send2trash/plat_osx_pyobjc.py index 49d111c..8694444 100644 --- a/send2trash/plat_osx_pyobjc.py +++ b/send2trash/plat_osx_pyobjc.py @@ -18,10 +18,7 @@ def check_op_result(op_result): def send2trash(paths): paths = preprocess_paths(paths) - paths = [ - path.decode("utf-8") if not isinstance(path, text_type) else path - for path in paths - ] + paths = [path.decode("utf-8") if not isinstance(path, text_type) else path for path in paths] for path in paths: file_url = NSURL.fileURLWithPath_(path) fm = NSFileManager.defaultManager() diff --git a/send2trash/plat_other.py b/send2trash/plat_other.py index 78da82f..37dd211 100644 --- a/send2trash/plat_other.py +++ b/send2trash/plat_other.py @@ -103,9 +103,7 @@ def trash_move(src, dst, topdir=None): counter = 0 destname = filename - while op.exists(op.join(filespath, destname)) or op.exists( - op.join(infopath, destname + INFO_SUFFIX) - ): + while op.exists(op.join(filespath, destname)) or op.exists(op.join(infopath, destname + INFO_SUFFIX)): counter += 1 destname = base_name + b" " + text_type(counter).encode("ascii") + ext diff --git a/send2trash/plat_win_legacy.py b/send2trash/plat_win_legacy.py index 31b8910..137c592 100644 --- a/send2trash/plat_win_legacy.py +++ b/send2trash/plat_win_legacy.py @@ -105,10 +105,7 @@ def get_short_path_name(long_name): def send2trash(paths): paths = preprocess_paths(paths) # convert data type - paths = [ - text_type(path, "mbcs") if not isinstance(path, text_type) else path - for path in paths - ] + paths = [text_type(path, "mbcs") if not isinstance(path, text_type) else path for path in paths] # convert to full paths paths = [op.abspath(path) if not op.isabs(path) else path for path in paths] # get short path to handle path length issues diff --git a/send2trash/plat_win_modern.py b/send2trash/plat_win_modern.py index 1569911..5f30713 100644 --- a/send2trash/plat_win_modern.py +++ b/send2trash/plat_win_modern.py @@ -18,10 +18,7 @@ from .IFileOperationProgressSink import CreateSink def send2trash(paths): paths = preprocess_paths(paths) # convert data type - paths = [ - text_type(path, "mbcs") if not isinstance(path, text_type) else path - for path in paths - ] + paths = [text_type(path, "mbcs") if not isinstance(path, text_type) else path for path in paths] # convert to full paths paths = [op.abspath(path) if not op.isabs(path) else path for path in paths] # remove the leading \\?\ if present @@ -33,19 +30,11 @@ def send2trash(paths): shell.CLSID_FileOperation, None, pythoncom.CLSCTX_ALL, shell.IID_IFileOperation, ) # default flags to use - flags = ( - shellcon.FOF_NOCONFIRMATION - | shellcon.FOF_NOERRORUI - | shellcon.FOF_SILENT - | shellcon.FOFX_EARLYFAILURE - ) + flags = shellcon.FOF_NOCONFIRMATION | shellcon.FOF_NOERRORUI | shellcon.FOF_SILENT | shellcon.FOFX_EARLYFAILURE # determine rest of the flags based on OS version # use newer recommended flags if available if int(version().split(".", 1)[0]) >= 8: - flags |= ( - 0x20000000 # FOFX_ADDUNDORECORD win 8+ - | 0x00080000 # FOFX_RECYCLEONDELETE win 8+ - ) + flags |= 0x20000000 | 0x00080000 # FOFX_ADDUNDORECORD win 8+ # FOFX_RECYCLEONDELETE win 8+ else: flags |= shellcon.FOF_ALLOWUNDO # set the flags diff --git a/send2trash/util.py b/send2trash/util.py index 677a856..2c73d44 100644 --- a/send2trash/util.py +++ b/send2trash/util.py @@ -10,7 +10,5 @@ def preprocess_paths(paths): if not isinstance(paths, list): paths = [paths] # Convert items such as pathlib paths to strings - paths = [ - path.__fspath__() if hasattr(path, "__fspath__") else path for path in paths - ] + paths = [path.__fspath__() if hasattr(path, "__fspath__") else path for path in paths] return paths diff --git a/tests/test_plat_other.py b/tests/test_plat_other.py index e4d10b0..6a796fa 100644 --- a/tests/test_plat_other.py +++ b/tests/test_plat_other.py @@ -28,9 +28,7 @@ else: @pytest.fixture def testfile(): - file = NamedTemporaryFile( - dir=op.expanduser("~"), prefix="send2trash_test", delete=False - ) + file = NamedTemporaryFile(dir=op.expanduser("~"), prefix="send2trash_test", delete=False) file.close() assert op.exists(file.name) is True yield file @@ -50,9 +48,7 @@ def testfiles(): files = list( map( lambda index: NamedTemporaryFile( - dir=op.expanduser("~"), - prefix="send2trash_test{}".format(index), - delete=False, + dir=op.expanduser("~"), prefix="send2trash_test{}".format(index), delete=False, ), range(10), ) @@ -62,10 +58,7 @@ def testfiles(): yield files filenames = [op.basename(file.name) for file in files] [os.remove(op.join(HOMETRASH, "files", filename)) for filename in filenames] - [ - os.remove(op.join(HOMETRASH, "info", filename + ".trashinfo")) - for filename in filenames - ] + [os.remove(op.join(HOMETRASH, "info", filename + ".trashinfo")) for filename in filenames] def test_trash(testfile): @@ -136,10 +129,7 @@ class ExtVol: return st.st_dev def s_ismount(path): - if op.realpath(path) in ( - op.realpath(self.trashTopdir), - op.realpath(self.trashTopdir_b), - ): + if op.realpath(path) in (op.realpath(self.trashTopdir), op.realpath(self.trashTopdir_b),): return True return old_ismount(path) @@ -172,15 +162,8 @@ def test_trash_topdir(testExtVol): s2t(testExtVol[2]) assert op.exists(testExtVol[2]) is False - assert ( - op.exists(op.join(trashDir, str(os.getuid()), "files", testExtVol[1])) is True - ) - assert ( - op.exists( - op.join(trashDir, str(os.getuid()), "info", testExtVol[1] + ".trashinfo",) - ) - is True - ) + assert op.exists(op.join(trashDir, str(os.getuid()), "files", testExtVol[1])) is True + assert op.exists(op.join(trashDir, str(os.getuid()), "info", testExtVol[1] + ".trashinfo",)) is True # info relative path (if another test is added, with the same fileName/Path, # then it gets renamed etc.) cfg = ConfigParser() @@ -191,17 +174,7 @@ def test_trash_topdir(testExtVol): def test_trash_topdir_fallback(testExtVol): s2t(testExtVol[2]) assert op.exists(testExtVol[2]) is False - assert ( - op.exists( - op.join( - testExtVol[0].trashTopdir, - ".Trash-" + str(os.getuid()), - "files", - testExtVol[1], - ) - ) - is True - ) + assert op.exists(op.join(testExtVol[0].trashTopdir, ".Trash-" + str(os.getuid()), "files", testExtVol[1],)) is True def test_trash_topdir_failure(testExtVol): @@ -221,15 +194,5 @@ def test_trash_symlink(testExtVol): os.symlink(op.join(testExtVol[0].trashTopdir, "subdir"), slDir) s2t(op.join(slDir, testExtVol[1])) assert op.exists(filePath) is False - assert ( - op.exists( - op.join( - testExtVol[0].trashTopdir, - ".Trash-" + str(os.getuid()), - "files", - testExtVol[1], - ) - ) - is True - ) + assert op.exists(op.join(testExtVol[0].trashTopdir, ".Trash-" + str(os.getuid()), "files", testExtVol[1],)) is True os.remove(slDir) diff --git a/tests/test_script_main.py b/tests/test_script_main.py index 22ac9c2..cc5c669 100644 --- a/tests/test_script_main.py +++ b/tests/test_script_main.py @@ -14,9 +14,7 @@ if sys.platform != "win32": @pytest.fixture def file(): - file = NamedTemporaryFile( - dir=op.expanduser("~"), prefix="send2trash_test", delete=False - ) + file = NamedTemporaryFile(dir=op.expanduser("~"), prefix="send2trash_test", delete=False) file.close() # Verify file was actually created assert op.exists(file.name) is True