[pywin32-checkins] /hgroot/pywin32/pywin32: 2 new changesets
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: <pyw...@li...> - 2016-04-16 04:10:04
|
changeset 9559d74774bc in /hgroot/pywin32/pywin32 details: http://pywin32.hg.sourceforge.net/hgweb/pywin32/pywin32/hgroot/pywin32/pywin32?cmd=changeset;node=9559d74774bc summary: Add pythoncom.StgOpenStorageOnILockBytes (Nick Czeczulin via patch #135) changeset 7a9466f06a9b in /hgroot/pywin32/pywin32 details: http://pywin32.hg.sourceforge.net/hgweb/pywin32/pywin32/hgroot/pywin32/pywin32?cmd=changeset;node=7a9466f06a9b summary: Allow win32com.client.CastTo() to have a typelib specified (Pieter Aarnoutse via patch #136) diffstat: CHANGES.txt | 5 +++++ com/win32com/client/__init__.py | 20 ++++++++++++++------ com/win32com/src/PyStorage.cpp | 35 +++++++++++++++++++++++++++++++++++ com/win32com/src/PythonCOM.cpp | 2 ++ 4 files changed, 56 insertions(+), 6 deletions(-) diffs (118 lines): diff -r fac37b1e89a7 -r 7a9466f06a9b CHANGES.txt --- a/CHANGES.txt Sat Apr 16 13:53:01 2016 +1000 +++ b/CHANGES.txt Sat Apr 16 14:09:27 2016 +1000 @@ -6,6 +6,11 @@ Since build 220: ---------------- +* Allow win32com.client.CastTo() to have a typelib specified, which will be + used to locate the object definition (Pieter Aarnoutse via patch #136) + +* Add pythoncom.StgOpenStorageOnILockBytes (Nick Czeczulin via patch #135) + * IDispatch failures will try and get error information via IErrorInfo (Stefan Schukat via patch #130) diff -r fac37b1e89a7 -r 7a9466f06a9b com/win32com/client/__init__.py --- a/com/win32com/client/__init__.py Sat Apr 16 13:53:01 2016 +1000 +++ b/com/win32com/client/__init__.py Sat Apr 16 14:09:27 2016 +1000 @@ -124,10 +124,17 @@ assert UnicodeToString is None, "this is deprecated and will go away" return Dispatch(ob, userName, returnCLSID,None) -def CastTo(ob, target): +def CastTo(ob, target, typelib = None): """'Cast' a COM object to another interface""" # todo - should support target being an IID - if hasattr(target, "index"): # string like + mod = None + if typelib is not None: # caller specified target typelib (TypelibSpec). See e.g. selecttlb.EnumTlbs(). + mod = gencache.MakeModuleForTypelib(typelib.clsid, typelib.lcid, int(typelib.major, 16), int(typelib.minor, 16)) + if not hasattr(mod, target): + raise ValueError("The interface name '%s' does not appear in the " \ + "specified library %r" % (target, typelib.ver_desc)) + + elif hasattr(target, "index"): # string like # for now, we assume makepy for this to work. if "CLSID" not in ob.__class__.__dict__: # Eeek - no makepy support - try and build it. @@ -152,10 +159,11 @@ raise ValueError("The interface name '%s' does not appear in the " \ "same library as object '%r'" % (target, ob)) mod = gencache.GetModuleForCLSID(target_clsid) - target_class = getattr(mod, target) - # resolve coclass to interface - target_class = getattr(target_class, "default_interface", target_class) - return target_class(ob) # auto QI magic happens + if mod is not None: + target_class = getattr(mod, target) + # resolve coclass to interface + target_class = getattr(target_class, "default_interface", target_class) + return target_class(ob) # auto QI magic happens raise ValueError class Constants: diff -r fac37b1e89a7 -r 7a9466f06a9b com/win32com/src/PyStorage.cpp --- a/com/win32com/src/PyStorage.cpp Sat Apr 16 13:53:01 2016 +1000 +++ b/com/win32com/src/PyStorage.cpp Sat Apr 16 14:09:27 2016 +1000 @@ -190,6 +190,41 @@ return PyCom_PyObjectFromIUnknown(pResult, IID_IStorage, FALSE); } +// @pymethod <o PyIStorage>|pythoncom|StgOpenStorageOnILockBytes|Open an existing storage object that does not reside in a disk file, but instead has an underlying <PyILockBytes> byte array provided by the caller. +PyObject *pythoncom_StgOpenStorageOnILockBytes(PyObject *self, PyObject *args) +{ + PyObject *obLockBytes; + PyObject *obStgPriority = NULL; + DWORD mode; + PyObject *obSnbExclude = NULL; + DWORD reserved = 0; + IStorage *pResult; + + if (!PyArg_ParseTuple(args, "OOk|Ok:StgOpenStorageOnILockBytes", + &obLockBytes, // @pyparm <o PyILockBytes>|lockBytes||The <o PyILockBytes> interface on the underlying byte array object on which to open an existing storage object. + &obStgPriority, // @pyparm <o PyIStorage>|stgPriority||Usually None, or another parent storage. + &mode, + &obSnbExclude, // @pyparm object|snbExclude|None|Not yet supported - must be None + &reserved)) // @pyparm int|reserved|0|A reserved value + return NULL; + ILockBytes *plb; + if (!PyCom_InterfaceFromPyObject(obLockBytes, IID_ILockBytes, (void **)&plb, FALSE)) + return NULL; + IStorage *pStgPriority; + if (!PyCom_InterfaceFromPyObject(obStgPriority, IID_IStorage, (void **)&pStgPriority, TRUE)) + { + plb->Release(); + return NULL; + } + PY_INTERFACE_PRECALL; + HRESULT hr = StgOpenStorageOnILockBytes(plb, pStgPriority, mode, NULL, reserved, &pResult); + plb->Release(); + if (pStgPriority) pStgPriority->Release(); + PY_INTERFACE_POSTCALL; + if (FAILED(hr)) return PyCom_BuildPyException(hr); + return PyCom_PyObjectFromIUnknown(pResult, IID_IStorage, FALSE); +} + #ifndef MS_WINCE // @pymethod int|pythoncom|StgIsStorageFile|Indicates whether a particular disk file contains a storage object. PyObject *pythoncom_StgIsStorageFile(PyObject *self, PyObject *args) diff -r fac37b1e89a7 -r 7a9466f06a9b com/win32com/src/PythonCOM.cpp --- a/com/win32com/src/PythonCOM.cpp Sat Apr 16 13:53:01 2016 +1000 +++ b/com/win32com/src/PythonCOM.cpp Sat Apr 16 14:09:27 2016 +1000 @@ -50,6 +50,7 @@ #endif // MS_WINCE extern PyObject *pythoncom_StgCreateDocfile(PyObject *self, PyObject *args); extern PyObject *pythoncom_StgCreateDocfileOnILockBytes(PyObject *self, PyObject *args); +extern PyObject *pythoncom_StgOpenStorageOnILockBytes(PyObject *self, PyObject *args); extern PyObject *pythoncom_WriteClassStg(PyObject *self, PyObject *args); extern PyObject *pythoncom_ReadClassStg(PyObject *self, PyObject *args); extern PyObject *pythoncom_WriteClassStm(PyObject *self, PyObject *args); @@ -2063,6 +2064,7 @@ #endif // MS_WINCE { "StgCreateDocfile", pythoncom_StgCreateDocfile, 1 }, // @pymeth StgCreateDocfile|Creates a new compound file storage object using the OLE-provided compound file implementation for the <o PyIStorage> interface. { "StgCreateDocfileOnILockBytes", pythoncom_StgCreateDocfileOnILockBytes, 1 }, // @pymeth StgCreateDocfileOnILockBytes|Creates a new compound file storage object using the OLE-provided compound file implementation for the <o PyIStorage> interface. + { "StgOpenStorageOnILockBytes", pythoncom_StgOpenStorageOnILockBytes, 1 }, // @pymeth StgOpenStorageOnILockBytes|Open an existing storage object that does not reside in a disk file, but instead has an underlying <PyILockBytes> byte array provided by the caller. #ifndef MS_WINCE { "StgIsStorageFile", pythoncom_StgIsStorageFile, 1 }, // @pymeth StgIsStorageFile|Indicates whether a particular disk file contains a storage object. #endif // MS_WINCE |