1
0
mirror of https://github.com/arsenetar/send2trash.git synced 2025-08-30 04:29:42 +00:00

Compare commits

..

No commits in common. "9a2c5bc6902843eb95f78ef3709aecc40b06f834" and "91d06989678ecd78ec8878d527ba70f59b60a45b" have entirely different histories.

15 changed files with 83 additions and 38 deletions

View File

@ -2,15 +2,19 @@
name: Default CI/CD
on: push
on:
push:
branches: [master]
pull_request:
branches: [master]
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- uses: actions/checkout@v4
- name: Set up Python 3.x
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
uses: actions/setup-python@v5
with:
python-version: 3.x
- name: Install dependencies
@ -26,8 +30,6 @@ jobs:
strategy:
matrix:
include:
- os: ubuntu-latest
python-version: 3.13
- os: ubuntu-latest
python-version: 3.12
- os: ubuntu-latest
@ -38,19 +40,27 @@ jobs:
python-version: 3.9
- os: ubuntu-latest
python-version: 3.8
- os: ubuntu-latest
python-version: 3.7
- os: ubuntu-latest
python-version: 2.7
# - os: macos-latest
# python-version: 3.13
# - os: macos-latest
# python-version: 3.11
# - os: macos-latestgit push
# python-version: 3.8
# - os: macos-latest
# python-version: 2.7
- os: windows-latest
python-version: 3.13
python-version: 3.12
- os: windows-latest
python-version: 3.8
- os: windows-latest
python-version: 2.7
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
uses: LizardByte/setup-python-action@master
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies

View File

@ -1,5 +1,5 @@
[build-system]
requires = ["setuptools >= 75.3.1"]
requires = ["setuptools >= 40.6.0"]
build-backend = "setuptools.build_meta"
[tool.black]

View File

@ -8,9 +8,6 @@ import sys
from send2trash.exceptions import TrashPermissionError # noqa: F401
if sys.version_info[0] < 3:
raise RuntimeError("send2trash is only compatible with Python 3 and above (use versions <= 1.8.3 for python 2).")
if sys.platform == "darwin":
from send2trash.mac import send2trash
elif sys.platform == "win32":

View File

@ -12,9 +12,6 @@ import sys
from argparse import ArgumentParser
from send2trash import send2trash
if sys.version_info[0] < 3:
raise RuntimeError("send2trash is only compatible with Python 3 and above (use versions <= 1.8.3 for python 2).")
def main(args=None):
parser = ArgumentParser(description="Tool to send files to trash")

25
send2trash/compat.py Normal file
View File

@ -0,0 +1,25 @@
# Copyright 2017 Virgil Dupras
# This software is licensed under the "BSD" License as described in the "LICENSE" file,
# which should be included with this package. The terms are also available at
# http://www.hardcoded.net/licenses/bsd_license
import sys
import os
PY3 = sys.version_info[0] >= 3
if PY3:
text_type = str
binary_type = bytes
if os.supports_bytes_environ:
# environb will be unset under Windows, but then again we're not supposed to use it.
environb = os.environb
else:
text_type = unicode # noqa: F821
binary_type = str
environb = os.environ
try:
from collections.abc import Iterable as iterable_type
except ImportError:
from collections import Iterable as iterable_type # noqa: F401

View File

@ -1,7 +1,13 @@
import errno
from send2trash.compat import PY3
if PY3:
_permission_error = PermissionError # noqa: F821
else:
_permission_error = OSError
class TrashPermissionError(PermissionError):
class TrashPermissionError(_permission_error):
"""A permission error specific to a trash directory.
Raising this error indicates that permissions prevent us efficiently
@ -17,4 +23,4 @@ class TrashPermissionError(PermissionError):
"""
def __init__(self, filename):
PermissionError.__init__(self, errno.EACCES, "Permission denied", filename)
_permission_error.__init__(self, errno.EACCES, "Permission denied", filename)

View File

