1
0
mirror of https://github.com/arsenetar/send2trash.git synced 2026-01-25 16:11:39 +00:00

2 Commits
1.4.1 ... 1.4.2

Author SHA1 Message Date
Virgil Dupras
7d38de269a v1.4.2 2017-11-17 13:50:29 -05:00
5733670fc2 Workaround embedded null character (#18)
Workaround embedded null characters in strings.  This fixes 17.
2017-11-01 08:28:22 -04:00
3 changed files with 21 additions and 3 deletions

View File

@@ -1,6 +1,11 @@
Changes
=======
Version 1.4.2 -- 2017/11/17
---------------------------
* Fix incompatibility with Python 3.6 on Windows. (#18)
Version 1.4.1 -- 2017/08/07
---------------------------

View File

@@ -6,7 +6,8 @@
from __future__ import unicode_literals
from ctypes import windll, Structure, byref, c_uint
from ctypes import (windll, Structure, byref, c_uint,
create_unicode_buffer, sizeof, addressof)
from ctypes.wintypes import HWND, UINT, LPCWSTR, BOOL
import os.path as op
@@ -46,7 +47,19 @@ def send2trash(path):
fileop = SHFILEOPSTRUCTW()
fileop.hwnd = 0
fileop.wFunc = FO_DELETE
fileop.pFrom = LPCWSTR(path + '\0')
# FIX: https://github.com/hsoft/send2trash/issues/17
# Starting in python 3.6.3 it is no longer possible to use:
# LPCWSTR(path + '\0') directly as embedded null characters are no longer
# allowed in strings
# Workaround
# - create buffer of c_wchar[] (LPCWSTR is based on this type)
# - buffer is two c_wchar characters longer (double null terminator)
# - cast the address of the buffer to a LPCWSTR
# NOTE: based on how python allocates memory for these types they should
# always be zero, if this is ever not true we can go back to explicitly
# setting the last two characters to null using buffer[index] = '\0'.
buffer = create_unicode_buffer(path, len(path)+2)
fileop.pFrom = LPCWSTR(addressof(buffer))
fileop.pTo = None
fileop.fFlags = FOF_ALLOWUNDO | FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_SILENT
fileop.fAnyOperationsAborted = 0

View File

@@ -19,7 +19,7 @@ LONG_DESCRIPTION = open('README.rst', 'rt').read() + '\n\n' + open('CHANGES.rst'
setup(
name='Send2Trash',
version='1.4.1',
version='1.4.2',
author='Virgil Dupras',
author_email='hsoft@hardcoded.net',
packages=['send2trash'],