Converted to py3k (haven't tried it on Windows yet, but it should compile and work...)

--HG--
branch : py3k
This commit is contained in:
Virgil Dupras 2010-07-07 16:12:13 +02:00
parent 88b90d859c
commit 2858b5b153
7 changed files with 52 additions and 26 deletions

View File

@ -34,12 +34,25 @@ static PyMethodDef TrashMethods[] = {
{NULL, NULL, 0, NULL}
};
PyMODINIT_FUNC
init_send2trash_osx(void)
static struct PyModuleDef TrashDef = {
PyModuleDef_HEAD_INIT,
"send2trash_osx",
NULL,
-1,
TrashMethods,
NULL,
NULL,
NULL,
NULL
};
PyObject *
PyInit_send2trash_osx(void)
{
PyObject *m = Py_InitModule("_send2trash_osx", TrashMethods);
PyObject *m = PyModule_Create(&TrashDef);
if (m == NULL) {
return;
return NULL;
}
return m;
}

View File

@ -58,11 +58,24 @@ static PyMethodDef TrashMethods[] = {
{NULL, NULL, 0, NULL}
};
PyMODINIT_FUNC
init_send2trash_win(void)
static struct PyModuleDef TrashDef = {
PyModuleDef_HEAD_INIT,
"send2trash_win",
NULL,
-1,
TrashMethods,
NULL,
NULL,
NULL,
NULL
};
PyObject *
PyInit_send2trash_win(void)
{
PyObject *m = Py_InitModule("_send2trash_win", TrashMethods);
PyObject *m = PyModule_Create(&TrashDef);
if (m == NULL) {
return;
return NULL;
}
return m;
}

View File

@ -7,8 +7,8 @@
import sys
if sys.platform == 'darwin':
from plat_osx import send2trash
from .plat_osx import send2trash
elif sys.platform == 'win32':
from plat_win import send2trash
from .plat_win import send2trash
else:
from plat_other import send2trash
from .plat_other import send2trash

View File

@ -4,9 +4,9 @@
# which should be included with this package. The terms are also available at
# http://www.hardcoded.net/licenses/bsd_license
import _send2trash_osx
import send2trash_osx
def send2trash(path):
if not isinstance(path, unicode):
path = unicode(path, 'utf-8')
_send2trash_osx.send(path)
if not isinstance(path, str):
path = str(path, 'utf-8')
send2trash_osx.send(path)

View File

@ -4,7 +4,7 @@
# which should be included with this package. The terms are also available at
# http://www.hardcoded.net/licenses/bsd_license
from __future__ import unicode_literals
import sys
import os
import os.path as op
@ -60,8 +60,8 @@ def move_without_conflict(src, dst):
os.rename(src, destpath)
def send2trash(path):
if not isinstance(path, unicode):
path = unicode(path, sys.getfilesystemencoding())
if not isinstance(path, str):
path = str(path, sys.getfilesystemencoding())
try:
move_without_conflict(path, TRASH_PATH)
except OSError:

View File

@ -5,11 +5,11 @@
# http://www.hardcoded.net/licenses/bsd_license
import os.path as op
import _send2trash_win
import send2trash_win
def send2trash(path):
if not isinstance(path, unicode):
path = unicode(path, 'mbcs')
if not isinstance(path, str):
path = str(path, 'mbcs')
if not op.isabs(path):
path = op.abspath(path)
_send2trash_win.send(path)
send2trash_win.send(path)

View File

@ -8,13 +8,13 @@ exts = []
if sys.platform == 'darwin':
exts.append(Extension(
'_send2trash_osx',
'send2trash_osx',
[op.join('modules', 'send2trash_osx.c')],
extra_link_args=['-framework', 'CoreServices'],
))
if sys.platform == 'win32':
exts.append(Extension(
'_send2trash_win',
'send2trash_win',
[op.join('modules', 'send2trash_win.c')],
extra_link_args = ['shell32.lib'],
))
@ -26,14 +26,14 @@ CLASSIFIERS = [
'Operating System :: MacOS :: MacOS X',
'Operating System :: Microsoft :: Windows',
'Operating System :: POSIX',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 3',
'Programming Language :: Objective C',
'Programming Language :: C',
'Topic :: Desktop Environment :: File Managers',
]
setup(
name='Send2Trash',
name='Send2Trash3k',
version='1.0.1',
author='Hardcoded Software',
author_email='hsoft@hardcoded.net',