@ -9,6 +9,7 @@ from __future__ import unicode_literals
from ctypes import cdll, byref, Structure, c_char, c_char_p
from ctypes.util import find_library
from send2trash.compat import binary_type
from send2trash.util import preprocess_paths
Foundation = cdll.LoadLibrary(find_library("Foundation"))
@ -41,7 +42,7 @@ def check_op_result(op_result):
def send2trash(paths):
paths = preprocess_paths(paths)
paths = [path.encode("utf-8") if not isinstance(path, bytes) 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

View File

@ -5,6 +5,7 @@
# http://www.hardcoded.net/licenses/bsd_license
from Foundation import NSFileManager, NSURL
from send2trash.compat import text_type
from send2trash.util import preprocess_paths
@ -17,7 +18,7 @@ def check_op_result(op_result):
def send2trash(paths):
paths = preprocess_paths(paths)
paths = [path.decode("utf-8") if not isinstance(path, str) 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()

View File

@ -30,6 +30,7 @@ except ImportError:
# Python 2
from urllib import quote
from send2trash.compat import text_type, environb
from send2trash.util import preprocess_paths
from send2trash.exceptions import TrashPermissionError
@ -52,21 +53,21 @@ INFO_DIR = b"info"
INFO_SUFFIX = b".trashinfo"
# Default of ~/.local/share [3]
XDG_DATA_HOME = op.expanduser(os.environb.get(b"XDG_DATA_HOME", b"~/.local/share"))
XDG_DATA_HOME = op.expanduser(environb.get(b"XDG_DATA_HOME", b"~/.local/share"))
HOMETRASH_B = op.join(XDG_DATA_HOME, b"Trash")
HOMETRASH = fsdecode(HOMETRASH_B)
uid = os.getuid()
TOPDIR_TRASH = b".Trash"
TOPDIR_FALLBACK = b".Trash-" + str(uid).encode("ascii")
TOPDIR_FALLBACK = b".Trash-" + text_type(uid).encode("ascii")
def is_parent(parent, path):
path = op.realpath(path) # In case it's a symlink
if isinstance(path, str):
if isinstance(path, text_type):
path = fsencode(path)
parent = op.realpath(parent)
if isinstance(parent, str):
if isinstance(parent, text_type):
parent = fsencode(parent)
return path.startswith(parent)
@ -105,7 +106,7 @@ def trash_move(src, dst, topdir=None, cross_dev=False):
destname = filename
while op.exists(op.join(filespath, destname)) or op.exists(op.join(infopath, destname + INFO_SUFFIX)):
counter += 1
destname = base_name + b" " + str(counter).encode("ascii") + ext
destname = base_name + b" " + text_type(counter).encode("ascii") + ext
check_create(filespath)
check_create(infopath)
@ -141,7 +142,7 @@ def find_ext_volume_global_trash(volume_root):
if not op.isdir(trash_dir) or op.islink(trash_dir) or not (mode & stat.S_ISVTX):
return None
trash_dir = op.join(trash_dir, str(uid).encode("ascii"))
trash_dir = op.join(trash_dir, text_type(uid).encode("ascii"))
try:
check_create(trash_dir)
except OSError:
@ -177,7 +178,7 @@ def get_dev(path):
def send2trash(paths):
paths = preprocess_paths(paths)
for path in paths:
if isinstance(path, str):
if isinstance(path, text_type):
path_b = fsencode(path)
elif isinstance(path, bytes):
path_b = path

View File

@ -5,11 +5,11 @@
# which should be included with this package. The terms are also available at
# http://www.hardcoded.net/licenses/bsd_license
import collections.abc
from send2trash.compat import text_type, binary_type, iterable_type
def preprocess_paths(paths):
if isinstance(paths, collections.abc.Iterable) and not isinstance(paths, (str, bytes)):
if isinstance(paths, iterable_type) and not isinstance(paths, (text_type, binary_type)):
paths = list(paths)
elif not isinstance(paths, list):
paths = [paths]

View File

@ -7,6 +7,7 @@
from __future__ import unicode_literals
import os.path as op
from send2trash.compat import text_type
from send2trash.util import preprocess_paths
from ctypes import (
@ -142,7 +143,7 @@ def send2trash(paths):
if not paths:
return
# convert data type
paths = [str(path, "mbcs") if not isinstance(path, str) 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

View File

@ -6,6 +6,7 @@
from __future__ import unicode_literals
import os.path as op
from send2trash.compat import text_type
from send2trash.util import preprocess_paths
from platform import version
import pythoncom
@ -19,7 +20,7 @@ def send2trash(paths):
if not paths:
return
# convert data type
paths = [str(path, "mbcs") if not isinstance(path, str) 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

View File

@ -1,6 +1,6 @@
[metadata]
name = Send2Trash
version = 2.0.0-dev
version = 1.8.3
url = https://github.com/arsenetar/send2trash
project_urls =
Bug Reports = https://github.com/arsenetar/send2trash/issues
@ -18,19 +18,20 @@ classifiers =
Operating System :: MacOS :: MacOS X
Operating System :: Microsoft :: Windows
Operating System :: POSIX
Programming Language :: Python :: 2.7
Programming Language :: Python :: 3
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Programming Language :: Python :: 3.11
Programming Language :: Python :: 3.12
Programming Language :: Python :: 3.13
Topic :: Desktop Environment :: File Managers
[options]
packages = find:
tests_require = pytest
python_requires = !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*, !=3.6.*, !=3.7.*
python_requires = >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*, !=3.6.*
[options.packages.find]
include=

View File

@ -4,6 +4,7 @@ import codecs
import os
import sys
from os import path as op
from send2trash.compat import PY3
from send2trash import TrashPermissionError
try:
@ -88,7 +89,7 @@ def _filesys_enc():
@pytest.fixture
def gen_unicode_file():
name = "send2trash_tést1"
name = u"send2trash_tést1"
file = op.join(op.expanduser(b"~"), name.encode("utf-8"))
touch(file)
assert op.exists(file) is True
@ -116,7 +117,10 @@ def test_trash_unicode(gen_unicode_file):
class ExtVol:
def __init__(self, path):
self.trash_topdir = path
self.trash_topdir_b = os.fsencode(self.trash_topdir)
if PY3:
self.trash_topdir_b = os.fsencode(self.trash_topdir)
else:
self.trash_topdir_b = self.trash_topdir
def s_getdev(path):
from send2trash.plat_other import is_parent

View File

@ -1,5 +1,5 @@
[tox]
envlist = py{38,39,310,311,312,313}
envlist = py{27,34,35,36,37,38,39,310}
skip_missing_interpreters = True
isolated_build = True