ThirdParty/Send2Trash/send2trash/plat_other.py

changeset 6228
9c3fbf39ec9b
parent 5994
cf0b37d2a28d
equal deleted inserted replaced
6227:fc0869cd16dc 6228:9c3fbf39ec9b
14 # For external volumes this implementation will raise an exception if it can't 14 # For external volumes this implementation will raise an exception if it can't
15 # find or create the user's trash directory. 15 # find or create the user's trash directory.
16 16
17 from __future__ import unicode_literals 17 from __future__ import unicode_literals
18 18
19 import errno
19 import sys 20 import sys
20 import os 21 import os
21 import os.path as op 22 import os.path as op
22 from datetime import datetime 23 from datetime import datetime
23 import stat 24 import stat
26 except ImportError: 27 except ImportError:
27 # Python 2 28 # Python 2
28 from urllib import quote 29 from urllib import quote
29 30
30 from .compat import text_type, environb 31 from .compat import text_type, environb
32 from .exceptions import TrashPermissionError
31 33
32 try: 34 try:
33 fsencode = os.fsencode # Python 3 35 fsencode = os.fsencode # Python 3
34 fsdecode = os.fsdecode 36 fsdecode = os.fsdecode
35 except AttributeError: 37 except AttributeError:
132 return trash_dir 134 return trash_dir
133 135
134 def find_ext_volume_fallback_trash(volume_root): 136 def find_ext_volume_fallback_trash(volume_root):
135 # from [2] Trash directories (1) create a .Trash-$uid dir. 137 # from [2] Trash directories (1) create a .Trash-$uid dir.
136 trash_dir = op.join(volume_root, TOPDIR_FALLBACK) 138 trash_dir = op.join(volume_root, TOPDIR_FALLBACK)
137 # Try to make the directory, if we can't the OSError exception will escape 139 # Try to make the directory, if we lack permission, raise TrashPermissionError
138 # be thrown out of send2trash. 140 try:
139 check_create(trash_dir) 141 check_create(trash_dir)
142 except OSError as e:
143 if e.errno == errno.EACCES:
144 raise TrashPermissionError(e.filename)
145 raise
140 return trash_dir 146 return trash_dir
141 147
142 def find_ext_volume_trash(volume_root): 148 def find_ext_volume_trash(volume_root):
143 trash_dir = find_ext_volume_global_trash(volume_root) 149 trash_dir = find_ext_volume_global_trash(volume_root)
144 if trash_dir is None: 150 if trash_dir is None:

eric ide

mercurial