[pywin32-checkins] /hgroot/pywin32/pywin32: 5 new changesets
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: <pyw...@li...> - 2015-08-24 09:05:56
|
changeset 055bbedd423c in /hgroot/pywin32/pywin32 details: http://pywin32.hg.sourceforge.net/hgweb/pywin32/pywin32/hgroot/pywin32/pywin32?cmd=changeset;node=055bbedd423c summary: py3 fixes for mapi.OpenStreamOnFile changeset f04eba3e2adb in /hgroot/pywin32/pywin32 details: http://pywin32.hg.sourceforge.net/hgweb/pywin32/pywin32/hgroot/pywin32/pywin32?cmd=changeset;node=f04eba3e2adb summary: Add mapi.HrGetOneProp and mapi.HrSetOneProp changeset 508bd990fe01 in /hgroot/pywin32/pywin32 details: http://pywin32.hg.sourceforge.net/hgweb/pywin32/pywin32/hgroot/pywin32/pywin32?cmd=changeset;node=508bd990fe01 summary: Add PyIMAPIFolder::DeleteFolder() changeset 79f05b2f4a2e in /hgroot/pywin32/pywin32 details: http://pywin32.hg.sourceforge.net/hgweb/pywin32/pywin32/hgroot/pywin32/pywin32?cmd=changeset;node=79f05b2f4a2e summary: Issue 148: add typemap for ULONG_PTR changeset 835a071ad7bf in /hgroot/pywin32/pywin32 details: http://pywin32.hg.sourceforge.net/hgweb/pywin32/pywin32/hgroot/pywin32/pywin32?cmd=changeset;node=835a071ad7bf summary: Issue 139 - reload comes from the imp module on py3k diffstat: SWIG/swig_lib/python/pywintypes.i | 43 +++++++++ com/win32com/client/gencache.py | 4 + com/win32comext/mapi/src/PyIMAPIFolder.i | 47 ++++++++++ com/win32comext/mapi/src/mapi.i | 138 +++++++++++++++++++++++++++++- win32/src/PyUnicode.cpp | 5 +- 5 files changed, 228 insertions(+), 9 deletions(-) diffs (truncated from 320 to 300 lines): diff -r 575a76a7789b -r 835a071ad7bf SWIG/swig_lib/python/pywintypes.i --- a/SWIG/swig_lib/python/pywintypes.i Wed May 20 17:31:53 2015 +1000 +++ b/SWIG/swig_lib/python/pywintypes.i Mon Aug 24 18:56:44 2015 +1000 @@ -480,6 +480,49 @@ } } +//-------------------------------------------------------------------------- +// +// ULONG_PTR +// +//-------------------------------------------------------------------------- +%typemap(python, in) ULONG_PTR +{ + if (!PyWinLong_AsULONG_PTR($source, &$target)) + return NULL; +} +%typemap(python, in) ULONG_PTR * (ULONG_PTR temp) +{ + $target = &temp; + if (!PyWinLong_AsULONG_PTR($source, $target)) + return NULL; +} +%typemap(python, ignore) ULONG_PTR *OUTPUT(ULONG_PTR temp) +{ + $target = &temp; +} +%typemap(python, out) ULONG_PTR +{ + $target = PyWinObject_FromULONG_PTR($source) +} +%typemap(python,argout) ULONG_PTR *OUTPUT { + PyObject *o; + o = PyWinObject_FromULONG_PTR(*$source); + if (!$target) { + $target = o; + } else if ($target == Py_None) { + Py_DECREF(Py_None); + $target = o; + } else { + if (!PyList_Check($target)) { + PyObject *o2 = $target; + $target = PyList_New(0); + PyList_Append($target,o2); + Py_XDECREF(o2); + } + PyList_Append($target,o); + Py_XDECREF(o); + } +} //--------------------------------------------------------------------------- // diff -r 575a76a7789b -r 835a071ad7bf com/win32com/client/gencache.py --- a/com/win32com/client/gencache.py Wed May 20 17:31:53 2015 +1000 +++ b/com/win32com/client/gencache.py Mon Aug 24 18:56:44 2015 +1000 @@ -27,6 +27,10 @@ import traceback import CLSIDToClass import operator +try: + from imp import reload # exported by the imp module in py3k. +except: + pass # a builtin on py2k. bForDemandDefault = 0 # Default value of bForDemand - toggle this to change the world - see also makepy.py diff -r 575a76a7789b -r 835a071ad7bf com/win32comext/mapi/src/PyIMAPIFolder.i --- a/com/win32comext/mapi/src/PyIMAPIFolder.i Wed May 20 17:31:53 2015 +1000 +++ b/com/win32comext/mapi/src/PyIMAPIFolder.i Mon Aug 24 18:56:44 2015 +1000 @@ -64,6 +64,53 @@ // @flag MESSAGE_DIALOG |Displays a progress indicator as the operation proceeds. // @flag MESSAGE_MOVE|The message or messages are to be moved rather than copied. If MESSAGE_MOVE is not set, the messages are copied. +// @pyswig |DeleteFolder|Deletes a subfolder. +%native(DeleteFolder) DeleteFolder; +%{ +PyObject *PyIMAPIFolder::DeleteFolder(PyObject *self, PyObject *args) +{ + HRESULT hRes; + PyObject *obEntryId, *obUIParam, *obProgress; + ULONG cbEID; + LPENTRYID eid; + ULONG_PTR ulUIParam; + LPMAPIPROGRESS lpProgress; + ULONG flags = 0; + + IMAPIFolder *_swig_self; + if ((_swig_self=GetI(self))==NULL) return NULL; + + if(!PyArg_ParseTuple(args,"OOO|l:DeleteFolder", + &obEntryId, // @pyparm string|entryId||The EntryID of the subfolder to delete. + &obUIParam, // @pyparm long|uiParam||Handle of the parent window of the progress indicator. + &obProgress, // @pyparm <o PyIMAPIProgress>|progress||A progress object, or None + &flags)) + return NULL; + if PyString_Check(obEntryId) { + eid = (LPENTRYID)PyString_AsString(obEntryId); + cbEID = PyString_Size(obEntryId); + } else { + PyErr_SetString(PyExc_TypeError, "EntryID must be a string"); + return NULL; + } + if (!PyWinLong_AsULONG_PTR(obUIParam, &ulUIParam)) + return NULL; + if (!PyCom_InterfaceFromPyInstanceOrObject(obProgress, IID_IMAPIProgress, (void **)&lpProgress, TRUE)) + return NULL; + + PY_INTERFACE_PRECALL; + hRes = (HRESULT)_swig_self->DeleteFolder(cbEID, eid, ulUIParam, lpProgress, flags); + PY_INTERFACE_POSTCALL; + + if (lpProgress) + lpProgress->Release(); + + if (FAILED(hRes)) + return OleSetOleError(hRes); + + return Py_BuildValue("i", hRes); +} +%} // @pyswig |DeleteMessages|Deletes the specified messages. HRESULT DeleteMessages( diff -r 575a76a7789b -r 835a071ad7bf com/win32comext/mapi/src/mapi.i --- a/com/win32comext/mapi/src/mapi.i Wed May 20 17:31:53 2015 +1000 +++ b/com/win32comext/mapi/src/mapi.i Mon Aug 24 18:56:44 2015 +1000 @@ -241,6 +241,13 @@ #define RTF_SYNC_BODY_CHANGED RTF_SYNC_BODY_CHANGED // The plain text version of the message has changed. #define RTF_SYNC_RTF_CHANGED RTF_SYNC_RTF_CHANGED // The RTF version of the message has changed. +#define DEL_FOLDERS DEL_FOLDERS // All subfolders of the subfolder pointed to by lpEntryID should be deleted. +#define DEL_MESSAGES DEL_MESSAGES // All messages in the subfolder pointed to by lpEntryID should be deleted. +#define FOLDER_DIALOG FOLDER_DIALOG // A progress indicator should be displayed while the operation proceeds. +#define MESSAGE_DIALOG MESSAGE_DIALOG // Displays a progress indicator as the operation proceeds. +#define SHOW_SOFT_DELETES ((ULONG) 0x00000002) // Shows items that are currently marked as soft deleted. +#define DELETE_HARD_DELETE ((ULONG) 0x00000010) // Permanently removes all messages, including soft-deleted ones. + #define MAPI_CREATE MAPI_CREATE // The object will be created if necessary. #define MAPI_E_CALL_FAILED MAPI_E_CALL_FAILED #define MAPI_E_NOT_ENOUGH_MEMORY MAPI_E_NOT_ENOUGH_MEMORY @@ -468,6 +475,9 @@ #define CCSF_EMBEDDED_MESSAGE CCSF_EMBEDDED_MESSAGE // sent/unsent information is persisted in X-Unsent #define CCSF_PRESERVE_SOURCE CCSF_PRESERVE_SOURCE // don't modify the source message +// StreamOnFile (SOF) +#define SOF_UNIQUEFILENAME SOF_UNIQUEFILENAME // A temporary file is to be created for the IStream object + // @object MAPIINIT_0|A MAPIINIT_0 is represented as a tuple of: // @tupleitem 0|int|version|This must be MAPI_INIT_VERSION. // @tupleitem 1|int|flags|MAPI initlization flags. @@ -795,32 +805,144 @@ %} %native(RTFStreamToHTML) MyRTFStreamToHTML; - +// @pyswig <o PyIStream>|OpenStreamOnFile|Allocates and initializes an OLE IStream object to access the contents of a file. +%native(OpenStreamOnFile) PyOpenStreamOnFile; %{ PyObject *PyOpenStreamOnFile(PyObject *self, PyObject *args) { HRESULT hRes; unsigned long flags = 0; IStream *pStream; - PyObject *obFilepath; + PyObject *obFileName; + char *filename = NULL; + PyObject *obPrefix = Py_None; + char *prefix = NULL; - if (!PyArg_ParseTuple(args, "O|l:OpenStreamOnFile", &obFilepath, &flags)) + if (!PyArg_ParseTuple(args, "O|lO:OpenStreamOnFile", + &obFileName, // @pyparm string|filename|| + &flags, // @pyparm int|flags|0| + &obPrefix)) // @pyparm string|prefix|None| return NULL; - TCHAR *filepath; - if (!PyWinObject_AsTCHAR(obFilepath, &filepath, FALSE)) - return NULL; + if (!PyWinObject_AsString(obFileName, &filename, TRUE)) + goto done; + + if (!PyWinObject_AsString(obPrefix, &prefix, TRUE)) + goto done; PY_INTERFACE_PRECALL; - hRes = OpenStreamOnFile(MAPIAllocateBuffer, MAPIFreeBuffer, flags, filepath, NULL, &pStream); + // mapiutil.h incorrectly declares OpenStreamOnFile taking type LPTSTR + hRes = OpenStreamOnFile(MAPIAllocateBuffer, MAPIFreeBuffer, flags, (LPTSTR)filename, (LPTSTR)prefix, &pStream); PY_INTERFACE_POSTCALL; + done: + PyWinObject_FreeString(filename); + PyWinObject_FreeString(prefix); + + if (PyErr_Occurred()) + return NULL; + if (FAILED(hRes)) return OleSetOleError(hRes); return PyCom_PyObjectFromIUnknown(pStream, IID_IStream, FALSE); } %} -%native(OpenStreamOnFile) PyOpenStreamOnFile; +// @pyswig item|HrGetOneProp|Retrieves the value of a single property from an IMAPIProp object. +%native(HrGetOneProp) PyHrGetOneProp; +%{ +PyObject *PyHrGetOneProp(PyObject *self, PyObject *args) +{ + HRESULT hRes; + PyObject *obProp; + ULONG propTag; + IMAPIProp *pProp = NULL; + PyObject *ret = NULL; + SPropValue *pPV = NULL; + + if (!PyArg_ParseTuple(args, "Ok:HrGetOneProp", + &obProp, // @pyparm <o PyIMAPIProp>|prop||Object to retrieve property value from. + &propTag))// @pyparm ULONG|propTag||The property tag to open. + return NULL; + + if (!PyCom_InterfaceFromPyObject(obProp, IID_IMAPIProp, (void **)&pProp, FALSE)) + goto done; + + PY_INTERFACE_PRECALL; + hRes = HrGetOneProp(pProp, propTag, &pPV); + PY_INTERFACE_POSTCALL; + if (FAILED(hRes)) + { + OleSetOleError(hRes); + goto done; + } + if ((ret = PyMAPIObject_FromSPropValue(pPV)) == NULL) + goto done; + + // PyMAPIObject_FromSPropValue does not raise an exception for types + // it cannot handle so that GetProps doesn't blow up. Since we are processing + // only a single item, we test for this condition, and raise an exception. + if (PyTuple_GET_ITEM(ret, 1) == Py_None && + PyLong_AsUnsignedLong(PyTuple_GET_ITEM(ret, 0)) != PT_NULL) + { + char buf[128]; + sprintf(buf, "Unsupported MAPI property type 0x%X", PROP_TYPE(pPV->ulPropTag)); + PyErr_SetString(PyExc_TypeError, buf); + Py_DECREF(ret); + ret = NULL; + } +done: + if (pProp) pProp->Release(); + MAPIFreeBuffer(pPV); + + return ret; +} +%} +// @pyswig item|HrSetOneProp|Sets the value of a single property on a IMAPIProp object. +%native(HrSetOneProp) PyHrSetOneProp; +%{ +PyObject *PyHrSetOneProp(PyObject *self, PyObject *args) +{ + HRESULT hRes; + PyObject *obProp; + PyObject *obPropValue; + ULONG propTag; + IMAPIProp *pProp = NULL; + PyObject *ret = NULL; + SPropValue *pPV = NULL; + + if (!PyArg_ParseTuple(args, "OO:HrSetOneProp", + &obProp, // @pyparm <o PyIMAPIProp>|prop||Object to set property value on. + &obPropValue))// @pyparm <o PySPropValue>|propValue||Property value to set. + return NULL; + + if (!PyCom_InterfaceFromPyObject(obProp, IID_IMAPIProp, (void **)&pProp, FALSE)) + goto done; + if (S_OK != (hRes=MAPIAllocateBuffer(sizeof(SPropValue), (void **)&pPV))) + { + OleSetOleError(hRes); + goto done; + } + if (!PyMAPIObject_AsSPropValue(obPropValue, pPV, pPV)) + goto done; + + PY_INTERFACE_PRECALL; + hRes = HrSetOneProp(pProp, pPV); + PY_INTERFACE_POSTCALL; + if (FAILED(hRes)) + { + OleSetOleError(hRes); + goto done; + } + Py_INCREF(Py_None); + ret = Py_None; +done: + if (pProp) pProp->Release(); + MAPIFreeBuffer(pPV); + |