[pywin32-checkins] /hgroot/pywin32/pywin32: Allow PyIStorage to be iterated; Don't ...
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: <pyw...@li...> - 2012-08-20 03:27:08
|
changeset 757d893bb5c0 in /hgroot/pywin32/pywin32 details: http://pywin32.hg.sourceforge.net/hgweb/pywin32/pywin32/hgroot/pywin32/pywin32?cmd=changeset;node=757d893bb5c0 summary: Allow PyIStorage to be iterated; Don't use BSTR for WCHAR parameters diffstat: com/win32com/src/extensions/PyIEnumSTATSTG.cpp | 4 +- com/win32com/src/extensions/PyIStorage.cpp | 206 ++++++++++-------------- com/win32com/src/include/PyIStorage.h | 2 +- com/win32com/storagecon.py | 5 + 4 files changed, 93 insertions(+), 124 deletions(-) diffs (truncated from 445 to 300 lines): diff -r f48937c1d707 -r 757d893bb5c0 com/win32com/src/extensions/PyIEnumSTATSTG.cpp --- a/com/win32com/src/extensions/PyIEnumSTATSTG.cpp Sun Aug 19 12:55:25 2012 -0400 +++ b/com/win32com/src/extensions/PyIEnumSTATSTG.cpp Sun Aug 19 23:18:55 2012 -0400 @@ -27,7 +27,7 @@ return (IEnumSTATSTG *)PyIUnknown::GetI(self); } -// @pymethod object|PyIEnumSTATSTG|Next|Retrieves a specified number of items in the enumeration sequence. +// @pymethod (<o STATSTG>, ...)|PyIEnumSTATSTG|Next|Retrieves a specified number of items in the enumeration sequence. PyObject *PyIEnumSTATSTG::Next(PyObject *self, PyObject *args) { long celt = 1; @@ -139,7 +139,7 @@ return PyCom_PyObjectFromIUnknown(pClone, IID_IEnumSTATSTG, FALSE); } -// @object PyIEnumSTATSTG|A Python interface to IEnumVARIANT +// @object PyIEnumSTATSTG|An enumerator for elements contained in a <o PyIStorage> object static struct PyMethodDef PyIEnumSTATSTG_methods[] = { { "Next", PyIEnumSTATSTG::Next, 1 }, // @pymeth Next|Retrieves a specified number of items in the enumeration sequence. diff -r f48937c1d707 -r 757d893bb5c0 com/win32com/src/extensions/PyIStorage.cpp --- a/com/win32com/src/extensions/PyIStorage.cpp Sun Aug 19 12:55:25 2012 -0400 +++ b/com/win32com/src/extensions/PyIStorage.cpp Sun Aug 19 23:18:55 2012 -0400 @@ -33,8 +33,8 @@ IStorage *pIS = GetI(self); if ( pIS == NULL ) return NULL; - // @pyparm string|pwcsName||Name of the new stream - // @pyparm int|grfMode||Specifies the access mode to use when opening the newly created stream. + // @pyparm str|Name||Name of the new stream + // @pyparm int|Mode||Access mode, storagecon.STGM_* // @pyparm int|reserved1|0|Reserved - must be zero. // @pyparm int|reserved2|0|Reserved - must be zero. DWORD grfMode; @@ -44,13 +44,12 @@ if ( !PyArg_ParseTuple(args, "Oi|ii:CreateStream", &obName, &grfMode, &reserved1, &reserved2) ) return NULL; IStream *ppstm; - BOOL bPythonIsHappy = TRUE; - BSTR bstrName; - bPythonIsHappy = PyWinObject_AsBstr(obName, &bstrName); - if (!bPythonIsHappy) return NULL; + TmpWCHAR Name; + if (!PyWinObject_AsWCHAR(obName, &Name)) + return NULL; + PY_INTERFACE_PRECALL; - HRESULT hr = pIS->CreateStream( bstrName, grfMode, reserved1, reserved2, &ppstm ); - PyWinObject_FreeBstr(bstrName); + HRESULT hr = pIS->CreateStream(Name, grfMode, reserved1, reserved2, &ppstm ); PY_INTERFACE_POSTCALL; if ( FAILED(hr) ) return PyCom_BuildPyException(hr, pIS, IID_IStorage); @@ -64,9 +63,9 @@ IStorage *pIS = GetI(self); if ( pIS == NULL ) return NULL; - // @pyparm string|pwcsName||Description for pwcsName + // @pyparm str|Name||Name of stream to be opened // @pyparm object|reserved1||A reserved param. Always pass None. NULL is always passed to the COM function - // @pyparm int|grfMode||Specifies the access mode to be assigned to the open stream. See the STGM enumeration values for descriptions of the possible values. . Whatever other modes you may choose, you must at least specify STGM_SHARE_EXCLUSIVE when calling this method. + // @pyparm int|Mode||Access mode, storagecon.STGM_* // @pyparm int|reserved2|0|Reserved - must be zero. PyObject *obName; DWORD grfMode; @@ -78,19 +77,17 @@ PyErr_SetString(PyExc_TypeError, "The 'reserved' parameter (param 2) must be None"); return NULL; } - IStream *ppstm; - BOOL bPythonIsHappy = TRUE; - BSTR name; - bPythonIsHappy = PyWinObject_AsBstr(obName, &name); - if (!bPythonIsHappy) return NULL; + IStream *pstm; + TmpWCHAR name; + if (!PyWinObject_AsWCHAR(obName, &name)) + return NULL; + PY_INTERFACE_PRECALL; - HRESULT hr = pIS->OpenStream( name, NULL, grfMode, reserved2, &ppstm ); - PyWinObject_FreeBstr(name); + HRESULT hr = pIS->OpenStream( name, NULL, grfMode, reserved2, &pstm ); PY_INTERFACE_POSTCALL; if ( FAILED(hr) ) return PyCom_BuildPyException(hr, pIS, IID_IStorage); - - return PyCom_PyObjectFromIUnknown(ppstm, IID_IStream, FALSE); + return PyCom_PyObjectFromIUnknown(pstm, IID_IStream, FALSE); } // @pymethod <o PyIStorage>|PyIStorage|CreateStorage|Creates and opens a new storage object nested within this storage object. @@ -99,9 +96,9 @@ IStorage *pIS = GetI(self); if ( pIS == NULL ) return NULL; - // @pyparm string|pwcsName||The name of the newly created stream. - // @pyparm int|grfMode||Specifies the access mode to use when opening the newly created storage object. - // @pyparm int|dwStgFmt||Documented as "reserved"! + // @pyparm str|Name||The name of the newly created stream. + // @pyparm int|Mode||Access mode - combination of storagecon.STGM_* flags + // @pyparm int|StgFmt||Documented as "reserved"! // @pyparm int|reserved2|0|Description for reserved2 PyObject *obName; DWORD grfMode; @@ -109,19 +106,17 @@ DWORD reserved2 = 0; if ( !PyArg_ParseTuple(args, "Oii|i:CreateStorage", &obName, &grfMode, &dwStgFmt, &reserved2) ) return NULL; - IStorage *ppstg; - BOOL bPythonIsHappy = TRUE; - BSTR name; - bPythonIsHappy = PyWinObject_AsBstr(obName, &name); - if (!bPythonIsHappy) return NULL; + IStorage *pstg; + TmpWCHAR name; + if (!PyWinObject_AsWCHAR(obName, &name)) + return NULL; + PY_INTERFACE_PRECALL; - HRESULT hr = pIS->CreateStorage( name, grfMode, dwStgFmt, reserved2, &ppstg ); + HRESULT hr = pIS->CreateStorage( name, grfMode, dwStgFmt, reserved2, &pstg ); PY_INTERFACE_POSTCALL; - PyWinObject_FreeBstr(name); if ( FAILED(hr) ) return PyCom_BuildPyException(hr, pIS, IID_IStorage); - - return PyCom_PyObjectFromIUnknown(ppstg, IID_IStorage, FALSE); + return PyCom_PyObjectFromIUnknown(pstg, IID_IStorage, FALSE); } // @pymethod <o PyIStorage>|PyIStorage|OpenStorage|Opens an existing storage object with the specified name in the specified access mode. @@ -130,12 +125,12 @@ IStorage *pIS = GetI(self); if ( pIS == NULL ) return NULL; - // @pyparm string|pwcsName||Name of the storage, or None. - // @pyparm <o PyIStorage>|pstgPriority||If the pstgPriority parameter is not None, it is a <o PyIStorage> object to a previous opening of an element of the storage object, + // @pyparm str|Name||Name of the storage, or None. + // @pyparm <o PyIStorage>|Priority||If the pstgPriority parameter is not None, it is a <o PyIStorage> object to a previous opening of an element of the storage object, // usually one that was opened in priority mode. The storage object should be closed and re-opened // according to grfMode. When the <om PyIStorage.OpenStorage> method returns, pstgPriority is no longer valid - use the result value. // If the pstgPriority parameter is None, it is ignored. - // @pyparm int|grfMode||Specifies the access mode to use when opening the storage object. See the STGM enumeration values for descriptions of the possible values. Whatever other modes you may choose, you must at least specify STGM_SHARE_EXCLUSIVE when calling this method. + // @pyparm int|Mode||Access mode - combination of storagecon.STGM_* flags (must include STGM_SHARE_EXCLUSIVE) // @pyparm <o SNB>|snbExclude||Reserved for later - Must be None // @pyparm int|reserved|0|Reserved integer param. PyObject *obName; @@ -146,23 +141,22 @@ if ( !PyArg_ParseTuple(args, "OOi|zi:OpenStorage", &obName, &obpstgPriority, &grfMode, &temp, &reserved) ) return NULL; IStorage *pstgPriority; - IStorage *ppstg; - BOOL bPythonIsHappy = TRUE; - BSTR bstrName; - bPythonIsHappy = PyWinObject_AsBstr(obName, &bstrName, TRUE); + IStorage *pstg; + TmpWCHAR Name; + if (!PyWinObject_AsWCHAR(obName, &Name, TRUE)) + return NULL; if (!PyCom_InterfaceFromPyObject(obpstgPriority, IID_IStorage, (void **)&pstgPriority, TRUE /* bNoneOK */)) - bPythonIsHappy = FALSE; - if (!bPythonIsHappy) return NULL; + return NULL; + PY_INTERFACE_PRECALL; - HRESULT hr = pIS->OpenStorage( bstrName, pstgPriority, grfMode, NULL, reserved, &ppstg ); + HRESULT hr = pIS->OpenStorage(Name, pstgPriority, grfMode, NULL, reserved, &pstg ); if ( pstgPriority != NULL ) pstgPriority->Release(); - PyWinObject_FreeBstr(bstrName); PY_INTERFACE_POSTCALL; if ( FAILED(hr) ) return PyCom_BuildPyException(hr, pIS, IID_IStorage); - return PyCom_PyObjectFromIUnknown(ppstg, IID_IStorage, FALSE); + return PyCom_PyObjectFromIUnknown(pstg, IID_IStorage, FALSE); } // @pymethod |PyIStorage|CopyTo|Copies the entire contents of an open storage object to another storage object. @@ -171,56 +165,35 @@ IStorage *pIS = GetI(self); if ( pIS == NULL ) return NULL; - // @pyparm [<o PyIID>,]|rgiidExclude||List of IID's to be excluded. + // @pyparm [<o PyIID>,]|rgiidExclude||List of IID's to be excluded. Use empty seq to exclude all objects, or None to indicate no excludes. // @pyparm <o SNB>|snbExclude||Reserved for later - Must be None // @pyparm <o PyIStorage>|stgDest||The open storage object into which this storage object is to be copied. // The destination storage object can be a different implementation of the <o PyIStorage> interface from the source storage object. // Thus, <om IStorage::CopyTo> can only use publicly available methods of the destination storage object. // If stgDest is open in transacted mode, it can be reverted by calling its <om PyIStorage::Revert> method. - DWORD ciidExclude = 0; PyObject *obSeqExclude; PyObject *obpstgDest; char *temp; if ( !PyArg_ParseTuple(args, "OzO:CopyTo", &obSeqExclude, &temp, &obpstgDest) ) return NULL; - IID *pExclude; - if (obSeqExclude==Py_None) - pExclude = NULL; - else { - if (!PySequence_Check(obSeqExclude)) { - PyErr_SetString(PyExc_TypeError, "Argument 1 must be a sequence of IID's, or None"); + DWORD ciidExclude = 0; + IID *pExclude = NULL; + if (obSeqExclude != Py_None) + if (!SeqToVector(obSeqExclude, &pExclude, &ciidExclude, PyWinObject_AsIID)) return NULL; - } - ciidExclude = PySequence_Length(obSeqExclude); - pExclude = new IID[ciidExclude]; - if (pExclude==NULL) { - PyErr_SetString(PyExc_MemoryError, "Allocating array of IID's"); - return NULL; - } - for (DWORD i=0;i<ciidExclude;i++) { - PyObject *ob = PySequence_GetItem(obSeqExclude, (int)i); - BOOL ok = PyWinObject_AsIID(ob, pExclude+i); - Py_XDECREF(ob); - if (!ok) { - delete [] pExclude; - return NULL; - } - } + IStorage *pstgDest; + if (!PyCom_InterfaceFromPyObject(obpstgDest, IID_IStorage, (void **)&pstgDest, FALSE /* bNoneOK */)){ + if (pExclude) + CoTaskMemFree(pExclude); + return NULL; } - IStorage *pstgDest; - BOOL bPythonIsHappy = TRUE; - if (!PyCom_InterfaceFromPyObject(obpstgDest, IID_IStorage, (void **)&pstgDest, FALSE /* bNoneOK */)) - bPythonIsHappy = FALSE; - if (!bPythonIsHappy) { - return NULL; - delete [] pExclude; - } + PY_INTERFACE_PRECALL; HRESULT hr = pIS->CopyTo( ciidExclude, pExclude, NULL, pstgDest ); - delete [] pExclude; pstgDest->Release(); PY_INTERFACE_POSTCALL; - + if (pExclude) + CoTaskMemFree(pExclude); if ( FAILED(hr) ) return PyCom_BuildPyException(hr, pIS, IID_IStorage); Py_INCREF(Py_None); @@ -233,35 +206,32 @@ IStorage *pIS = GetI(self); if ( pIS == NULL ) return NULL; - // @pyparm string|name||A string that contains the name of the element in this storage object to be moved or copied. + // @pyparm str|Name||A string that contains the name of the element in this storage object to be moved or copied. // @pyparm <o PyIStorage>|stgDest||<o PyIStorage> for the destination storage object. - // @pyparm string|newName||A string that contains the new name for the element in its new storage object. - // @pyparm int|grfFlags||Specifies whether the operation should be a move (STGMOVE_MOVE) or a copy (STGMOVE_COPY). See the STGMOVE enumeration. + // @pyparm str|NewName||A string that contains the new name for the element in its new storage object. + // @pyparm int|Flags||Specifies whether to move or copy (storagecon.STGMOVE_MOVE or STGMOVE_COPY) PyObject *obName, *obNewName; PyObject *obpstgDest; DWORD grfFlags; if ( !PyArg_ParseTuple(args, "OOOi:MoveElementTo", &obName, &obpstgDest, &obNewName, &grfFlags) ) return NULL; IStorage *pstgDest; - BOOL bPythonIsHappy = TRUE; - BSTR bstrName, bstrNewName; - bPythonIsHappy = PyWinObject_AsBstr(obName, &bstrName); - if (!PyWinObject_AsBstr(obNewName, &bstrNewName)) - bPythonIsHappy = FALSE; + TmpWCHAR Name, NewName; + if (!PyWinObject_AsWCHAR(obName, &Name)) + return NULL; + if (!PyWinObject_AsWCHAR(obNewName, &NewName)) + return NULL; if (!PyCom_InterfaceFromPyObject(obpstgDest, IID_IStorage, (void **)&pstgDest, FALSE /* bNoneOK */)) - bPythonIsHappy = FALSE; - if (!bPythonIsHappy) return NULL; + return NULL; PY_INTERFACE_PRECALL; - HRESULT hr = pIS->MoveElementTo( bstrName, pstgDest, bstrNewName, grfFlags ); + HRESULT hr = pIS->MoveElementTo(Name, pstgDest, NewName, grfFlags ); pstgDest->Release(); PY_INTERFACE_POSTCALL; - PyWinObject_FreeBstr(bstrName); - PyWinObject_FreeBstr(bstrNewName); + if ( FAILED(hr) ) return PyCom_BuildPyException(hr, pIS, IID_IStorage); Py_INCREF(Py_None); return Py_None; - } // @pymethod |PyIStorage|Commit|Ensures that any changes made to a storage object open in transacted mode are reflected in the parent storage; @@ -338,19 +308,16 @@ PyObject *obName; |