pywin32-checkins Mailing List for Python for Windows Extensions (Page 112)
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
You can subscribe to this list here.
2003 |
Jan
|
Feb
|
Mar
|
Apr
(2) |
May
(1) |
Jun
(6) |
Jul
(50) |
Aug
(11) |
Sep
(24) |
Oct
(184) |
Nov
(118) |
Dec
(22) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2004 |
Jan
(31) |
Feb
(25) |
Mar
(34) |
Apr
(105) |
May
(49) |
Jun
(38) |
Jul
(39) |
Aug
(7) |
Sep
(98) |
Oct
(79) |
Nov
(20) |
Dec
(17) |
2005 |
Jan
(66) |
Feb
(32) |
Mar
(43) |
Apr
(30) |
May
(58) |
Jun
(30) |
Jul
(16) |
Aug
(4) |
Sep
(21) |
Oct
(42) |
Nov
(11) |
Dec
(14) |
2006 |
Jan
(42) |
Feb
(30) |
Mar
(22) |
Apr
(1) |
May
(9) |
Jun
(15) |
Jul
(20) |
Aug
(9) |
Sep
(8) |
Oct
(1) |
Nov
(9) |
Dec
(43) |
2007 |
Jan
(52) |
Feb
(45) |
Mar
(20) |
Apr
(12) |
May
(59) |
Jun
(39) |
Jul
(35) |
Aug
(31) |
Sep
(17) |
Oct
(20) |
Nov
(4) |
Dec
(4) |
2008 |
Jan
(28) |
Feb
(111) |
Mar
(4) |
Apr
(27) |
May
(40) |
Jun
(27) |
Jul
(32) |
Aug
(94) |
Sep
(87) |
Oct
(153) |
Nov
(336) |
Dec
(331) |
2009 |
Jan
(298) |
Feb
(127) |
Mar
(20) |
Apr
(8) |
May
|
Jun
(10) |
Jul
(6) |
Aug
|
Sep
(2) |
Oct
(2) |
Nov
|
Dec
(1) |
2010 |
Jan
(7) |
Feb
(1) |
Mar
|
Apr
|
May
(15) |
Jun
(4) |
Jul
(3) |
Aug
(28) |
Sep
(1) |
Oct
(19) |
Nov
(16) |
Dec
(6) |
2011 |
Jan
(2) |
Feb
(18) |
Mar
(17) |
Apr
(12) |
May
(5) |
Jun
(11) |
Jul
(7) |
Aug
(2) |
Sep
(2) |
Oct
(4) |
Nov
(4) |
Dec
|
2012 |
Jan
(6) |
Feb
(2) |
Mar
|
Apr
(8) |
May
(4) |
Jun
(3) |
Jul
(13) |
Aug
(27) |
Sep
(8) |
Oct
(9) |
Nov
(3) |
Dec
(2) |
2013 |
Jan
|
Feb
(1) |
Mar
(5) |
Apr
(10) |
May
|
Jun
(2) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(1) |
Dec
(9) |
2014 |
Jan
(2) |
Feb
(4) |
Mar
(4) |
Apr
(1) |
May
(4) |
Jun
(2) |
Jul
|
Aug
|
Sep
|
Oct
(2) |
Nov
|
Dec
(1) |
2015 |
Jan
(1) |
Feb
|
Mar
|
Apr
(6) |
May
(2) |
Jun
|
Jul
|
Aug
(1) |
Sep
|
Oct
|
Nov
|
Dec
|
2016 |
Jan
(3) |
Feb
(2) |
Mar
|
Apr
(3) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2017 |
Jan
|
Feb
|
Mar
(1) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(1) |
Oct
|
Nov
|
Dec
|
From: Mark H. <mha...@us...> - 2005-05-31 12:36:21
|
Update of /cvsroot/pywin32/pywin32/com/win32com In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24405 Modified Files: readme.htm Added Files: decimal_23.py Log Message: With help from Roger Upole: * Add PyObject_AsCurrency and PyObject_FromCurrency to convert CY/CURRENCY structs to/from Python objects. * Invent a pythoncom.__future_currency__ scheme, allowing us to move from the current brain-dead (hiword, loword) currency support into a decimal.Decimal() object. See win32com\readme.html for more details. --- NEW FILE: decimal_23.py --- # <win32com> # This is a clone of Python 2.4's 'decimal' module. It will only be used when # 'import decimal' fails - so is likely to be used in Python 2.3. # </win32com> # Copyright (c) 2004 Python Software Foundation. # All rights reserved. # Written by Eric Price <eprice at tjhsst.edu> # and Facundo Batista <facundo at taniquetil.com.ar> # and Raymond Hettinger <python at rcn.com> # and Aahz <aahz at pobox.com> # and Tim Peters # This module is currently Py2.3 compatible and should be kept that way # unless a major compelling advantage arises. IOW, 2.3 compatibility is # strongly preferred, but not guaranteed. # Also, this module should be kept in sync with the latest updates of # the IBM specification as it evolves. Those updates will be treated [...3008 lines suppressed...] mantissa = intpart + fracpart tmp = map(int, mantissa) backup = tmp while tmp and tmp[0] == 0: del tmp[0] # It's a zero if not tmp: if backup: return (sign, tuple(backup), exp) return (sign, (0,), exp) mantissa = tuple(tmp) return (sign, mantissa, exp) if __name__ == '__main__': import doctest, sys doctest.testmod(sys.modules[__name__]) Index: readme.htm =================================================================== RCS file: /cvsroot/pywin32/pywin32/com/win32com/readme.htm,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** readme.htm 11 Apr 2004 04:41:21 -0000 1.14 --- readme.htm 31 May 2005 12:36:02 -0000 1.15 *************** *** 18,22 **** scripts (and a new <a href="test/readme.txt">readme.txt</a>). Although these are used for testing, they do show a variety of COM techniques.</p> ! <h3>Recent Changes</h3> <h4>win32com.shell</h4> --- 18,57 ---- scripts (and a new <a href="test/readme.txt">readme.txt</a>). Although these are used for testing, they do show a variety of COM techniques.</p> ! ! <a name="currency"><h3>Important Currency changes</h3></a> ! <p> ! In all builds prior to 204, a COM currency value was returned as a tuple of ! integers. Working with 2 integers to represent a currency object was a poor ! choice, but the alternative was never clear. Now Python ships with the ! <a href="http://www.python.org/dev/doc/devel/lib/module-decimal.html">decimal</a> ! module, the alternative has arrived! ! </p> ! <p> ! To ease the transition, from pywin32 build 205 a FutureWarning will be issued ! when your code fetches a COM currency object - but a tuple will still be ! returned. However, if your code sets <code>pythoncom.__future_currency__ = True</code>, ! a warning will not be issued, and a decimal module object will be returned. ! At some undetermined point in the future (but not before build 208) the ! new behaviour will be the default. ! </p> ! <p> ! When supplying a COM currency object, you can supply either a decimal object ! or a tuple. This issue only applies when pythoncom passes you a currency value ! </p> ! <p> ! Python 2.3 does not ship with a decimal module. For this reason, ! win32com/decimal_23.py is supplied with pywin32. This is a clone of the decimal ! module, but will only be used when <code>import decimal</code> fails. If you ! want to use this functionality in your Python 2.3 programs, you should write ! something similar to: ! <pre> ! try: ! import decimal ! except ImportError: ! import win32com.decimal_23 as decimal ! val = decimal.Decimal("123.45") ! </pre> ! </p> ! <h3>Recent Changes</h3> <h4>win32com.shell</h4> *************** *** 27,31 **** These shell interfaces are now generally stable. <h4>New win32com.taskscheduler module</h4> ! Roger Uploe has contribted an interface to the Windows task scheduler. This is actually very neat, and it allows Python to edit the task list as shown by Windows Control Panel. Property page suppport may even appear later, now that the win32 library has the new win32rcparser module. --- 62,66 ---- These shell interfaces are now generally stable. <h4>New win32com.taskscheduler module</h4> ! Roger Upole has contributed an interface to the Windows task scheduler. This is actually very neat, and it allows Python to edit the task list as shown by Windows Control Panel. Property page suppport may even appear later, now that the win32 library has the new win32rcparser module. |
From: Mark H. <mha...@us...> - 2005-05-31 12:36:21
|
Update of /cvsroot/pywin32/pywin32/com/win32com/servers In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24405/servers Modified Files: test_pycomtest.py Log Message: With help from Roger Upole: * Add PyObject_AsCurrency and PyObject_FromCurrency to convert CY/CURRENCY structs to/from Python objects. * Invent a pythoncom.__future_currency__ scheme, allowing us to move from the current brain-dead (hiword, loword) currency support into a decimal.Decimal() object. See win32com\readme.html for more details. Index: test_pycomtest.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/com/win32com/servers/test_pycomtest.py,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** test_pycomtest.py 19 Nov 2002 10:39:44 -0000 1.7 --- test_pycomtest.py 31 May 2005 12:36:02 -0000 1.8 *************** *** 11,14 **** --- 11,16 ---- from win32com.server.util import wrap + import pythoncom + pythoncom.__future_currency__ = True # We use the constants from the module, so must insist on a gencache. # Otherwise, use of gencache is not necessary (tho still advised) |
From: Mark H. <mha...@us...> - 2005-05-31 12:36:21
|
Update of /cvsroot/pywin32/pywin32/com/win32com/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24405/test Modified Files: testPyComTest.py Log Message: With help from Roger Upole: * Add PyObject_AsCurrency and PyObject_FromCurrency to convert CY/CURRENCY structs to/from Python objects. * Invent a pythoncom.__future_currency__ scheme, allowing us to move from the current brain-dead (hiword, loword) currency support into a decimal.Decimal() object. See win32com\readme.html for more details. Index: testPyComTest.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/com/win32com/test/testPyComTest.py,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** testPyComTest.py 4 May 2004 07:01:13 -0000 1.19 --- testPyComTest.py 31 May 2005 12:36:03 -0000 1.20 *************** *** 113,116 **** --- 113,127 ---- if o.LongProp != 3 or o.IntProp != 3: raise error, "Property value wrong - got %d/%d" % (o.LongProp,o.IntProp) + # currency. + pythoncom.__future_currency__ = 1 + if o.CurrencyProp != 0: + raise error, "Expecting 0, got %r" % (o.CurrencyProp,) + try: + import decimal + except ImportError: + import win32com.decimal_23 as decimal + o.CurrencyProp = decimal.Decimal("1234.5678") + if o.CurrencyProp != decimal.Decimal("1234.5678"): + raise error, "got %r" % (o.CurrencyProp,) def TestGenerated(): *************** *** 208,211 **** --- 219,235 ---- raise error, "Property value wrong - got %d/%d" % (o.LongProp,o.IntProp) + # currency. + pythoncom.__future_currency__ = 1 + if o.CurrencyProp != 0: + raise error, "Expecting 0, got %r" % (o.CurrencyProp,) + try: + import decimal + except ImportError: + import win32com.decimal_23 as decimal + for val in ("1234.5678", "1234.56", "1234"): + o.CurrencyProp = decimal.Decimal(val) + if o.CurrencyProp != decimal.Decimal(val): + raise error, "%s got %r" % (val, o.CurrencyProp) + # Do the connection point thing... # Create a connection object. |
From: Mark H. <mha...@us...> - 2005-05-31 12:36:19
|
Update of /cvsroot/pywin32/pywin32/com/win32com/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24405/src Modified Files: PyComHelpers.cpp PythonCOM.cpp oleargs.cpp univgw_dataconv.cpp Log Message: With help from Roger Upole: * Add PyObject_AsCurrency and PyObject_FromCurrency to convert CY/CURRENCY structs to/from Python objects. * Invent a pythoncom.__future_currency__ scheme, allowing us to move from the current brain-dead (hiword, loword) currency support into a decimal.Decimal() object. See win32com\readme.html for more details. Index: univgw_dataconv.cpp =================================================================== RCS file: /cvsroot/pywin32/pywin32/com/win32com/src/univgw_dataconv.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** univgw_dataconv.cpp 14 Dec 2004 10:19:35 -0000 1.7 --- univgw_dataconv.cpp 31 May 2005 12:36:02 -0000 1.8 *************** *** 536,543 **** { DATE *pdbl = *(DATE **)pbArg; - if ( !PyTime_Check(obOutValue) ) - { - goto Error; - } if ( !PyWinObject_AsDATE(obOutValue, pdbl) ) { --- 536,539 ---- *************** *** 549,564 **** { CY *pcy = *(CY **)pbArg; ! if (!PyTuple_Check(obOutValue) || PyTuple_Size(obOutValue) != 2 || ! !PyLong_Check(PyTuple_GET_ITEM(obOutValue, 0)) || ! !PyLong_Check(PyTuple_GET_ITEM(obOutValue, 1))) ! { ! PyErr_Format( ! PyExc_TypeError, ! "Return value[%d] is a VT_CY which requires a tuple " ! "containing two Python longs.", i); goto Error; - } - pcy->Hi = PyLong_AsLong(PyTuple_GET_ITEM(obOutValue, 0)); - pcy->Lo = PyLong_AsLong(PyTuple_GET_ITEM(obOutValue, 1)); break; } --- 545,550 ---- { CY *pcy = *(CY **)pbArg; ! if (!PyObject_AsCurrency(obOutValue, pcy)) goto Error; break; } Index: PythonCOM.cpp =================================================================== RCS file: /cvsroot/pywin32/pywin32/com/win32com/src/PythonCOM.cpp,v retrieving revision 1.35 retrieving revision 1.36 diff -C2 -d -r1.35 -r1.36 *** PythonCOM.cpp 24 May 2005 14:45:01 -0000 1.35 --- PythonCOM.cpp 31 May 2005 12:36:02 -0000 1.36 *************** *** 16,19 **** --- 16,22 ---- #include "PyFactory.h" + // keep a reference to pythoncom'm __dict__ so the COM currency format can be looked up dynamically + extern PyObject *pythoncom_dict=NULL; + extern int PyCom_RegisterCoreIIDs(PyObject *dict); *************** *** 1718,1721 **** --- 1721,1726 ---- PyObject *dict = PyModule_GetDict(oModule); if (!dict) return; /* Another serious error!*/ + pythoncom_dict=dict; + PyDict_SetItemString(dict, "TypeIIDs", g_obPyCom_MapIIDToType); PyDict_SetItemString(dict, "ServerInterfaces", g_obPyCom_MapGatewayIIDToName); *************** *** 2061,2065 **** AddConstant(dict, "dcom", 0 ); } ! PyObject *obfmtid=NULL; obfmtid=PyWinObject_FromIID(FMTID_DocSummaryInformation); --- 2066,2070 ---- AddConstant(dict, "dcom", 0 ); } ! AddConstant(dict, "__future_currency__", 0); PyObject *obfmtid=NULL; obfmtid=PyWinObject_FromIID(FMTID_DocSummaryInformation); Index: PyComHelpers.cpp =================================================================== RCS file: /cvsroot/pywin32/pywin32/com/win32com/src/PyComHelpers.cpp,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** PyComHelpers.cpp 26 Jan 2005 02:29:47 -0000 1.8 --- PyComHelpers.cpp 31 May 2005 12:36:02 -0000 1.9 *************** *** 11,14 **** --- 11,15 ---- extern PyObject *g_obPyCom_MapIIDToType; extern PyObject *g_obPyCom_MapServerIIDToGateway; + extern PyObject *pythoncom_dict; // String conversions *************** *** 66,69 **** --- 67,152 ---- } + // Currency conversions. + PyObject *PyObject_FromCurrency(CURRENCY &cy) + { + static BOOL decimal_imported=FALSE; + static PyObject *decimal_module=NULL; + static BOOL warned_future_currency=FALSE; + PyObject *result = NULL; + + // Use decimal module if available and __future_currency__ evaluates to True, otherwise use old behaviour + PyObject *__future_currency__; + BOOL use_decimal; + __future_currency__=PyDict_GetItemString(pythoncom_dict,"__future_currency__"); + if (__future_currency__==NULL){ // should not happen ! + PyErr_Print(); + use_decimal=FALSE; + } + else + use_decimal=PyObject_IsTrue(__future_currency__); + if (!use_decimal && !warned_future_currency) { + PyErr_Warn(PyExc_FutureWarning, + "Currency objects will soon be changed so a decimal.Decimal instance is used." + "\n (set pythoncom.__future_currency__ to get these objects now.)"); + warned_future_currency = TRUE; + } + + if (use_decimal && !decimal_imported){ + decimal_module=PyImport_ImportModule("decimal"); + if (!decimal_module) { + PyErr_Clear(); + decimal_module=PyImport_ImportModule("win32com.decimal_23"); + } + decimal_imported=TRUE; + if (decimal_module==NULL) + PyErr_Print(); + } + if (use_decimal && (decimal_module==NULL)){ + PyErr_Warn(NULL,"Can't find decimal module, reverting to using tuple for currency"); + use_decimal=FALSE; + } + if (!use_decimal) + result = Py_BuildValue("ll", cy.Hi, cy.Lo); + else { + PyObject *unscaled_result; + unscaled_result=PyObject_CallMethod(decimal_module, "Decimal", "L", cy.int64); + if (unscaled_result!=NULL){ + result=PyObject_CallMethod(unscaled_result, "__div__", "l", 10000); + Py_DECREF(unscaled_result); + } + } + return result; + } + + PYCOM_EXPORT BOOL PyObject_AsCurrency(PyObject *ob, CURRENCY *pcy) + { + if (!PyTuple_Check(ob) || PyTuple_Size(ob) != 2 || + !PyLong_Check(PyTuple_GET_ITEM(ob, 0)) || + !PyLong_Check(PyTuple_GET_ITEM(ob, 1))) + { + if (strcmp(ob->ob_type->tp_name, "Decimal")==0) { + PyObject *scaled = PyObject_CallMethod(ob, "__mul__", "l", 10000); + if (!scaled) return FALSE; + PyObject *longval = PyNumber_Long(scaled); + Py_DECREF(scaled); + pcy->int64 = PyLong_AsLongLong(longval); + Py_DECREF(longval); + if (pcy->int64 == -1 && PyErr_Occurred()) + return FALSE; + } else { + PyErr_Format( + PyExc_TypeError, + "Currency object must be either a tuple of 2 longs or a " + "Decimal instance (got %s).", + ob->ob_type->tp_name); + return FALSE; + } + } else { + pcy->Hi = PyLong_AsLong(PyTuple_GET_ITEM(ob, 0)); + pcy->Lo = PyLong_AsLong(PyTuple_GET_ITEM(ob, 1)); + } + return TRUE; + } + // If PyCom_PyObjectFromIUnknown is called with bAddRef==FALSE, the // caller is asking us to take ownership of the COM reference. If we Index: oleargs.cpp =================================================================== RCS file: /cvsroot/pywin32/pywin32/com/win32com/src/oleargs.cpp,v retrieving revision 1.28 retrieving revision 1.29 diff -C2 -d -r1.28 -r1.29 *** oleargs.cpp 13 Jul 2004 07:30:26 -0000 1.28 --- oleargs.cpp 31 May 2005 12:36:02 -0000 1.29 *************** *** 175,178 **** --- 175,184 ---- V_VT(var) = VT_RECORD; } + else if (strcmp(obj->ob_type->tp_name, "Decimal")==0) + { + if (!PyObject_AsCurrency(obj, &V_CY(var))) + return FALSE; + V_VT(var) = VT_CY; + } /* else if (obj->ob_type == &AutomatedType) *************** *** 327,333 **** case VT_CY: ! // Cheesy support borrowed from: ! // PyIPropertyStorage.cpp. ! result = Py_BuildValue("ll", varValue.cyVal.Hi, varValue.cyVal.Lo); break; --- 333,337 ---- case VT_CY: ! result = PyObject_FromCurrency(varValue.cyVal); break; |
From: Mark H. <mha...@us...> - 2005-05-31 12:32:05
|
Update of /cvsroot/pywin32/pywin32/com/win32com/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23130 Modified Files: testMarshal.py Log Message: Convert to threading module and wait for threads to stop Index: testMarshal.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/com/win32com/test/testMarshal.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** testMarshal.py 31 May 2005 09:28:16 -0000 1.3 --- testMarshal.py 31 May 2005 12:31:50 -0000 1.4 *************** *** 22,26 **** """ ! import thread, traceback import win32com.client import win32event, win32api --- 22,26 ---- """ ! import threading, traceback import win32com.client import win32event, win32api *************** *** 49,53 **** interp.Exec("import win32api") #print "The test thread id is %d, Python.Interpreter's thread ID is %d" % (myThread, interp.Eval("win32api.GetCurrentThreadId()")) - interp = None pythoncom.CoUninitialize() --- 49,52 ---- *************** *** 60,74 **** """ interp = win32com.client.Dispatch("Python.Interpreter") ! ret = [] for i in range(numThreads): hEvent = win32event.CreateEvent(None, 0, 0, None) interpStream = pythoncom.CoMarshalInterThreadInterfaceInStream(pythoncom.IID_IDispatch, interp._oleobj_) ! thread.start_new(self._testInterpInThread, (hEvent, interpStream)) ! ret.append(hEvent) ! return ret # # NOTE - this doesnt quite work - Im not even sure it should, but Greg reckons # you should be able to avoid the marshal per thread! def BeginThreadsFastMarshal(self, numThreads): """Creates multiple threads using fast (but complex) marshalling. --- 59,79 ---- """ interp = win32com.client.Dispatch("Python.Interpreter") ! events = [] ! threads = [] for i in range(numThreads): hEvent = win32event.CreateEvent(None, 0, 0, None) + events.append(hEvent) interpStream = pythoncom.CoMarshalInterThreadInterfaceInStream(pythoncom.IID_IDispatch, interp._oleobj_) ! t = threading.Thread(target=self._testInterpInThread, args=(hEvent, interpStream)) ! t.setDaemon(1) # so errors dont cause shutdown hang ! t.start() ! threads.append(t) ! interp = None ! return threads, events # # NOTE - this doesnt quite work - Im not even sure it should, but Greg reckons # you should be able to avoid the marshal per thread! + # I think that refers to CoMarshalInterface though... def BeginThreadsFastMarshal(self, numThreads): """Creates multiple threads using fast (but complex) marshalling. *************** *** 81,95 **** if freeThreaded: interp = pythoncom.CoMarshalInterThreadInterfaceInStream(pythoncom.IID_IDispatch, interp._oleobj_) ! ret = [] ! for i in range(numThreads): hEvent = win32event.CreateEvent(None, 0, 0, None) ! thread.start_new(self._testInterpInThread, (hEvent, interp)) ! ret.append(hEvent) ! return ret def _DoTestMarshal(self, fn, bCoWait = 0): #print "The main thread is %d" % (win32api.GetCurrentThreadId()) ! events = fn(2) numFinished = 0 while 1: --- 86,103 ---- if freeThreaded: interp = pythoncom.CoMarshalInterThreadInterfaceInStream(pythoncom.IID_IDispatch, interp._oleobj_) ! events = [] ! threads = [] for i in range(numThreads): hEvent = win32event.CreateEvent(None, 0, 0, None) ! t = threading.Thread(target=self._testInterpInThread, args=(hEvent, interp)) ! t.setDaemon(1) # so errors dont cause shutdown hang ! t.start() ! events.append(hEvent) ! threads.append(t) ! return threads, events def _DoTestMarshal(self, fn, bCoWait = 0): #print "The main thread is %d" % (win32api.GetCurrentThreadId()) ! threads, events = fn(2) numFinished = 0 while 1: *************** *** 112,115 **** --- 120,130 ---- except KeyboardInterrupt: break + for t in threads: + t.join(2) + self.failIf(t.isAlive(), "thread failed to stop!?") + threads = None # threads hold references to args + # Seems to be a leak here I can't locate :( + #self.failUnlessEqual(pythoncom._GetInterfaceCount(), 0) + #self.failUnlessEqual(pythoncom._GetGatewayCount(), 0) def testSimpleMarshal(self): |
From: Mark H. <mha...@us...> - 2005-05-31 09:28:25
|
Update of /cvsroot/pywin32/pywin32/com/win32com/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21864 Modified Files: testMarshal.py testall.py Log Message: Ressurect old stale test Index: testall.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/com/win32com/test/testall.py,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** testall.py 11 Oct 2004 06:46:14 -0000 1.25 --- testall.py 31 May 2005 09:28:16 -0000 1.26 *************** *** 77,81 **** testAXScript testxslt testDictionary testCollections testServers errorSemantics.test testvb testArrays ! testClipboard """.split(), # Level 2 tests. --- 77,81 ---- testAXScript testxslt testDictionary testCollections testServers errorSemantics.test testvb testArrays ! testClipboard testMarshal """.split(), # Level 2 tests. Index: testMarshal.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/com/win32com/test/testMarshal.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** testMarshal.py 18 Nov 2002 11:20:07 -0000 1.2 --- testMarshal.py 31 May 2005 09:28:16 -0000 1.3 *************** *** 26,42 **** import win32event, win32api import pythoncom ! from testservers import TestInterp freeThreaded = 1 ! def TestInterpInThread(stopEvent, interp): ! try: ! DoTestInterpInThread(interp) ! finally: ! win32event.SetEvent(stopEvent) ! def DoTestInterpInThread(interp): ! try: pythoncom.CoInitialize() myThread = win32api.GetCurrentThreadId() --- 26,43 ---- import win32event, win32api import pythoncom + import unittest ! from testServers import InterpCase freeThreaded = 1 ! class ThreadInterpCase(InterpCase): ! def _testInterpInThread(self, stopEvent, interp): ! try: ! self._doTestInThread(interp) ! finally: ! win32event.SetEvent(stopEvent) ! def _doTestInThread(self, interp): pythoncom.CoInitialize() myThread = win32api.GetCurrentThreadId() *************** *** 46,122 **** interp = win32com.client.Dispatch(interp) - TestInterp(interp) interp.Exec("import win32api") ! print "The test thread id is %d, Python.Interpreter's thread ID is %d" % (myThread, interp.Eval("win32api.GetCurrentThreadId()")) interp = None pythoncom.CoUninitialize() - except: - traceback.print_exc() ! def BeginThreadsSimpleMarshal(numThreads): ! """Creates multiple threads using simple (but slower) marshalling. ! ! Single interpreter object, but a new stream is created per thread. ! ! Returns the handles the threads will set when complete. ! """ ! interp = win32com.client.Dispatch("Python.Interpreter") ! ret = [] ! for i in range(numThreads): ! hEvent = win32event.CreateEvent(None, 0, 0, None) ! interpStream = pythoncom.CoMarshalInterThreadInterfaceInStream(pythoncom.IID_IDispatch, interp._oleobj_) ! thread.start_new(TestInterpInThread, (hEvent, interpStream)) ! ret.append(hEvent) ! return ret ! # ! # NOTE - this doesnt quite work - Im not even sure it should, but Greg reckons ! # you should be able to avoid the marshal per thread! ! def BeginThreadsFastMarshal(numThreads): ! """Creates multiple threads using fast (but complex) marshalling. ! The marshal stream is created once, and each thread uses the same stream ! Returns the handles the threads will set when complete. ! """ ! interp = win32com.client.Dispatch("Python.Interpreter") ! if freeThreaded: ! interp = pythoncom.CoMarshalInterThreadInterfaceInStream(pythoncom.IID_IDispatch, interp._oleobj_) ! ret = [] ! for i in range(numThreads): ! hEvent = win32event.CreateEvent(None, 0, 0, None) ! thread.start_new(TestInterpInThread, (hEvent, interp)) ! ret.append(hEvent) ! return ret ! def test(fn): ! print "The main thread is %d" % (win32api.GetCurrentThreadId()) ! events = fn(2) ! numFinished = 0 ! while 1: ! try: ! # Specifying "bWaitAll" here seems to prevent messages??? ! rc = win32event.MsgWaitForMultipleObjects(events, 0, 2000, win32event.QS_ALLINPUT) ! if rc >= win32event.WAIT_OBJECT_0 and rc < win32event.WAIT_OBJECT_0+len(events): ! numFinished = numFinished + 1 ! if numFinished >= len(events): ! break ! elif rc==win32event.WAIT_OBJECT_0 + len(events): # a message ! # This is critical - whole apartment model demo will hang. ! pythoncom.PumpWaitingMessages() ! else: # Timeout ! print "Waiting for thread to stop with interfaces=%d, gateways=%d" % (pythoncom._GetInterfaceCount(), pythoncom._GetGatewayCount()) ! except KeyboardInterrupt: ! break if __name__=='__main__': ! test(BeginThreadsSimpleMarshal) ! # test(BeginThreadsFastMarshal) ! win32api.Sleep(500) ! # Doing CoUninit here stop Pythoncom.dll hanging when DLLMain shuts-down the process ! pythoncom.CoUninitialize() ! if pythoncom._GetInterfaceCount()!=0 or pythoncom._GetGatewayCount()!=0: ! print "Done with interfaces=%d, gateways=%d" % (pythoncom._GetInterfaceCount(), pythoncom._GetGatewayCount()) ! else: ! print "Done." --- 47,125 ---- interp = win32com.client.Dispatch(interp) interp.Exec("import win32api") ! #print "The test thread id is %d, Python.Interpreter's thread ID is %d" % (myThread, interp.Eval("win32api.GetCurrentThreadId()")) interp = None pythoncom.CoUninitialize() ! def BeginThreadsSimpleMarshal(self, numThreads): ! """Creates multiple threads using simple (but slower) marshalling. ! ! Single interpreter object, but a new stream is created per thread. ! ! Returns the handles the threads will set when complete. ! """ ! interp = win32com.client.Dispatch("Python.Interpreter") ! ret = [] ! for i in range(numThreads): ! hEvent = win32event.CreateEvent(None, 0, 0, None) ! interpStream = pythoncom.CoMarshalInterThreadInterfaceInStream(pythoncom.IID_IDispatch, interp._oleobj_) ! thread.start_new(self._testInterpInThread, (hEvent, interpStream)) ! ret.append(hEvent) ! return ret ! # ! # NOTE - this doesnt quite work - Im not even sure it should, but Greg reckons ! # you should be able to avoid the marshal per thread! ! def BeginThreadsFastMarshal(self, numThreads): ! """Creates multiple threads using fast (but complex) marshalling. ! ! The marshal stream is created once, and each thread uses the same stream ! ! Returns the handles the threads will set when complete. ! """ ! interp = win32com.client.Dispatch("Python.Interpreter") ! if freeThreaded: ! interp = pythoncom.CoMarshalInterThreadInterfaceInStream(pythoncom.IID_IDispatch, interp._oleobj_) ! ret = [] ! ! for i in range(numThreads): ! hEvent = win32event.CreateEvent(None, 0, 0, None) ! thread.start_new(self._testInterpInThread, (hEvent, interp)) ! ret.append(hEvent) ! return ret ! def _DoTestMarshal(self, fn, bCoWait = 0): ! #print "The main thread is %d" % (win32api.GetCurrentThreadId()) ! events = fn(2) ! numFinished = 0 ! while 1: ! try: ! if bCoWait: ! rc = pythoncom.CoWaitForMultipleHandles(0, 2000, events) ! else: ! # Specifying "bWaitAll" here will wait for messages *and* all events ! # (which is pretty useless) ! rc = win32event.MsgWaitForMultipleObjects(events, 0, 2000, win32event.QS_ALLINPUT) ! if rc >= win32event.WAIT_OBJECT_0 and rc < win32event.WAIT_OBJECT_0+len(events): ! numFinished = numFinished + 1 ! if numFinished >= len(events): ! break ! elif rc==win32event.WAIT_OBJECT_0 + len(events): # a message ! # This is critical - whole apartment model demo will hang. ! pythoncom.PumpWaitingMessages() ! else: # Timeout ! print "Waiting for thread to stop with interfaces=%d, gateways=%d" % (pythoncom._GetInterfaceCount(), pythoncom._GetGatewayCount()) ! except KeyboardInterrupt: ! break ! def testSimpleMarshal(self): ! self._DoTestMarshal(self.BeginThreadsSimpleMarshal) ! def testSimpleMarshalCoWait(self): ! self._DoTestMarshal(self.BeginThreadsSimpleMarshal, 1) ! # def testFastMarshal(self): ! # self._DoTestMarshal(self.BeginThreadsFastMarshal) if __name__=='__main__': ! unittest.main('testMarshal') |
From: Mark H. <mha...@us...> - 2005-05-31 02:07:45
|
Update of /cvsroot/pywin32/pywin32/win32/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31219/src Modified Files: win32security.i win32security_ds.cpp win32security_sspi.h Log Message: Add DsList* functions. Index: win32security_ds.cpp =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/src/win32security_ds.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** win32security_ds.cpp 24 May 2005 13:55:30 -0000 1.1 --- win32security_ds.cpp 31 May 2005 02:07:34 -0000 1.2 *************** *** 6,9 **** --- 6,27 ---- #include "Lm.h" // for NetApiBufferFree, for some Ds functions. + // @object PyDS_NAME_RESULT_ITEM|A tuple representing a DS_NAME_RESULT_ITEM + // @tupleitem 0|int|status| + // @tupleitem 1|<o PyUnicode>|domain| + // @tupleitem 2|<o PyUnicode>|name| + static PyObject *PyObject_FromDS_NAME_RESULT(DS_NAME_RESULT *dsresult) + { + PyObject *ret = PyList_New(dsresult->cItems); + if (!ret) return NULL; + for (DWORD i=0;i<dsresult->cItems;i++) { + DS_NAME_RESULT_ITEM *pi = dsresult->rItems + i; + PyList_SET_ITEM(ret, i, + Py_BuildValue("iNN", pi->status, + PyWinObject_FromWCHAR(pi->pDomain), + PyWinObject_FromWCHAR(pi->pName))); + } + return ret; + } + // Directory service handle, yet another type of PyHANDLE // @object PyDS_HANDLE|Directory service handle, returned by <om win32security.DsBind> *************** *** 72,78 **** if (!PyWinObject_AsHANDLE(obhandle, &dshandle)) return NULL; ! Py_BEGIN_ALLOW_THREADS err=(*pfnDsUnBind)(&dshandle); ! Py_END_ALLOW_THREADS if (err==NO_ERROR){ Py_INCREF(Py_None); --- 90,96 ---- if (!PyWinObject_AsHANDLE(obhandle, &dshandle)) return NULL; ! Py_BEGIN_ALLOW_THREADS err=(*pfnDsUnBind)(&dshandle); ! Py_END_ALLOW_THREADS if (err==NO_ERROR){ Py_INCREF(Py_None); *************** *** 188,196 **** } ! Py_BEGIN_ALLOW_THREADS err=(*pfnDsGetSpn)(ServiceType, ServiceClass, ServiceName, InstancePort, cInstanceNames, (LPCWSTR *)InstanceNames, InstancePorts, &cSpns, &Spns); ! Py_END_ALLOW_THREADS if (err!=STATUS_SUCCESS) PyWin_SetAPIError("DsGetSpn",err); --- 206,214 ---- } ! Py_BEGIN_ALLOW_THREADS err=(*pfnDsGetSpn)(ServiceType, ServiceClass, ServiceName, InstancePort, cInstanceNames, (LPCWSTR *)InstanceNames, InstancePorts, &cSpns, &Spns); ! Py_END_ALLOW_THREADS if (err!=STATUS_SUCCESS) PyWin_SetAPIError("DsGetSpn",err); *************** *** 239,245 **** if (!PyWinObject_AsWCHARArray(obspns, &spns, &spn_cnt)) goto done; ! Py_BEGIN_ALLOW_THREADS err=(*pfnDsWriteAccountSpn)(dshandle, Operation, acct, spn_cnt, (LPCWSTR *)spns); ! Py_END_ALLOW_THREADS if (err!=STATUS_SUCCESS) PyWin_SetAPIError("DsWriteAccountSpn", err); --- 257,263 ---- if (!PyWinObject_AsWCHARArray(obspns, &spns, &spn_cnt)) goto done; ! Py_BEGIN_ALLOW_THREADS err=(*pfnDsWriteAccountSpn)(dshandle, Operation, acct, spn_cnt, (LPCWSTR *)spns); ! Py_END_ALLOW_THREADS if (err!=STATUS_SUCCESS) PyWin_SetAPIError("DsWriteAccountSpn", err); *************** *** 256,260 **** PyObject *PyDsGetDcName(PyObject *self, PyObject *args, PyObject *kw) { ! static char *kw_items[]= { "computerName","domainName","domainGUID","siteName", "flags", NULL, }; --- 274,278 ---- PyObject *PyDsGetDcName(PyObject *self, PyObject *args, PyObject *kw) { ! static char *kw_items[]= { "computerName","domainName","domainGUID","siteName", "flags", NULL, }; *************** *** 262,278 **** CHECK_PFN(DsGetDcName); PyObject *obServer = Py_None, *obDomain = Py_None, *obSiteName = Py_None; ! PyObject *obGUID = Py_None; WCHAR *szServer = NULL, *szDomain = NULL, *szSiteName = NULL; ! GUID guidBuf, *pGUID = NULL; PyObject *ret = NULL; ! DOMAIN_CONTROLLER_INFO *pdci = NULL; ! DWORD flags = 0; DWORD err; if (!PyArg_ParseTupleAndKeywords(args, kw, "|OOOOi:DsGetDcName", kw_items, ! &obServer, ! &obDomain, ! &obGUID, ! &obSiteName, ! &flags)) return NULL; if (!PyWinObject_AsWCHAR(obServer, &szServer, TRUE)) --- 280,296 ---- CHECK_PFN(DsGetDcName); PyObject *obServer = Py_None, *obDomain = Py_None, *obSiteName = Py_None; ! PyObject *obGUID = Py_None; WCHAR *szServer = NULL, *szDomain = NULL, *szSiteName = NULL; ! GUID guidBuf, *pGUID = NULL; PyObject *ret = NULL; ! DOMAIN_CONTROLLER_INFO *pdci = NULL; ! DWORD flags = 0; DWORD err; if (!PyArg_ParseTupleAndKeywords(args, kw, "|OOOOi:DsGetDcName", kw_items, ! &obServer, ! &obDomain, ! &obGUID, ! &obSiteName, ! &flags)) return NULL; if (!PyWinObject_AsWCHAR(obServer, &szServer, TRUE)) *************** *** 282,309 **** if (!PyWinObject_AsWCHAR(obSiteName, &szSiteName, TRUE)) goto done; ! if (obGUID != Py_None) { ! if (!PyWinObject_AsIID(obGUID, &guidBuf)) ! goto done; ! pGUID = &guidBuf; ! } ! Py_BEGIN_ALLOW_THREADS ! err = (*pfnDsGetDcName)(szServer, szDomain, pGUID, szSiteName, flags, &pdci); ! Py_END_ALLOW_THREADS if (err) { PyWin_SetAPIError("DsGetDcName", err); goto done; } ! ret = Py_BuildValue("{s:N,s:N,s:i,s:N,s:N,s:N,s:i,s:N,s:N}", ! "DomainControllerName", PyWinObject_FromTCHAR(pdci->DomainControllerName), ! "DomainControllerAddress", PyWinObject_FromTCHAR(pdci->DomainControllerAddress), ! "DomainControllerAddressType", pdci->DomainControllerAddressType, ! "DomainGuid", PyWinObject_FromIID(pdci->DomainGuid), ! "DomainName", PyWinObject_FromTCHAR(pdci->DomainName), ! "DnsForestName", PyWinObject_FromTCHAR(pdci->DnsForestName), ! "Flags", pdci->Flags, ! "DcSiteName", PyWinObject_FromTCHAR(pdci->DcSiteName), ! "ClientSiteName", PyWinObject_FromTCHAR(pdci->ClientSiteName)); ! // @rdesc The result is a dictionary with keys having the same name as the ! // Win32 DOMAIN_CONTROLLER_INFO struct. done: PyWinObject_FreeWCHAR(szServer); --- 300,327 ---- if (!PyWinObject_AsWCHAR(obSiteName, &szSiteName, TRUE)) goto done; ! if (obGUID != Py_None) { ! if (!PyWinObject_AsIID(obGUID, &guidBuf)) ! goto done; ! pGUID = &guidBuf; ! } ! Py_BEGIN_ALLOW_THREADS ! err = (*pfnDsGetDcName)(szServer, szDomain, pGUID, szSiteName, flags, &pdci); ! Py_END_ALLOW_THREADS if (err) { PyWin_SetAPIError("DsGetDcName", err); goto done; } ! ret = Py_BuildValue("{s:N,s:N,s:i,s:N,s:N,s:N,s:i,s:N,s:N}", ! "DomainControllerName", PyWinObject_FromTCHAR(pdci->DomainControllerName), ! "DomainControllerAddress", PyWinObject_FromTCHAR(pdci->DomainControllerAddress), ! "DomainControllerAddressType", pdci->DomainControllerAddressType, ! "DomainGuid", PyWinObject_FromIID(pdci->DomainGuid), ! "DomainName", PyWinObject_FromTCHAR(pdci->DomainName), ! "DnsForestName", PyWinObject_FromTCHAR(pdci->DnsForestName), ! "Flags", pdci->Flags, ! "DcSiteName", PyWinObject_FromTCHAR(pdci->DcSiteName), ! "ClientSiteName", PyWinObject_FromTCHAR(pdci->ClientSiteName)); ! // @rdesc The result is a dictionary with keys having the same name as the ! // Win32 DOMAIN_CONTROLLER_INFO struct. done: PyWinObject_FreeWCHAR(szServer); *************** *** 320,333 **** DS_NAME_FLAGS flags; DS_NAME_FORMAT formatOffered, formatDesired; ! PyObject *obNames; PyObject *ret=NULL, *obhandle; ! LPWSTR *names; ! DWORD cnames; ! PDS_NAME_RESULT dsresult = NULL; ! CHECK_PFN(DsCrackNames); CHECK_PFN(DsFreeNameResult); if (!PyArg_ParseTuple(args, "OlllO:DsCrackNames", &obhandle, &flags, &formatOffered, ! &formatDesired, &obNames)) return NULL; if (!PyWinObject_AsHANDLE(obhandle, &dshandle, TRUE)) --- 338,351 ---- DS_NAME_FLAGS flags; DS_NAME_FORMAT formatOffered, formatDesired; ! PyObject *obNames; PyObject *ret=NULL, *obhandle; ! LPWSTR *names; ! DWORD cnames; ! PDS_NAME_RESULT dsresult = NULL; ! CHECK_PFN(DsCrackNames); CHECK_PFN(DsFreeNameResult); if (!PyArg_ParseTuple(args, "OlllO:DsCrackNames", &obhandle, &flags, &formatOffered, ! &formatDesired, &obNames)) return NULL; if (!PyWinObject_AsHANDLE(obhandle, &dshandle, TRUE)) *************** *** 335,358 **** if (!PyWinObject_AsWCHARArray(obNames, &names, &cnames)) goto done; ! Py_BEGIN_ALLOW_THREADS err=(*pfnDsCrackNames)(dshandle, flags, formatOffered, formatDesired, cnames, names, &dsresult); ! Py_END_ALLOW_THREADS if (err!=STATUS_SUCCESS || !dsresult) ! PyWin_SetAPIError("DsWriteAccountSpn", err); ! else { ! ret = PyList_New(dsresult->cItems); ! if (!ret) goto done; ! for (DWORD i=0;i<dsresult->cItems;i++) { ! DS_NAME_RESULT_ITEM *pi = dsresult->rItems + i; ! PyList_SET_ITEM(ret, i, ! Py_BuildValue("iNN", pi->status, ! PyWinObject_FromWCHAR(pi->pDomain), ! PyWinObject_FromWCHAR(pi->pName))); ! } ! } done: PyWinObject_FreeWCHARArray(names, cnames); ! if (dsresult) ! (*pfnDsFreeNameResult)(dsresult); return ret; } --- 353,554 ---- if (!PyWinObject_AsWCHARArray(obNames, &names, &cnames)) goto done; ! Py_BEGIN_ALLOW_THREADS err=(*pfnDsCrackNames)(dshandle, flags, formatOffered, formatDesired, cnames, names, &dsresult); ! Py_END_ALLOW_THREADS if (err!=STATUS_SUCCESS || !dsresult) ! PyWin_SetAPIError("DsCrackNames", err); ! else ! ret = PyObject_FromDS_NAME_RESULT(dsresult); done: PyWinObject_FreeWCHARArray(names, cnames); ! if (dsresult) ! (*pfnDsFreeNameResult)(dsresult); ! return ret; ! } ! ! PyObject *PyDsListInfoForServer(PyObject *self, PyObject *args) ! { ! DWORD err; ! HANDLE dshandle; ! PyObject *obName; ! PyObject *ret=NULL, *obhandle; ! PDS_NAME_RESULT dsresult = NULL; ! WCHAR *name = NULL; ! ! CHECK_PFN(DsListInfoForServer); ! CHECK_PFN(DsFreeNameResult); ! // @pyparm int|hds|| ! // @pyparm <o PyUnicode>|server|| ! if (!PyArg_ParseTuple(args, "OO:DsListInfoForServer", &obhandle, &obName)) ! return NULL; ! if (!PyWinObject_AsHANDLE(obhandle, &dshandle, TRUE)) ! return NULL; ! if (!PyWinObject_AsWCHAR(obName, &name)) ! goto done; ! Py_BEGIN_ALLOW_THREADS ! err=(*pfnDsListInfoForServer)(dshandle, name, &dsresult); ! Py_END_ALLOW_THREADS ! if (err!=STATUS_SUCCESS || !dsresult) ! PyWin_SetAPIError("DsListInfoForServer", err); ! else ! ret = PyObject_FromDS_NAME_RESULT(dsresult); ! done: ! PyWinObject_FreeWCHAR(name); ! if (dsresult) ! (*pfnDsFreeNameResult)(dsresult); ! return ret; ! } ! ! PyObject *PyDsListServersForDomainInSite(PyObject *self, PyObject *args) ! { ! DWORD err; ! HANDLE dshandle; ! PyObject *obName, *obSite; ! PyObject *ret=NULL, *obhandle; ! PDS_NAME_RESULT dsresult = NULL; ! WCHAR *name = NULL, *site = NULL; ! ! CHECK_PFN(DsListServersForDomainInSite); ! CHECK_PFN(DsFreeNameResult); ! // @pyparm int|hds|| ! // @pyparm <o PyUnicode>|sute|| ! if (!PyArg_ParseTuple(args, "OOO:DsListServersForDomainInSite", &obhandle, &obName, &obSite)) ! return NULL; ! if (!PyWinObject_AsHANDLE(obhandle, &dshandle, TRUE)) ! return NULL; ! if (!PyWinObject_AsWCHAR(obName, &name)) ! goto done; ! if (!PyWinObject_AsWCHAR(obSite, &site)) ! goto done; ! Py_BEGIN_ALLOW_THREADS ! err=(*pfnDsListServersForDomainInSite)(dshandle, name, site, &dsresult); ! Py_END_ALLOW_THREADS ! if (err!=STATUS_SUCCESS || !dsresult) ! PyWin_SetAPIError("DsListServersForDomainInSite", err); ! else ! ret = PyObject_FromDS_NAME_RESULT(dsresult); ! done: ! PyWinObject_FreeWCHAR(name); ! PyWinObject_FreeWCHAR(site); ! if (dsresult) ! (*pfnDsFreeNameResult)(dsresult); ! return ret; ! } ! ! PyObject *PyDsListServersInSite(PyObject *self, PyObject *args) ! { ! DWORD err; ! HANDLE dshandle; ! PyObject *obName; ! PyObject *ret=NULL, *obhandle; ! PDS_NAME_RESULT dsresult = NULL; ! WCHAR *name = NULL; ! ! CHECK_PFN(DsListServersInSite); ! CHECK_PFN(DsFreeNameResult); ! // @pyparm int|hds|| ! // @pyparm <o PyUnicode>|sute|| ! if (!PyArg_ParseTuple(args, "OO:DsListServersInSite", &obhandle, &obName)) ! return NULL; ! if (!PyWinObject_AsHANDLE(obhandle, &dshandle, TRUE)) ! return NULL; ! if (!PyWinObject_AsWCHAR(obName, &name)) ! goto done; ! Py_BEGIN_ALLOW_THREADS ! err=(*pfnDsListServersInSite)(dshandle, name, &dsresult); ! Py_END_ALLOW_THREADS ! if (err!=STATUS_SUCCESS || !dsresult) ! PyWin_SetAPIError("DsListServersInSite", err); ! else ! ret = PyObject_FromDS_NAME_RESULT(dsresult); ! done: ! PyWinObject_FreeWCHAR(name); ! if (dsresult) ! (*pfnDsFreeNameResult)(dsresult); ! return ret; ! } ! ! PyObject *PyDsListSites(PyObject *self, PyObject *args) ! { ! DWORD err; ! HANDLE dshandle; ! PyObject *ret=NULL, *obhandle; ! PDS_NAME_RESULT dsresult = NULL; ! ! CHECK_PFN(DsListSites); ! CHECK_PFN(DsFreeNameResult); ! // @pyparm int|hds|| ! if (!PyArg_ParseTuple(args, "O:DsListSites", &obhandle)) ! return NULL; ! if (!PyWinObject_AsHANDLE(obhandle, &dshandle, TRUE)) ! return NULL; ! Py_BEGIN_ALLOW_THREADS ! err=(*pfnDsListSites)(dshandle, &dsresult); ! Py_END_ALLOW_THREADS ! if (err!=STATUS_SUCCESS || !dsresult) ! PyWin_SetAPIError("DsListSites", err); ! else ! ret = PyObject_FromDS_NAME_RESULT(dsresult); ! if (dsresult) ! (*pfnDsFreeNameResult)(dsresult); ! return ret; ! } ! ! PyObject *PyDsListRoles(PyObject *self, PyObject *args) ! { ! DWORD err; ! HANDLE dshandle; ! PyObject *ret=NULL, *obhandle; ! PDS_NAME_RESULT dsresult = NULL; ! ! CHECK_PFN(DsListRoles); ! CHECK_PFN(DsFreeNameResult); ! // @pyparm int|hds|| ! if (!PyArg_ParseTuple(args, "O:DsListRoles", &obhandle)) ! return NULL; ! if (!PyWinObject_AsHANDLE(obhandle, &dshandle, TRUE)) ! return NULL; ! Py_BEGIN_ALLOW_THREADS ! err=(*pfnDsListRoles)(dshandle, &dsresult); ! Py_END_ALLOW_THREADS ! if (err!=STATUS_SUCCESS || !dsresult) ! PyWin_SetAPIError("DsListRoles", err); ! else ! ret = PyObject_FromDS_NAME_RESULT(dsresult); ! if (dsresult) ! (*pfnDsFreeNameResult)(dsresult); ! return ret; ! } ! ! PyObject *PyDsListDomainsInSite(PyObject *self, PyObject *args) ! { ! DWORD err; ! HANDLE dshandle; ! PyObject *obName; ! PyObject *ret=NULL, *obhandle; ! PDS_NAME_RESULT dsresult = NULL; ! WCHAR *name = NULL; ! ! CHECK_PFN(DsListDomainsInSite); ! CHECK_PFN(DsFreeNameResult); ! // @pyparm int|hds|| ! // @pyparm <o PyUnicode>|site|| ! if (!PyArg_ParseTuple(args, "OO:DsListDomainsInSite", &obhandle, &obName)) ! return NULL; ! if (!PyWinObject_AsHANDLE(obhandle, &dshandle, TRUE)) ! return NULL; ! if (!PyWinObject_AsWCHAR(obName, &name)) ! goto done; ! Py_BEGIN_ALLOW_THREADS ! err=(*pfnDsListDomainsInSite)(dshandle, name, &dsresult); ! Py_END_ALLOW_THREADS ! if (err!=STATUS_SUCCESS || !dsresult) ! PyWin_SetAPIError("DsListDomainsInSite", err); ! else ! ret = PyObject_FromDS_NAME_RESULT(dsresult); ! done: ! PyWinObject_FreeWCHAR(name); ! if (dsresult) ! (*pfnDsFreeNameResult)(dsresult); return ret; } Index: win32security_sspi.h =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/src/win32security_sspi.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** win32security_sspi.h 24 May 2005 13:55:30 -0000 1.3 --- win32security_sspi.h 31 May 2005 02:07:34 -0000 1.4 *************** *** 186,189 **** --- 186,207 ---- extern DsCrackNamesfunc pfnDsCrackNames; + typedef DWORD (WINAPI *DsListInfoForServerfunc)(HANDLE, LPTSTR, PDS_NAME_RESULT *); + extern DsListInfoForServerfunc pfnDsListInfoForServer; + + typedef DWORD (WINAPI *DsListServersInSitefunc)(HANDLE, LPTSTR, PDS_NAME_RESULT *); + extern DsListServersInSitefunc pfnDsListServersInSite; + + typedef DWORD (WINAPI *DsListDomainsInSitefunc)(HANDLE, LPTSTR, PDS_NAME_RESULT *); + extern DsListDomainsInSitefunc pfnDsListDomainsInSite; + + typedef DWORD (WINAPI *DsListServersForDomainInSitefunc)(HANDLE, LPTSTR, LPTSTR, PDS_NAME_RESULT *); + extern DsListServersForDomainInSitefunc pfnDsListServersForDomainInSite; + + typedef DWORD (WINAPI *DsListSitesfunc)(HANDLE, PDS_NAME_RESULT *); + extern DsListSitesfunc pfnDsListSites; + + typedef DWORD (WINAPI *DsListRolesfunc)(HANDLE, PDS_NAME_RESULT *); + extern DsListRolesfunc pfnDsListRoles; + typedef VOID (WINAPI *DsFreeNameResultfunc)(DS_NAME_RESULTW *); extern DsFreeNameResultfunc pfnDsFreeNameResult; Index: win32security.i =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/src/win32security.i,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** win32security.i 27 May 2005 07:14:05 -0000 1.26 --- win32security.i 31 May 2005 02:07:34 -0000 1.27 *************** *** 80,84 **** static TranslateNamefunc pfnTranslateName=NULL; ! // function pointers used in win32security_sspi.cpp extern DsBindfunc pfnDsBind=NULL; extern DsUnBindfunc pfnDsUnBind=NULL; --- 80,84 ---- static TranslateNamefunc pfnTranslateName=NULL; ! // function pointers used in win32security_sspi.cpp and win32security_ds.cpp extern DsBindfunc pfnDsBind=NULL; extern DsUnBindfunc pfnDsUnBind=NULL; *************** *** 88,91 **** --- 88,97 ---- extern DsGetDcNamefunc pfnDsGetDcName=NULL; extern DsCrackNamesfunc pfnDsCrackNames=NULL; + extern DsListInfoForServerfunc pfnDsListInfoForServer=NULL; + extern DsListServersForDomainInSitefunc pfnDsListServersForDomainInSite=NULL; + extern DsListServersInSitefunc pfnDsListServersInSite=NULL; + extern DsListSitesfunc pfnDsListSites=NULL; + extern DsListDomainsInSitefunc pfnDsListDomainsInSite=NULL; + extern DsListRolesfunc pfnDsListRoles=NULL; extern DsFreeNameResultfunc pfnDsFreeNameResult=NULL; *************** *** 651,654 **** --- 657,667 ---- pfnDsFreeSpnArray=(DsFreeSpnArrayfunc)loadapifunc("DsFreeSpnArrayW", ntdsapi_dll); pfnDsCrackNames=(DsCrackNamesfunc)loadapifunc("DsCrackNamesW", ntdsapi_dll); + pfnDsListInfoForServer=(DsListInfoForServerfunc)loadapifunc("DsListInfoForServerW", ntdsapi_dll); + pfnDsListDomainsInSite=(DsListDomainsInSitefunc)loadapifunc("DsListDomainsInSiteW", ntdsapi_dll); + pfnDsListServersForDomainInSite=(DsListServersForDomainInSitefunc)loadapifunc("DsListServersForDomainInSiteW", ntdsapi_dll); + pfnDsListServersInSite=(DsListServersInSitefunc)loadapifunc("DsListServersInSiteW", ntdsapi_dll); + pfnDsListSites=(DsListSitesfunc)loadapifunc("DsListSitesW", ntdsapi_dll); + pfnDsListRoles=(DsListRolesfunc)loadapifunc("DsListRolesW", ntdsapi_dll); + pfnDsFreeNameResult=(DsFreeNameResultfunc)loadapifunc("DsFreeNameResultW", ntdsapi_dll); pfnDsGetDcName=(DsGetDcNamefunc)loadapifunc("DsGetDcNameW", netapi32_dll); *************** *** 709,717 **** %native (DsCrackNames) extern PyObject *PyDsCrackNames(PyObject *self, PyObject *args); // @pyswig [ (status, domain, name) ]|DsCrackNames|Converts an array of directory service object names from one format to another. ! // @pyswig int|flags|| // @pyparm int|formatOffered|| // @pyparm int|formatDesired|| // @pyparm [name, ...]|names|| // @pyswig PyACL|ACL|Creates a new <o PyACL> object. // @pyparm int|bufSize|64|The size of the buffer for the ACL. --- 722,759 ---- %native (DsCrackNames) extern PyObject *PyDsCrackNames(PyObject *self, PyObject *args); // @pyswig [ (status, domain, name) ]|DsCrackNames|Converts an array of directory service object names from one format to another. ! // @pyparm int|hds|| ! // @pyparm int|flags|| // @pyparm int|formatOffered|| // @pyparm int|formatDesired|| // @pyparm [name, ...]|names|| + %native (DsListInfoForServer) extern PyObject *PyDsListInfoForServer(PyObject *self, PyObject *args); + // @pyswig [ <o PyDS_NAME_RESULT>, ...]|DsListInfoForServer|Lists miscellaneous information for a server. + // @pyparm int|hds|| + // @pyparm <o PyUnicode>|server|| + + %native (DsListServersInSite) extern PyObject *PyDsListServersInSite(PyObject *self, PyObject *args); + // @pyswig [ <o PyDS_NAME_RESULT_ITEM>, ...]|DsListServersInSite| + // @pyparm int|hds|| + // @pyparm <o PyUnicode>|site|| + + %native (DsListServersForDomainInSite) extern PyObject *PyDsListServersForDomainInSite(PyObject *self, PyObject *args); + // @pyswig [ <o PyDS_NAME_RESULT_ITEM>, ...]|DsListServersInSite| + // @pyparm int|hds|| + // @pyparm <o PyUnicode>|domain|| + // @pyparm <o PyUnicode>|site|| + + %native (DsListSites) extern PyObject *PyDsListSites(PyObject *self, PyObject *args); + // @pyswig [ <o PyDS_NAME_RESULT_ITEM>, ...]|DsListServersInSite| + // @pyparm int|hds|| + + %native (DsListRoles) extern PyObject *PyDsListRoles(PyObject *self, PyObject *args); + // @pyswig [ <o PyDS_NAME_RESULT_ITEM>, ...]|DsListRoles| + // @pyparm int|hds|| + + %native (DsListDomainsInSite) extern PyObject *PyDsListDomainsInSite(PyObject *self, PyObject *args); + // @pyswig [ <o PyDS_NAME_RESULT_ITEM>, ...]|DsListDomainsInSite| + // @pyparm int|hds|| + // @pyswig PyACL|ACL|Creates a new <o PyACL> object. // @pyparm int|bufSize|64|The size of the buffer for the ACL. |
From: Mark H. <mha...@us...> - 2005-05-31 02:07:43
|
Update of /cvsroot/pywin32/pywin32/win32/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31219/test Modified Files: test_security.py Log Message: Add DsList* functions. Index: test_security.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/test/test_security.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** test_security.py 24 May 2005 13:55:30 -0000 1.3 --- test_security.py 31 May 2005 02:07:35 -0000 1.4 *************** *** 1,2 **** --- 1,3 ---- + # Tests for the win32security module. import sys, os import unittest *************** *** 37,40 **** --- 38,50 ---- win32security.DsGetDcName() + def testDsListServerInfo(self): + # again, not checking much, just exercising the code. + h=win32security.DsBind() + for (status, ignore, site) in win32security.DsListSites(h): + for (status, ignore, server) in win32security.DsListServersInSite(h, site): + info = win32security.DsListInfoForServer(h, server) + for (status, ignore, domain) in win32security.DsListDomainsInSite(h, site): + pass + def testDsCrackNames(self): h = win32security.DsBind() |
From: Mark H. <mha...@us...> - 2005-05-30 23:57:22
|
Update of /cvsroot/pywin32/pywin32/win32/Lib In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28753 Modified Files: win32serviceutil.py Log Message: _GetServiceShortName() ignores case when looking for a service description Index: win32serviceutil.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/Lib/win32serviceutil.py,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** win32serviceutil.py 27 May 2005 07:11:46 -0000 1.18 --- win32serviceutil.py 30 May 2005 23:57:13 -0000 1.19 *************** *** 51,54 **** --- 51,55 ---- hkey = win32api.RegOpenKey(win32con.HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Services", 0, access) num = win32api.RegQueryInfoKey(hkey)[0] + longName = longName.lower() # loop through number of subkeys for x in range(0, num): *************** *** 57,63 **** skey = win32api.RegOpenKey(hkey, svc, 0, access) try: ! # find short name ! shortName = str(win32api.RegQueryValueEx(skey, "DisplayName")[0]) ! if shortName == longName: return svc except win32api.error: --- 58,64 ---- skey = win32api.RegOpenKey(hkey, svc, 0, access) try: ! # find display name ! thisName = str(win32api.RegQueryValueEx(skey, "DisplayName")[0]) ! if thisName.lower() == longName: return svc except win32api.error: |
From: Mark H. <mha...@us...> - 2005-05-27 07:14:15
|
Update of /cvsroot/pywin32/pywin32/win32/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6819 Modified Files: win32security.i Log Message: Document result of LsaEnumerateAccountRights Index: win32security.i =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/src/win32security.i,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** win32security.i 24 May 2005 13:55:29 -0000 1.25 --- win32security.i 27 May 2005 07:14:05 -0000 1.26 *************** *** 2319,2323 **** %} ! // @pyswig |LsaEnumerateAccountRights|Lists privileges held by SID %native(LsaEnumerateAccountRights) PyLsaEnumerateAccountRights; %{ --- 2319,2323 ---- %} ! // @pyswig [<o PyUnicode>, ...]|LsaEnumerateAccountRights|Lists privileges held by SID %native(LsaEnumerateAccountRights) PyLsaEnumerateAccountRights; %{ |
From: Mark H. <mha...@us...> - 2005-05-27 07:13:28
|
Update of /cvsroot/pywin32/pywin32/win32/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6528 Modified Files: win32gui.i Log Message: Add GetMessage, SetDoubleClickTime, GetDoubleClickTime, DragDetect and DragAcceptFiles Index: win32gui.i =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/src/win32gui.i,v retrieving revision 1.64 retrieving revision 1.65 diff -C2 -d -r1.64 -r1.65 *** win32gui.i 23 May 2005 14:27:58 -0000 1.64 --- win32gui.i 27 May 2005 07:13:00 -0000 1.65 *************** *** 184,187 **** --- 184,220 ---- } + %typemap(python,ignore) MSG *OUTPUT(MSG temp) + { + $target = &temp; + memset($target, 0, sizeof(MSG)); + } + + %typemap(python,argout) MSG *OUTPUT{ + PyObject *o; + o = Py_BuildValue("iiiii(ii)", + $source->hwnd, + $source->message, + $source->wParam, + $source->lParam, + $source->time, + $source->pt.x, + $source->pt.y); + 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); + } + } + %typemap(python,in) MSG *INPUT { $target = (MSG *)_alloca(sizeof(MSG)); *************** *** 2178,2181 **** --- 2211,2234 ---- TCHAR *INPUT_NULLOK); // @pyparm string|WindowName|| + // @pyswig |DragAcceptFiles|Registers whether a window accepts dropped files. + // @pyparm int|hwnd||Handle to the Window + // @pyparm int|fAccept||Value that indicates if the window identified by the hWnd parameter accepts dropped files. + // This value is True to accept dropped files or False to discontinue accepting dropped files. + void DragAcceptFiles(HWND hWnd, BOOL fAccept); + + // @pyswig |DragDetect|captures the mouse and tracks its movement until the user releases the left button, presses the ESC key, or moves the mouse outside the drag rectangle around the specified point. + // @pyparm int|hwnd||Handle to the Window + // @pyparm (int, int)|point||Initial position of the mouse, in screen coordinates. The function determines the coordinates of the drag rectangle by using this point. + // @rdesc If the user moved the mouse outside of the drag rectangle while holding down the left button , the return value is nonzero. + // <nl>If the user did not move the mouse outside of the drag rectangle while holding down the left button , the return value is zero. + BOOL DragDetect(HWND hWnd, POINT INPUT); + + // @pyswig int|GetDoubleClickTime| + UINT GetDoubleClickTime(); + + // @pyswig |SetDoubleClickTime| + // @pyparm int|newVal|| + BOOLAPI SetDoubleClickTime(UINT val); + // @pyswig |HideCaret| BOOLAPI HideCaret(HWND hWnd); *************** *** 2419,2422 **** --- 2472,2478 ---- %native (PumpWaitingMessages) PyPumpWaitingMessages; + // @pyswig MSG|GetMessage| + BOOL GetMessage(MSG *OUTPUT, HWND hwnd, UINT min, UINT max); + // @pyswig int|TranslateMessage| // @pyparm MSG|msg|| |
From: Mark H. <mha...@us...> - 2005-05-27 07:12:11
|
Update of /cvsroot/pywin32/pywin32/win32/Lib In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6320 Modified Files: win32serviceutil.py Log Message: When looking for a service name, allow ERROR_INVALID_NAME. Index: win32serviceutil.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/Lib/win32serviceutil.py,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** win32serviceutil.py 11 Apr 2005 00:37:09 -0000 1.17 --- win32serviceutil.py 27 May 2005 07:11:46 -0000 1.18 *************** *** 71,75 **** return win32service.OpenService(hscm, name, access) except win32api.error, details: ! if details[0]!=winerror.ERROR_SERVICE_DOES_NOT_EXIST: raise name = _GetServiceShortName(name) --- 71,76 ---- return win32service.OpenService(hscm, name, access) except win32api.error, details: ! if details[0] not in [winerror.ERROR_SERVICE_DOES_NOT_EXIST, ! winerror.ERROR_INVALID_NAME]: raise name = _GetServiceShortName(name) |
From: Mark H. <mha...@us...> - 2005-05-27 07:09:45
|
Update of /cvsroot/pywin32/pywin32/com/win32comext/adsi/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5722/com/win32comext/adsi/src Modified Files: PyIADsUser.i adsi.i Added Files: PyIADs.cpp PyIADs.h PyIADsDeleteOps.i Log Message: * Add IADs and IADsDeleteOps Index: adsi.i =================================================================== RCS file: /cvsroot/pywin32/pywin32/com/win32comext/adsi/src/adsi.i,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** adsi.i 26 May 2005 11:39:30 -0000 1.5 --- adsi.i 27 May 2005 07:09:36 -0000 1.6 *************** *** 25,28 **** --- 25,29 ---- %{ #include "objsel.h" + #include "PyIADs.h" #include "PyIEnumVARIANT.h" #include "PythonCOMServer.h" *************** *** 32,39 **** --- 33,43 ---- #include "PyIADsContainer.h" #include "PyIADsUser.h" + #include "PyIADsDeleteOps.h" #include "PyIDsObjectPicker.h" #include "ADSIID.h" extern PyTypeObject PyDSOP_SCOPE_INIT_INFOsType; + extern PyObject* PyIADs_getattro(PyObject *ob, PyObject *obname); + extern PyObject* PyIADsUser_getattro(PyObject *ob, PyObject *obname); %} *************** *** 243,247 **** AddIID(d, "LIBID_ADs", LIBID_ADs); - ADD_IID(IID_IADs); ADD_IID(IID_IADsNamespaces); ADD_IID(IID_IADsDomain); --- 247,250 ---- *************** *** 286,289 **** --- 289,299 ---- AddIID(d, "DBPROPSET_ADSISEARCH", DBPROPSET_ADSISEARCH); + if ( PyCom_RegisterClientType(&PyIADs::type, &IID_IADs) != 0 ) return; + ADD_IID(IID_IADs); + // Patch up getattro for all types deriving from IADs + PyIADs::type.tp_getattro = PyIADs_getattro; + PyIADsUser::type.tp_getattro = PyIADsUser_getattro; + + if ( PyCom_RegisterClientType(&PyIDirectoryObject::type, &IID_IDirectoryObject) != 0 ) return; ADD_IID(IID_IDirectoryObject); *************** *** 300,302 **** --- 310,315 ---- if ( PyCom_RegisterClientType(&PyIDsObjectPicker::type, &IID_IDsObjectPicker) != 0 ) return; ADD_IID(IID_IDsObjectPicker); + + if ( PyCom_RegisterClientType(&PyIADsDeleteOps::type, &IID_IADsDeleteOps) != 0 ) return; + ADD_IID(IID_IADsDeleteOps); %} --- NEW FILE: PyIADsDeleteOps.i --- %module IADsDeleteOps // A COM interface to ADSI's IADsDeleteOps interface. %include "typemaps.i" %include "pywin32.i" %include "pythoncom.i" %include "adsilib.i" %{ #include "PyIADsDeleteOps.h" #define SWIG_THIS_IID IID_IADsDeleteOps PyIADsDeleteOps::PyIADsDeleteOps(IUnknown *pDisp) : PyIDispatch(pDisp) { ob_type = &type; } PyIADsDeleteOps::~PyIADsDeleteOps() { } IADsDeleteOps *PyIADsDeleteOps::GetI(PyObject *self) { return (IADsDeleteOps *)PyIDispatch::GetI(self); } %} // @pyswig |DeleteObject| // @pyswig int|flags|0| HRESULT DeleteObject(LONG flags = 0); --- NEW FILE: PyIADs.h --- // This file declares the IADs Interface and Gateway for Python. // Generated by makegw.py // --------------------------------------------------- // // Interface Declaration class PyIADs : public PyIDispatch { public: MAKE_PYCOM_CTOR(PyIADs); static IADs *GetI(PyObject *self); static PyComTypeObject type; // The Python methods static PyObject *GetInfo(PyObject *self, PyObject *args); static PyObject *SetInfo(PyObject *self, PyObject *args); static PyObject *Get(PyObject *self, PyObject *args); static PyObject *Put(PyObject *self, PyObject *args); static PyObject *GetEx(PyObject *self, PyObject *args); static PyObject *PutEx(PyObject *self, PyObject *args); static PyObject *GetInfoEx(PyObject *self, PyObject *args); protected: PyIADs(IUnknown *pdisp); ~PyIADs(); }; --- NEW FILE: PyIADs.cpp --- // This file implements the IADs Interface and Gateway for Python. // Generated by makegw.py // This interface does not use SWIG, mainly so we can implement a custom // getattr for the type. // All "get_" methods have been exposed as properties. #include "pythoncom.h" #include "PyADSIutil.h" #include "PyIADs.h" // @doc - This file contains autoduck documentation // --------------------------------------------------- // // Interface Implementation PyIADs::PyIADs(IUnknown *pdisp): PyIDispatch(pdisp) { ob_type = &type; } PyIADs::~PyIADs() { } /* static */ IADs *PyIADs::GetI(PyObject *self) { return (IADs *)PyIDispatch::GetI(self); } // @pymethod |PyIADs|GetInfo|Description of GetInfo. PyObject *PyIADs::GetInfo(PyObject *self, PyObject *args) { IADs *pIAD = GetI(self); if ( pIAD == NULL ) return NULL; if ( !PyArg_ParseTuple(args, ":GetInfo") ) return NULL; HRESULT hr; PY_INTERFACE_PRECALL; hr = pIAD->GetInfo( ); PY_INTERFACE_POSTCALL; if ( FAILED(hr) ) return PyCom_BuildPyException(hr, pIAD, IID_IADs ); Py_INCREF(Py_None); return Py_None; } // @pymethod |PyIADs|SetInfo|Description of SetInfo. PyObject *PyIADs::SetInfo(PyObject *self, PyObject *args) { IADs *pIAD = GetI(self); if ( pIAD == NULL ) return NULL; if ( !PyArg_ParseTuple(args, ":SetInfo") ) return NULL; HRESULT hr; PY_INTERFACE_PRECALL; hr = pIAD->SetInfo( ); PY_INTERFACE_POSTCALL; if ( FAILED(hr) ) return PyCom_BuildPyException(hr, pIAD, IID_IADs ); Py_INCREF(Py_None); return Py_None; } // @pymethod object|PyIADs|Get|Description of Get. // @rdesc The result is a Python object converted from a COM variant. It // may be an array, or any types supported by COM variant. PyObject *PyIADs::Get(PyObject *self, PyObject *args) { IADs *pIAD = GetI(self); if ( pIAD == NULL ) return NULL; VARIANT val; VariantInit(&val); // @pyparm <o PyUnicode>|prop||The name of the property to fetch PyObject *obbstrName; BSTR bstrName; if ( !PyArg_ParseTuple(args, "O:Get", &obbstrName) ) return NULL; BOOL bPythonIsHappy = TRUE; if (bPythonIsHappy && !PyWinObject_AsBstr(obbstrName, &bstrName)) bPythonIsHappy = FALSE; if (!bPythonIsHappy) return NULL; HRESULT hr; PY_INTERFACE_PRECALL; hr = pIAD->Get( bstrName, &val ); SysFreeString(bstrName); PY_INTERFACE_POSTCALL; if ( FAILED(hr) ) return PyCom_BuildPyException(hr, pIAD, IID_IADs ); PyObject *ret = PyCom_PyObjectFromVariant(&val); { PY_INTERFACE_PRECALL; VariantClear(&val); PY_INTERFACE_POSTCALL; } return ret; } // @pymethod |PyIADs|Put|Description of Put. PyObject *PyIADs::Put(PyObject *self, PyObject *args) { IADs *pIAD = GetI(self); if ( pIAD == NULL ) return NULL; // @pyparm <o PyUnicode>|property||The property name to set // @pyparm object|val||The value to set. PyObject *obbstrName; PyObject *obvProp; BSTR bstrName; VARIANT vProp; VariantInit(&vProp); if ( !PyArg_ParseTuple(args, "OO:Put", &obbstrName, &obvProp) ) return NULL; BOOL bPythonIsHappy = TRUE; if (bPythonIsHappy && !PyWinObject_AsBstr(obbstrName, &bstrName)) bPythonIsHappy = FALSE; if ( !PyCom_VariantFromPyObject(obvProp, &vProp) ) bPythonIsHappy = FALSE; if (!bPythonIsHappy) return NULL; HRESULT hr; PY_INTERFACE_PRECALL; hr = pIAD->Put( bstrName, vProp ); SysFreeString(bstrName); VariantClear(&vProp); PY_INTERFACE_POSTCALL; if ( FAILED(hr) ) return PyCom_BuildPyException(hr, pIAD, IID_IADs ); Py_INCREF(Py_None); return Py_None; } /**** // @pymethod |PyIADs|GetEx|Description of GetEx. PyObject *PyIADs::GetEx(PyObject *self, PyObject *args) { IADs *pIAD = GetI(self); if ( pIAD == NULL ) return NULL; // @pyparm <o unicode>|bstrName||Description for bstrName // *** The input argument pvProp of type "VARIANT *" was not processed *** // Please check the conversion function is appropriate and exists! VARIANT * pvProp; PyObject *obpvProp; // @pyparm <o PyVARIANT *>|pvProp||Description for pvProp PyObject *obbstrName; BSTR bstrName; if ( !PyArg_ParseTuple(args, "OO:GetEx", &obbstrName, &obpvProp) ) return NULL; BOOL bPythonIsHappy = TRUE; if (bPythonIsHappy && !PyWinObject_AsBstr(obbstrName, &bstrName)) bPythonIsHappy = FALSE; if (bPythonIsHappy && !PyObject_AsVARIANT *( obpvProp, &pvProp )) bPythonIsHappy = FALSE; if (!bPythonIsHappy) return NULL; HRESULT hr; PY_INTERFACE_PRECALL; hr = pIAD->GetEx( bstrName, pvProp ); PyObject_FreeVARIANT *(pvProp); PY_INTERFACE_POSTCALL; if ( FAILED(hr) ) return PyCom_BuildPyException(hr, pIAD, IID_IADs ); // *** The output argument pvProp of type "VARIANT *" was not processed *** // The type 'VARIANT *' (pvProp) is unknown. Py_INCREF(Py_None); return Py_None; } // @pymethod |PyIADs|PutEx|Description of PutEx. PyObject *PyIADs::PutEx(PyObject *self, PyObject *args) { IADs *pIAD = GetI(self); if ( pIAD == NULL ) return NULL; // @pyparm int|lnControlCode||Description for lnControlCode // @pyparm <o unicode>|bstrName||Description for bstrName // @pyparm <o PyVARIANT>|vProp||Description for vProp PyObject *obbstrName; PyObject *obvProp; long lnControlCode; BSTR bstrName; VARIANT vProp; if ( !PyArg_ParseTuple(args, "lOO:PutEx", &lnControlCode, &obbstrName, &obvProp) ) return NULL; BOOL bPythonIsHappy = TRUE; if (bPythonIsHappy && !PyWinObject_AsBstr(obbstrName, &bstrName)) bPythonIsHappy = FALSE; if ( !PyCom_VariantFromPyObject(obvProp, &vProp) ) bPythonIsHappy = FALSE; if (!bPythonIsHappy) return NULL; HRESULT hr; PY_INTERFACE_PRECALL; hr = pIAD->PutEx( lnControlCode, bstrName, vProp ); PY_INTERFACE_POSTCALL; if ( FAILED(hr) ) return PyCom_BuildPyException(hr, pIAD, IID_IADs ); Py_INCREF(Py_None); return Py_None; } // @pymethod |PyIADs|GetInfoEx|Description of GetInfoEx. PyObject *PyIADs::GetInfoEx(PyObject *self, PyObject *args) { IADs *pIAD = GetI(self); if ( pIAD == NULL ) return NULL; // @pyparm <o PyVARIANT>|vProperties||Description for vProperties // @pyparm int|lnReserved||Description for lnReserved PyObject *obvProperties; VARIANT vProperties; long lnReserved; if ( !PyArg_ParseTuple(args, "Ol:GetInfoEx", &obvProperties, &lnReserved) ) return NULL; BOOL bPythonIsHappy = TRUE; if ( !PyCom_VariantFromPyObject(obvProperties, &vProperties) ) bPythonIsHappy = FALSE; if (!bPythonIsHappy) return NULL; HRESULT hr; PY_INTERFACE_PRECALL; hr = pIAD->GetInfoEx( vProperties, lnReserved ); PY_INTERFACE_POSTCALL; if ( FAILED(hr) ) return PyCom_BuildPyException(hr, pIAD, IID_IADs ); Py_INCREF(Py_None); return Py_None; } ***/ // @object PyIADs|An object representing the IADs interface. // In most cases you can achieve the same result via IDispatch - however, this // interface allows you get get and set properties without the IDispatch // overhead. static struct PyMethodDef PyIADs_methods[] = { { "GetInfo", PyIADs::GetInfo, 1 }, // @pymeth GetInfo|Description of GetInfo { "SetInfo", PyIADs::SetInfo, 1 }, // @pymeth SetInfo|Description of SetInfo { "Get", PyIADs::Get, 1 }, // @pymeth Get|Description of Get { "Put", PyIADs::Put, 1 }, // @pymeth Put|Description of Put { "get", PyIADs::Get, 1 }, // @pymeth get|Synonym for Get { "put", PyIADs::Put, 1 }, // @pymeth put|Synonym for Put { NULL } }; PyObject* PyIADs_getattro(PyObject *ob, PyObject *obname) { char *name = PyString_AsString(obname); if (!name) return NULL; IADs *p = PyIADs::GetI(ob); // These are all BSTR values BSTR ret = NULL; HRESULT hr; BOOL bad = FALSE; Py_BEGIN_ALLOW_THREADS // docs refer to 'property' as AdsPath, but function is ADsPath // allow both // @prop <o PyUnicode>|ADsPath| // @prop <o PyUnicode>|AdsPath|Synonym for ADsPath if (strcmp(name, "AdsPath")==0 || strcmp(name, "ADsPath")==0) hr = p->get_ADsPath(&ret); // @prop <o PyUnicode>|Class| else if (strcmp(name, "Class")==0) hr = p->get_Class(&ret); // @prop <o PyUnicode>|GUID|Like the IADs method, this returns a string rather than a GUID object. else if (strcmp(name, "GUID")==0) hr = p->get_GUID(&ret); // @prop <o PyUnicode>|Name| else if (strcmp(name, "Name")==0) hr = p->get_Name(&ret); // @prop <o PyUnicode>|Parent| else if (strcmp(name, "Parent")==0) hr = p->get_Parent(&ret); // @prop <o PyUnicode>|Schema| else if (strcmp(name, "Schema")==0) hr = p->get_Schema(&ret); else bad = TRUE; Py_END_ALLOW_THREADS if (bad) return PyIBase::getattro(ob, obname); if (FAILED(hr)) return PyCom_BuildPyException(hr, p, IID_IADs ); PyObject *rc = MakeBstrToObj(ret); SysFreeString(ret); return rc; } PyComTypeObject PyIADs::type("PyIADs", &PyIDispatch::type, sizeof(PyIADs), PyIADs_methods, GET_PYCOM_CTOR(PyIADs)); Index: PyIADsUser.i =================================================================== RCS file: /cvsroot/pywin32/pywin32/com/win32comext/adsi/src/PyIADsUser.i,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** PyIADsUser.i 25 May 2005 01:26:04 -0000 1.2 --- PyIADsUser.i 27 May 2005 07:09:36 -0000 1.3 *************** *** 7,16 **** %{ ! #include "PyIADsUser.h" #define SWIG_THIS_IID IID_IADsUser PyIADsUser::PyIADsUser(IUnknown *pDisp) : ! PyIDispatch(pDisp) { ob_type = &type; --- 7,17 ---- %{ ! #include "PyIADs.h" #include "PyIADsUser.h" + #define SWIG_THIS_IID IID_IADsUser PyIADsUser::PyIADsUser(IUnknown *pDisp) : ! PyIADs(pDisp) { ob_type = &type; *************** *** 23,27 **** IADsUser *PyIADsUser::GetI(PyObject *self) { ! return (IADsUser *)PyIDispatch::GetI(self); } --- 24,38 ---- IADsUser *PyIADsUser::GetI(PyObject *self) { ! return (IADsUser *)PyIADs::GetI(self); ! } ! ! PyObject* PyIADsUser_getattro(PyObject *ob, PyObject *obname) ! { ! char *name = PyString_AsString(obname); ! if (!name) return NULL; ! ! IADsUser *p = PyIADsUser::GetI(ob); ! // todo! ! return PyIADs::getattro(ob, obname); } |
From: Mark H. <mha...@us...> - 2005-05-27 07:09:45
|
Update of /cvsroot/pywin32/pywin32 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5722 Modified Files: setup.py Log Message: * Add IADs and IADsDeleteOps Index: setup.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/setup.py,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** setup.py 26 May 2005 11:41:03 -0000 1.9 --- setup.py 27 May 2005 07:09:35 -0000 1.10 *************** *** 917,920 **** --- 917,921 ---- %(adsi)s/PyIADsContainer.i %(adsi)s/PyIADsContainer.cpp %(adsi)s/PyIADsUser.i %(adsi)s/PyIADsUser.cpp + %(adsi)s/PyIADsDeleteOps.i %(adsi)s/PyIADsDeleteOps.cpp %(adsi)s/PyIDirectoryObject.i %(adsi)s/PyIDirectoryObject.cpp %(adsi)s/PyIDirectorySearch.i %(adsi)s/PyIDirectorySearch.cpp *************** *** 922,926 **** %(adsi)s/adsilib.i ! %(adsi)s/PyADSIUtil.cpp %(adsi)s/PyDSOPObjects.cpp """ % dirs).split()), WinExt_win32com('axcontrol', pch_header="axcontrol_pch.h"), --- 923,928 ---- %(adsi)s/adsilib.i ! %(adsi)s/PyADSIUtil.cpp %(adsi)s/PyDSOPObjects.cpp ! %(adsi)s/PyIADs.cpp """ % dirs).split()), WinExt_win32com('axcontrol', pch_header="axcontrol_pch.h"), *************** *** 1013,1020 **** 'adsi': None, # module 'PyIADsContainer': 'IDispatch', ! 'PyIADsUser': 'IDispatch', 'PyIDirectoryObject': '', 'PyIDirectorySearch': '', 'PyIDsObjectPicker': '', } --- 1015,1024 ---- 'adsi': None, # module 'PyIADsContainer': 'IDispatch', ! 'PyIADsDeleteOps': 'IDispatch', ! 'PyIADsUser': 'IADs', 'PyIDirectoryObject': '', 'PyIDirectorySearch': '', 'PyIDsObjectPicker': '', + 'PyIADs': 'IDispatch', } |
From: Mark H. <mha...@us...> - 2005-05-27 07:08:41
|
Update of /cvsroot/pywin32/pywin32/com/win32comext/adsi In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5493 Modified Files: __init__.py Log Message: * Give the Dispatch wrapper better names for wrapped objects. * If an attribute with value None exists on the base object, let that past. Index: __init__.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/com/win32comext/adsi/__init__.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** __init__.py 5 May 2000 00:42:00 -0000 1.1 --- __init__.py 27 May 2005 07:08:30 -0000 1.2 *************** *** 37,41 **** if hasattr(ob, "Invoke"): import win32com.client.dynamic ! return win32com.client.dynamic.Dispatch(ob, "ADSI_object", ADSIDispatch) return ob --- 37,42 ---- if hasattr(ob, "Invoke"): import win32com.client.dynamic ! name = "Dispatch wrapper around %r" % ob ! return win32com.client.dynamic.Dispatch(ob, name, ADSIDispatch) return ob *************** *** 80,87 **** def __getattr__(self, attr): ! ret = getattr(self._oleobj_, attr, None) ! if ret is None: ! ret = win32com.client.CDispatch.__getattr__(self, attr) ! return ret def QueryInterface(self, iid): ret = self._oleobj_.QueryInterface(iid) --- 81,89 ---- def __getattr__(self, attr): ! try: ! return getattr(self._oleobj_, attr) ! except AttributeError: ! return win32com.client.CDispatch.__getattr__(self, attr) ! def QueryInterface(self, iid): ret = self._oleobj_.QueryInterface(iid) |
From: Mark H. <mha...@us...> - 2005-05-26 11:41:52
|
Update of /cvsroot/pywin32/pywin32/AutoDuck In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26849 Modified Files: pywin32.mak Log Message: New adsi files, and correct existing adsi doc generation. Index: pywin32.mak =================================================================== RCS file: /cvsroot/pywin32/pywin32/AutoDuck/pywin32.mak,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** pywin32.mak 24 May 2005 14:10:41 -0000 1.12 --- pywin32.mak 26 May 2005 11:41:43 -0000 1.13 *************** *** 78,85 **** --- 78,87 ---- $(GENDIR)\exchdapi.d \ $(ADSI_DIR)\src\*.cpp \ + $(GENDIR)\adsi.d \ $(GENDIR)\PyIADsContainer.d \ $(GENDIR)\PyIADsUser.d \ $(GENDIR)\PyIDirectoryObject.d \ $(GENDIR)\PyIDirectorySearch.d \ + $(GENDIR)\PyIDsObjectPicker.d \ PYTHONWIN_SOURCE = \ *************** *** 223,237 **** $(GENDIR)\PyIADsContainer.d: $(ADSI_DIR)/src/$(*B).i ! $(PYTHON) makedfromi.py -o$*.d $(ADSI_DIR)/src/$(*B).i $(GENDIR)\PyIADsUser.d: $(ADSI_DIR)/src/$(*B).i ! $(PYTHON) makedfromi.py -o$*.d $(ADSI_DIR)/src/$(*B).i $(GENDIR)\PyIDirectoryObject.d: $(ADSI_DIR)/src/$(*B).i ! $(PYTHON) makedfromi.py -o$*.d $(ADSI_DIR)/src/$(*B).i $(GENDIR)\PyIDirectorySearch.d: $(ADSI_DIR)/src/$(*B).i ! $(PYTHON) makedfromi.py -o$*.d $(ADSI_DIR)/src/$(*B).i !include "common.mak" --- 225,241 ---- $(GENDIR)\PyIADsContainer.d: $(ADSI_DIR)/src/$(*B).i ! $(PYTHON) makedfromi.py -o$*.d -p PyIUnknown $(ADSI_DIR)/src/$(*B).i $(GENDIR)\PyIADsUser.d: $(ADSI_DIR)/src/$(*B).i ! $(PYTHON) makedfromi.py -o$*.d -p PyIDispatch $(ADSI_DIR)/src/$(*B).i $(GENDIR)\PyIDirectoryObject.d: $(ADSI_DIR)/src/$(*B).i ! $(PYTHON) makedfromi.py -o$*.d -p PyIUnknown $(ADSI_DIR)/src/$(*B).i $(GENDIR)\PyIDirectorySearch.d: $(ADSI_DIR)/src/$(*B).i ! $(PYTHON) makedfromi.py -o$*.d -p PyIUnknown $(ADSI_DIR)/src/$(*B).i + $(GENDIR)\PyIDsObjectPicker.d: $(ADSI_DIR)/src/$(*B).i + $(PYTHON) makedfromi.py -o$*.d -p PyIUnknown $(ADSI_DIR)/src/$(*B).i !include "common.mak" |
From: Mark H. <mha...@us...> - 2005-05-26 11:41:13
|
Update of /cvsroot/pywin32/pywin32 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26664 Modified Files: setup.py Log Message: New files in adsi project, and move this to explicit specification of 'sources' while at it. A few other minor fixups of recent 'source' changes. Index: setup.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/setup.py,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** setup.py 24 May 2005 13:55:28 -0000 1.8 --- setup.py 26 May 2005 11:41:03 -0000 1.9 *************** *** 182,191 **** decorated.sort() result = [item[1] for item in decorated] - return result class WinExt_pythonwin(WinExt): def __init__ (self, name, **kw): ! if not kw.has_key("dsp_file"): kw["dsp_file"] = "pythonwin/" + name + ".dsp" kw.setdefault("extra_compile_args", []).extend( --- 182,190 ---- decorated.sort() result = [item[1] for item in decorated] return result class WinExt_pythonwin(WinExt): def __init__ (self, name, **kw): ! if not kw.has_key("dsp_file") and not kw.get("sources"): kw["dsp_file"] = "pythonwin/" + name + ".dsp" kw.setdefault("extra_compile_args", []).extend( *************** *** 211,215 **** class WinExt_win32com(WinExt): def __init__ (self, name, **kw): ! if not kw.has_key("dsp_file"): kw["dsp_file"] = "com/" + name + ".dsp" kw["libraries"] = kw.get("libraries", "") + " oleaut32 ole32" --- 210,214 ---- class WinExt_win32com(WinExt): def __init__ (self, name, **kw): ! if not kw.has_key("dsp_file") and not kw.get("sources"): kw["dsp_file"] = "com/" + name + ".dsp" kw["libraries"] = kw.get("libraries", "") + " oleaut32 ole32" *************** *** 865,868 **** --- 864,871 ---- win32_extensions += [ WinExt_win32("win32gui", + sources = """ + win32/src/win32dynamicdialog.cpp + win32/src/win32gui.i win32/src/win32guimodule.cpp + """.split(), libraries="gdi32 user32 comdlg32 comctl32 shell32", define_macros = [("WIN32GUI", None)], *************** *** 871,876 **** # including windows.h. It also has an XP style manifest. WinExt_win32("winxpgui", ! sources = ["win32/src/winxpgui.rc"], ! dsp_file = "win32/win32gui.dsp", libraries="gdi32 user32 comdlg32 comctl32 shell32", define_macros = [("WIN32GUI",None), ("WINXPGUI",None)], --- 874,881 ---- # including windows.h. It also has an XP style manifest. WinExt_win32("winxpgui", ! sources = """ ! win32/src/winxpgui.rc win32/src/win32dynamicdialog.cpp ! win32/src/win32gui.i win32/src/win32guimodule.cpp ! """.split(), libraries="gdi32 user32 comdlg32 comctl32 shell32", define_macros = [("WIN32GUI",None), ("WINXPGUI",None)], *************** *** 880,884 **** WinExt_win32("_winxptheme", sources = ["win32/src/_winxptheme.i", "win32/src/_winxpthememodule.cpp"], - dsp_file = None, libraries="gdi32 user32 comdlg32 comctl32 shell32 Uxtheme", windows_h_version=0x0500, --- 885,888 ---- *************** *** 893,896 **** --- 897,904 ---- ] + dirs = { + 'adsi' : 'com/win32comext/adsi/src', + } + # The COM modules. pythoncom = WinExt_system32('pythoncom', *************** *** 904,908 **** com_extensions = [pythoncom] com_extensions += [ ! WinExt_win32com('adsi', libraries="ACTIVEDS ADSIID"), WinExt_win32com('axcontrol', pch_header="axcontrol_pch.h"), WinExt_win32com('axscript', --- 912,927 ---- com_extensions = [pythoncom] com_extensions += [ ! WinExt_win32com('adsi', libraries="ACTIVEDS ADSIID", ! sources=(""" ! %(adsi)s/adsi.i %(adsi)s/adsi.cpp ! %(adsi)s/PyIADsContainer.i %(adsi)s/PyIADsContainer.cpp ! %(adsi)s/PyIADsUser.i %(adsi)s/PyIADsUser.cpp ! %(adsi)s/PyIDirectoryObject.i %(adsi)s/PyIDirectoryObject.cpp ! %(adsi)s/PyIDirectorySearch.i %(adsi)s/PyIDirectorySearch.cpp ! %(adsi)s/PyIDsObjectPicker.i %(adsi)s/PyIDsObjectPicker.cpp ! ! %(adsi)s/adsilib.i ! %(adsi)s/PyADSIUtil.cpp %(adsi)s/PyDSOPObjects.cpp ! """ % dirs).split()), WinExt_win32com('axcontrol', pch_header="axcontrol_pch.h"), WinExt_win32com('axscript', *************** *** 997,1000 **** --- 1016,1020 ---- 'PyIDirectoryObject': '', 'PyIDirectorySearch': '', + 'PyIDsObjectPicker': '', } |
From: Mark H. <mha...@us...> - 2005-05-26 11:39:57
|
Update of /cvsroot/pywin32/pywin32/com/win32comext/adsi In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26331 Modified Files: adsicon.py Log Message: Add support for IDsObjectPicker Index: adsicon.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/com/win32comext/adsi/adsicon.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** adsicon.py 20 May 2005 23:23:31 -0000 1.2 --- adsicon.py 26 May 2005 11:39:17 -0000 1.3 *************** *** 277,278 **** --- 277,336 ---- ADS_CHASE_REFERRALS_EXTERNAL = 0x40 ADS_CHASE_REFERRALS_ALWAYS = ADS_CHASE_REFERRALS_SUBORDINATE | ADS_CHASE_REFERRALS_EXTERNAL + + # Generated by h2py from ObjSel.h + DSOP_SCOPE_TYPE_TARGET_COMPUTER = 0x00000001 + DSOP_SCOPE_TYPE_UPLEVEL_JOINED_DOMAIN = 0x00000002 + DSOP_SCOPE_TYPE_DOWNLEVEL_JOINED_DOMAIN = 0x00000004 + DSOP_SCOPE_TYPE_ENTERPRISE_DOMAIN = 0x00000008 + DSOP_SCOPE_TYPE_GLOBAL_CATALOG = 0x00000010 + DSOP_SCOPE_TYPE_EXTERNAL_UPLEVEL_DOMAIN = 0x00000020 + DSOP_SCOPE_TYPE_EXTERNAL_DOWNLEVEL_DOMAIN = 0x00000040 + DSOP_SCOPE_TYPE_WORKGROUP = 0x00000080 + DSOP_SCOPE_TYPE_USER_ENTERED_UPLEVEL_SCOPE = 0x00000100 + DSOP_SCOPE_TYPE_USER_ENTERED_DOWNLEVEL_SCOPE = 0x00000200 + DSOP_SCOPE_FLAG_STARTING_SCOPE = 0x00000001 + DSOP_SCOPE_FLAG_WANT_PROVIDER_WINNT = 0x00000002 + DSOP_SCOPE_FLAG_WANT_PROVIDER_LDAP = 0x00000004 + DSOP_SCOPE_FLAG_WANT_PROVIDER_GC = 0x00000008 + DSOP_SCOPE_FLAG_WANT_SID_PATH = 0x00000010 + DSOP_SCOPE_FLAG_WANT_DOWNLEVEL_BUILTIN_PATH = 0x00000020 + DSOP_SCOPE_FLAG_DEFAULT_FILTER_USERS = 0x00000040 + DSOP_SCOPE_FLAG_DEFAULT_FILTER_GROUPS = 0x00000080 + DSOP_SCOPE_FLAG_DEFAULT_FILTER_COMPUTERS = 0x00000100 + DSOP_SCOPE_FLAG_DEFAULT_FILTER_CONTACTS = 0x00000200 + DSOP_FILTER_INCLUDE_ADVANCED_VIEW = 0x00000001 + DSOP_FILTER_USERS = 0x00000002 + DSOP_FILTER_BUILTIN_GROUPS = 0x00000004 + DSOP_FILTER_WELL_KNOWN_PRINCIPALS = 0x00000008 + DSOP_FILTER_UNIVERSAL_GROUPS_DL = 0x00000010 + DSOP_FILTER_UNIVERSAL_GROUPS_SE = 0x00000020 + DSOP_FILTER_GLOBAL_GROUPS_DL = 0x00000040 + DSOP_FILTER_GLOBAL_GROUPS_SE = 0x00000080 + DSOP_FILTER_DOMAIN_LOCAL_GROUPS_DL = 0x00000100 + DSOP_FILTER_DOMAIN_LOCAL_GROUPS_SE = 0x00000200 + DSOP_FILTER_CONTACTS = 0x00000400 + DSOP_FILTER_COMPUTERS = 0x00000800 + DSOP_DOWNLEVEL_FILTER_USERS = (-2147483647) + DSOP_DOWNLEVEL_FILTER_LOCAL_GROUPS = (-2147483646) + DSOP_DOWNLEVEL_FILTER_GLOBAL_GROUPS = (-2147483644) + DSOP_DOWNLEVEL_FILTER_COMPUTERS = (-2147483640) + DSOP_DOWNLEVEL_FILTER_WORLD = (-2147483632) + DSOP_DOWNLEVEL_FILTER_AUTHENTICATED_USER = (-2147483616) + DSOP_DOWNLEVEL_FILTER_ANONYMOUS = (-2147483584) + DSOP_DOWNLEVEL_FILTER_BATCH = (-2147483520) + DSOP_DOWNLEVEL_FILTER_CREATOR_OWNER = (-2147483392) + DSOP_DOWNLEVEL_FILTER_CREATOR_GROUP = (-2147483136) + DSOP_DOWNLEVEL_FILTER_DIALUP = (-2147482624) + DSOP_DOWNLEVEL_FILTER_INTERACTIVE = (-2147481600) + DSOP_DOWNLEVEL_FILTER_NETWORK = (-2147479552) + DSOP_DOWNLEVEL_FILTER_SERVICE = (-2147475456) + DSOP_DOWNLEVEL_FILTER_SYSTEM = (-2147467264) + DSOP_DOWNLEVEL_FILTER_EXCLUDE_BUILTIN_GROUPS = (-2147450880) + DSOP_DOWNLEVEL_FILTER_TERMINAL_SERVER = (-2147418112) + DSOP_DOWNLEVEL_FILTER_ALL_WELLKNOWN_SIDS = (-2147352576) + DSOP_DOWNLEVEL_FILTER_LOCAL_SERVICE = (-2147221504) + DSOP_DOWNLEVEL_FILTER_NETWORK_SERVICE = (-2146959360) + DSOP_DOWNLEVEL_FILTER_REMOTE_LOGON = (-2146435072) + DSOP_FLAG_MULTISELECT = 0x00000001 + DSOP_FLAG_SKIP_TARGET_COMPUTER_DC_CHECK = 0x00000002 + CFSTR_DSOP_DS_SELECTION_LIST = "CFSTR_DSOP_DS_SELECTION_LIST" |
From: Mark H. <mha...@us...> - 2005-05-26 11:39:44
|
Update of /cvsroot/pywin32/pywin32/com/win32comext/adsi/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26331/src Modified Files: adsi.i Added Files: PyDSOPObjects.cpp PyIDsObjectPicker.i Log Message: Add support for IDsObjectPicker Index: adsi.i =================================================================== RCS file: /cvsroot/pywin32/pywin32/com/win32comext/adsi/src/adsi.i,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** adsi.i 24 Sep 2004 07:25:12 -0000 1.4 --- adsi.i 26 May 2005 11:39:30 -0000 1.5 *************** *** 24,27 **** --- 24,28 ---- %{ + #include "objsel.h" #include "PyIEnumVARIANT.h" #include "PythonCOMServer.h" *************** *** 31,35 **** --- 32,40 ---- #include "PyIADsContainer.h" #include "PyIADsUser.h" + #include "PyIDsObjectPicker.h" #include "ADSIID.h" + + extern PyTypeObject PyDSOP_SCOPE_INIT_INFOsType; + %} *************** *** 221,227 **** --- 226,244 ---- %native (ADsEnumerateNext) PyADsEnumerateNext; + + %{ + // @pyswig <o PyDS_SELECTION_LIST>|StringAsDS_SELECTION_LIST|Unpacks a string (generally fetched via <om PyIDataObject.GetData>) into a <o PyDS_SELECTION_LIST> list. + // @pyparm str|buf||The raw buffer + extern PyObject *PyStringAsDS_SELECTION_LIST(PyObject *self, PyObject *args); + %} + %native (StringAsDS_SELECTION_LIST) PyStringAsDS_SELECTION_LIST; + %init %{ PyDict_SetItemString(d, "error", PyWinExc_COMError); + // @pyswig <o DSOP_SCOPE_INIT_INFOs>|DSOP_SCOPE_INIT_INFOs|The type object for <o PyDSOP_SCOPE_INIT_INFOs> objects. + // @pyparm int|size||The number of <o PyDSOP_SCOPE_INIT_INFO> objects to create in the array. + PyDict_SetItemString(d, "DSOP_SCOPE_INIT_INFOs", (PyObject *)&PyDSOP_SCOPE_INIT_INFOsType); + AddIID(d, "LIBID_ADs", LIBID_ADs); *************** *** 262,266 **** ADD_IID(CLSID_AccessControlList); ADD_IID(CLSID_SecurityDescriptor); ! // ADD_IID(IID_IDirectoryAttrMgmt); --- 279,283 ---- ADD_IID(CLSID_AccessControlList); ADD_IID(CLSID_SecurityDescriptor); ! ADD_IID(CLSID_DsObjectPicker); // ADD_IID(IID_IDirectoryAttrMgmt); *************** *** 280,282 **** --- 297,302 ---- if ( PyCom_RegisterClientType(&PyIADsContainer::type, &IID_IADsContainer) != 0 ) return; ADD_IID(IID_IADsContainer); + + if ( PyCom_RegisterClientType(&PyIDsObjectPicker::type, &IID_IDsObjectPicker) != 0 ) return; + ADD_IID(IID_IDsObjectPicker); %} --- NEW FILE: PyIDsObjectPicker.i --- %module IDsObjectPicker // A COM interface to ADSI's IDsObjectPicker interface. %include "typemaps.i" %include "pywin32.i" %include "pythoncom.i" %include "adsilib.i" %apply HWND {long}; typedef long HWND %{ #include "Objsel.h" #include "PyIDsObjectPicker.h" extern BOOL PyObject_AsDSOP_SCOPE_INIT_INFOs(PyObject *ob, DSOP_SCOPE_INIT_INFO**p, ULONG *n); static void PyWinObject_FreeWCHARArray(LPWSTR *wchars, DWORD str_cnt) { if (wchars!=NULL){ for (DWORD wchar_index=0; wchar_index<str_cnt; wchar_index++) PyWinObject_FreeWCHAR(wchars[wchar_index]); free(wchars); } } static BOOL PyWinObject_AsWCHARArray(PyObject *str_seq, LPWSTR **wchars, DWORD *str_cnt, BOOL bNoneOK = FALSE) { if (bNoneOK && str_seq==Py_None) { *wchars = NULL; *str_cnt = 0; return TRUE; } BOOL ret=FALSE; PyObject *str_tuple=NULL, *tuple_item; DWORD bufsize, tuple_index; *wchars=NULL; *str_cnt=0; if ((str_tuple=PySequence_Tuple(str_seq))==NULL) return FALSE; *str_cnt=PyTuple_Size(str_tuple); bufsize=*str_cnt * sizeof(LPWSTR); *wchars=(LPWSTR *)malloc(bufsize); if (*wchars==NULL){ PyErr_Format(PyExc_MemoryError, "Unable to allocate %d bytes", bufsize); goto done; } ZeroMemory(*wchars, bufsize); for (tuple_index=0;tuple_index<*str_cnt;tuple_index++){ tuple_item=PyTuple_GET_ITEM(str_tuple, tuple_index); if (!PyWinObject_AsWCHAR(tuple_item, &((*wchars)[tuple_index]), FALSE)){ PyWinObject_FreeWCHARArray(*wchars, *str_cnt); *wchars=NULL; *str_cnt=0; goto done; } } ret=TRUE; done: Py_XDECREF(str_tuple); return ret; } #define SWIG_THIS_IID IID_IDsObjectPicker PyIDsObjectPicker::PyIDsObjectPicker(IUnknown *pDisp) : PyIUnknown(pDisp) { ob_type = &type; } PyIDsObjectPicker::~PyIDsObjectPicker() { } IDsObjectPicker *PyIDsObjectPicker::GetI(PyObject *self) { return (IDsObjectPicker *)PyIUnknown::GetI(self); } // @pyswig |Initialize|Initializes the IDsObjectPicker interface with information about the scopes, filters, and options used by the object picker dialog box. PyObject *PyIDsObjectPicker::Initialize(PyObject *self, PyObject *args) { HRESULT hr; PyObject *ret; PyObject *obTargetComputer; PyObject *obScopeInfos; IDsObjectPicker *_swig_self; if ((_swig_self=GetI(self))==NULL) return NULL; PyObject *obAttributeNames = Py_None; DSOP_INIT_INFO ii; memset(&ii, sizeof(ii), 0); ii.cbSize = sizeof(ii); if (!PyArg_ParseTuple(args, "OO|lO:Initialize", &obTargetComputer, // @pyparm <o PyUnicode>|targetComputer|| &obScopeInfos, // @pyparm <o PyDSOP_SCOPE_INIT_INFOs>|scopeInfos|| &ii.flOptions, // @pyparm int|options|0| &obAttributeNames)) // @pyparm [<o PyUnicode>, ...]|attrNames|None| return NULL; if (!PyWinObject_AsWCHAR(obTargetComputer, (WCHAR **)&ii.pwzTargetComputer, TRUE)) goto done; if (!PyObject_AsDSOP_SCOPE_INIT_INFOs(obScopeInfos, &ii.aDsScopeInfos, &ii.cDsScopeInfos)) goto done; if (!PyWinObject_AsWCHARArray(obAttributeNames, (WCHAR ***)&ii.apwzAttributeNames, &ii.cAttributesToFetch, TRUE)) goto done; Py_BEGIN_ALLOW_THREADS hr = _swig_self->Initialize(&ii); Py_END_ALLOW_THREADS if (FAILED(hr)) PyCom_BuildPyException(hr, _swig_self, IID_IDsObjectPicker); else { ret = Py_None; Py_INCREF(ret); } done: PyWinObject_FreeWCHAR((WCHAR *)ii.pwzTargetComputer); PyWinObject_FreeWCHARArray((WCHAR **)ii.apwzAttributeNames, ii.cAttributesToFetch); return ret; } %} %native(Initialize) Initialize; %typemap(python,ignore) IDataObject **OUTPUT(IDataObject *temp) { $target = &temp; } %typemap(python,argout) IDataObject **OUTPUT { MAKE_OUTPUT_INTERFACE($source, $target, IID_IDataObject) } // @pyswig <o PyIDataObject>|InvokeDialog|Displays a modal object picker dialog box and returns the user's selections. // @pyparm int|hwnd|| HRESULT InvokeDialog(HWND hwnd, IDataObject **OUTPUT); --- NEW FILE: PyDSOPObjects.cpp --- // Directory Service Object Picker objects. // @doc #define UNICODE #define _UNICODE #include "PyWinTypes.h" #include "PythonCOM.h" #include "Objsel.h" // DS_SELECTION_LIST helpers PyObject *PyStringAsDS_SELECTION_LIST(PyObject *self, PyObject *args) { char *sz; unsigned int cb; if (!PyArg_ParseTuple(args, "s#:PyStringAsDS_SELECTION_LIST", &sz, &cb)) return NULL; if (cb < sizeof(DS_SELECTION_LIST)) return PyErr_Format(PyExc_ValueError, "String must be at least %d bytes (got %d)", sizeof(DS_SELECTION_LIST), cb); DS_SELECTION_LIST *pSL = (DS_SELECTION_LIST *)sz; PyObject *ret = PyList_New(pSL->cItems); if (!ret) return NULL; for (unsigned int i=0;i<pSL->cItems;i++) { // get attrs for this item DS_SELECTION *pItem = pSL->aDsSelection+i; PyObject *obAttr; if (pItem->pvarFetchedAttributes) { obAttr = PyList_New(pSL->cFetchedAttributes); if (!obAttr) { Py_DECREF(ret); return NULL; } for (unsigned int ia=0;ia<pSL->cFetchedAttributes;ia++) PyList_SET_ITEM(obAttr, ia, PyCom_PyObjectFromVariant(pItem->pvarFetchedAttributes+ia)); } else { obAttr = Py_None; Py_INCREF(Py_None); } PyObject *sub = Py_BuildValue("NNNNNl", PyWinObject_FromWCHAR(pItem->pwzName), PyWinObject_FromWCHAR(pItem->pwzADsPath), PyWinObject_FromWCHAR(pItem->pwzClass), PyWinObject_FromWCHAR(pItem->pwzUPN), obAttr, pItem->flScopeType); if (!sub) { Py_DECREF(ret); return NULL; } PyList_SET_ITEM(ret, i, sub); } return ret; } class PyDSOP_SCOPE_INIT_INFOs : public PyObject { public: PyDSOP_SCOPE_INIT_INFOs(DSOP_SCOPE_INIT_INFO *_scopes, int _count); PyDSOP_SCOPE_INIT_INFOs(); ~PyDSOP_SCOPE_INIT_INFOs(); static void deallocFunc(PyObject *ob); static PyObject *tp_new(PyTypeObject *, PyObject *, PyObject *); static PySequenceMethods sequencemethods; DSOP_SCOPE_INIT_INFO *pScopes; int count; }; class PyDSOP_SCOPE_INIT_INFO : public PyObject { public: PyDSOP_SCOPE_INIT_INFO(PyDSOP_SCOPE_INIT_INFOs *owner, int index); ~PyDSOP_SCOPE_INIT_INFO(); static void deallocFunc(PyObject *ob); static PyObject *getattro(PyObject *self, PyObject *name); static int setattro(PyObject *self, PyObject *obname, PyObject *obvalue); public: PyDSOP_SCOPE_INIT_INFOs *owner; int index; // my pos in the owner's array }; class PyDSOP_FILTER_FLAGS : public PyObject { public: PyDSOP_FILTER_FLAGS(PyDSOP_SCOPE_INIT_INFO *owner); ~PyDSOP_FILTER_FLAGS(); static void deallocFunc(PyObject *ob); static PyObject *getattro(PyObject *self, PyObject *name); static int setattro(PyObject *self, PyObject *obname, PyObject *obvalue); protected: PyDSOP_SCOPE_INIT_INFO *owner; }; class PyDSOP_UPLEVEL_FILTER_FLAGS : public PyObject { public: PyDSOP_UPLEVEL_FILTER_FLAGS( PyDSOP_SCOPE_INIT_INFO *owner); ~PyDSOP_UPLEVEL_FILTER_FLAGS(); static void deallocFunc(PyObject *ob); static PyObject *getattro(PyObject *self, PyObject *name); static int setattro(PyObject *self, PyObject *obname, PyObject *obvalue); protected: PyDSOP_SCOPE_INIT_INFO *owner; }; //////////////////////////////////////////////////////////////////////////// // PyDSOP_SCOPE_INIT_INFOs //////////////////////////////////////////////////////////////////////////// // @object PyDSOP_SCOPE_INIT_INFOs|An object representing an array of <o PyDSOP_SCOPE_INIT_INFO> objects // @comm You must pass the number of items in the array to the constructor. // Once set, this can not be changed. You can index the index (eg, ob[2]). The // object has no other (interesting) methods or attributes. // <nl>These objects are created via <om adsi.DSOP_SCOPE_INIT_INFOs>(size) int PyDSOP_SCOPE_INIT_INFOs_sq_length(PyObject *self) { PyDSOP_SCOPE_INIT_INFOs *p = (PyDSOP_SCOPE_INIT_INFOs *)self; return p->count; } PyObject *PyDSOP_SCOPE_INIT_INFOs_sq_item(PyObject *self, int i) { PyDSOP_SCOPE_INIT_INFOs *p =(PyDSOP_SCOPE_INIT_INFOs *)self; if (i>=p->count){ PyErr_SetString(PyExc_IndexError,"Index specified larger than number of allocated buffers"); return NULL; } return new PyDSOP_SCOPE_INIT_INFO(p, i); } PySequenceMethods PyDSOP_SCOPE_INIT_INFOs_sequencemethods= { PyDSOP_SCOPE_INIT_INFOs_sq_length, // inquiry sq_length; NULL, // binaryfunc sq_concat; NULL, // intargfunc sq_repeat; PyDSOP_SCOPE_INIT_INFOs_sq_item, // intargfunc sq_item; NULL, // intintargfunc sq_slice; NULL, // intobjargproc sq_ass_item;; NULL, // intintobjargproc sq_ass_slice; NULL, // objobjproc sq_contains; NULL, // binaryfunc sq_inplace_concat; NULL // intargfunc sq_inplace_repeat; }; PyTypeObject PyDSOP_SCOPE_INIT_INFOsType = { PyObject_HEAD_INIT(&PyType_Type) 0, "PyDSOP_SCOPE_INIT_INFOs", sizeof(PyDSOP_SCOPE_INIT_INFOs), 0, PyDSOP_SCOPE_INIT_INFOs::deallocFunc, // tp_dealloc 0, // tp_print 0, // tp_getattr 0, // tp_setattr 0, // tp_compare 0, // tp_repr 0, // PyNumberMethods *tp_as_number &PyDSOP_SCOPE_INIT_INFOs_sequencemethods, // PySequenceMethods *tp_as_sequence 0, // PyMappingMethods *tp_as_mapping 0, // hashfunc tp_hash 0, // tp_call 0, // tp_str PyObject_GenericGetAttr, // tp_getattro PyObject_GenericSetAttr, // tp_setattro 0, // PyBufferProcs *tp_as_buffer Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, // tp_flags 0, // tp_doc 0, // traverseproc tp_traverse 0, // tp_clear 0, // richcmpfunc tp_richcompare 0, // tp_weaklistoffset 0, // getiterfunc tp_iter 0, // iternextfunc tp_iternext 0, // methods 0, // members 0, // tp_getset; 0, // tp_base; 0, // tp_dict; 0, // tp_descr_get 0, // tp_descr_set 0, // tp_dictoffset 0, // tp_init 0, // tp_alloc PyDSOP_SCOPE_INIT_INFOs::tp_new, // newfunc tp_new; }; PyDSOP_SCOPE_INIT_INFOs::PyDSOP_SCOPE_INIT_INFOs(DSOP_SCOPE_INIT_INFO *_scopes, int _count) { ob_type = &PyDSOP_SCOPE_INIT_INFOsType; pScopes = _scopes; count = _count; memset(pScopes, 0, sizeof(DSOP_SCOPE_INIT_INFO) * count); for (int i=0;i<count;i++) pScopes[i].cbSize = sizeof(DSOP_SCOPE_INIT_INFO); _Py_NewReference(this); } PyDSOP_SCOPE_INIT_INFOs::~PyDSOP_SCOPE_INIT_INFOs() { for (int i=0;i<count;i++) // Need to cast away the const of pwzDcName PyWinObject_FreeWCHAR((WCHAR *)pScopes[i].pwzDcName); free(pScopes); } void PyDSOP_SCOPE_INIT_INFOs::deallocFunc(PyObject *ob) { delete (PyDSOP_SCOPE_INIT_INFOs *)ob; } PyObject *PyDSOP_SCOPE_INIT_INFOs::tp_new(PyTypeObject *typ, PyObject *args, PyObject *kwargs) { int count; if (!PyArg_ParseTuple(args, "i", &count)) return NULL; DSOP_SCOPE_INIT_INFO *p = (DSOP_SCOPE_INIT_INFO *)malloc(sizeof(DSOP_SCOPE_INIT_INFO) * count); if (!p) return PyErr_NoMemory(); return new PyDSOP_SCOPE_INIT_INFOs(p, count); } BOOL PyObject_AsDSOP_SCOPE_INIT_INFOs(PyObject *ob, DSOP_SCOPE_INIT_INFO**p, ULONG *n) { if (ob->ob_type != &PyDSOP_SCOPE_INIT_INFOsType) { PyErr_Format(PyExc_TypeError, "Expected DSOP_SCOPE_INIT_INFOs (got %s)", ob->ob_type->tp_name); return FALSE; } PyDSOP_SCOPE_INIT_INFOs *psii = (PyDSOP_SCOPE_INIT_INFOs *)ob; *p = psii->pScopes; *n = psii->count; return TRUE; } //////////////////////////////////////////////////////////////////////////// // PyDSOP_SCOPE_INIT_INFO //////////////////////////////////////////////////////////////////////////// // @object PyDSOP_SCOPE_INIT_INFO|An object representing an ActiveDirectory // DSOP_SCOPE_INIT_INFO structure. // <nl>These objects can only be accessed by indexing a <o PyDSOP_SCOPE_INIT_INFOs> object. PyTypeObject PyDSOP_SCOPE_INIT_INFOType = { PyObject_HEAD_INIT(&PyType_Type) 0, "PyDSOP_SCOPE_INIT_INFO", sizeof(PyDSOP_SCOPE_INIT_INFO), 0, PyDSOP_SCOPE_INIT_INFO::deallocFunc, // tp_dealloc 0, // tp_print 0, // tp_getattr 0, // tp_setattr 0, // tp_compare 0, // tp_repr 0, // PyNumberMethods *tp_as_number 0, // PySequenceMethods *tp_as_sequence 0, // PyMappingMethods *tp_as_mapping 0, // hashfunc tp_hash 0, // tp_call 0, // tp_str PyDSOP_SCOPE_INIT_INFO::getattro, // tp_getattro PyDSOP_SCOPE_INIT_INFO::setattro, // tp_setattro 0, // PyBufferProcs *tp_as_buffer Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, // tp_flags 0, // tp_doc 0, // traverseproc tp_traverse 0, // tp_clear 0, // richcmpfunc tp_richcompare 0, // tp_weaklistoffset 0, // getiterfunc tp_iter 0, // iternextfunc tp_iternext 0, // methods 0, // members 0, // tp_getset; 0, // tp_base; 0, // tp_dict; 0, // tp_descr_get 0, // tp_descr_set 0, // tp_dictoffset 0, // tp_init 0, // tp_alloc 0, // newfunc tp_new; }; PyDSOP_SCOPE_INIT_INFO::PyDSOP_SCOPE_INIT_INFO(PyDSOP_SCOPE_INIT_INFOs *_owner, int _index) { ob_type = &PyDSOP_SCOPE_INIT_INFOType; owner = _owner; index = _index; Py_INCREF(owner); _Py_NewReference(this); } PyDSOP_SCOPE_INIT_INFO::~PyDSOP_SCOPE_INIT_INFO() { Py_DECREF(owner); } PyObject * PyDSOP_SCOPE_INIT_INFO::getattro(PyObject *self, PyObject *obname) { PyDSOP_SCOPE_INIT_INFO *p = (PyDSOP_SCOPE_INIT_INFO *)self; DSOP_SCOPE_INIT_INFO *pssi = p->owner->pScopes + p->index; char *name=PyString_AsString(obname); if (!name) return NULL; // @prop int|type| if (strcmp(name, "type")==0) return PyInt_FromLong(pssi->flType); // @prop int|scope| if (strcmp(name, "scope")==0) return PyInt_FromLong(pssi->flScope); // @prop int|hr| if (strcmp(name, "hr")==0) return PyInt_FromLong(pssi->hr); // @prop <o PyUnicode>|dcName| if (strcmp(name, "dcName")==0) return PyWinObject_FromWCHAR(pssi->pwzDcName); // @prop <o PyDSOP_FILTER_FLAGS>|filterFlags| if (strcmp(name, "filterFlags")==0) return new PyDSOP_FILTER_FLAGS(p); return PyObject_GenericGetAttr(self,obname); } int PyDSOP_SCOPE_INIT_INFO::setattro(PyObject *self, PyObject *obname, PyObject *val) { PyDSOP_SCOPE_INIT_INFO *p = (PyDSOP_SCOPE_INIT_INFO *)self; DSOP_SCOPE_INIT_INFO *pssi = p->owner->pScopes + p->index; char *name=PyString_AsString(obname); PyErr_Clear(); if (strcmp(name, "type")==0) { pssi->flType = PyInt_AsLong(val); if (PyErr_Occurred()) return -1; } else if (strcmp(name, "scope")==0) { pssi->flScope = PyInt_AsLong(val); if (PyErr_Occurred()) return -1; } else if (strcmp(name, "scope")==0) { pssi->hr = PyInt_AsLong(val); if (PyErr_Occurred()) return -1; } else if (strcmp(name, "dcName")==0) { WCHAR *buf; if (!PyWinObject_AsWCHAR(val, &buf, TRUE)) return -1; PyWinObject_FreeWCHAR((WCHAR *)pssi->pwzDcName); pssi->pwzDcName = buf; } else if (strcmp(name, "filterFlags")==0) { PyErr_SetString(PyExc_AttributeError, "filterFlags attribute can not be set (try setting attributes on the object itself)"); return -1; } else { return PyObject_GenericSetAttr(self, obname, val); } return 0; } void PyDSOP_SCOPE_INIT_INFO::deallocFunc(PyObject *ob) { delete (PyDSOP_SCOPE_INIT_INFO *)ob; } //////////////////////////////////////////////////////////////////////////// // PyDSOP_FILTER_FLAGS //////////////////////////////////////////////////////////////////////////// // @object PyDSOP_FILTER_FLAGS|An object representing an ActiveDirectory DSOP_FILTER_FLAGS structure // <nl>These objects can only be accessed via a <o PyDSOP_SCOPE_INIT_INFO> object. PyTypeObject PyDSOP_FILTER_FLAGSType = { PyObject_HEAD_INIT(&PyType_Type) 0, "PyDSOP_FILTER_FLAGS", sizeof(PyDSOP_FILTER_FLAGS), 0, PyDSOP_FILTER_FLAGS::deallocFunc, // tp_dealloc 0, // tp_print 0, // tp_getattr 0, // tp_setattr 0, // tp_compare 0, // tp_repr 0, // PyNumberMethods *tp_as_number 0, // PySequenceMethods *tp_as_sequence 0, // PyMappingMethods *tp_as_mapping 0, // hashfunc tp_hash 0, // tp_call 0, // tp_str PyDSOP_FILTER_FLAGS::getattro, // tp_getattro PyDSOP_FILTER_FLAGS::setattro, // tp_setattro 0, // PyBufferProcs *tp_as_buffer Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, // tp_flags 0, // tp_doc 0, // traverseproc tp_traverse 0, // tp_clear 0, // richcmpfunc tp_richcompare 0, // tp_weaklistoffset 0, // getiterfunc tp_iter 0, // iternextfunc tp_iternext 0, // methods 0, // members 0, // tp_getset; 0, // tp_base; 0, // tp_dict; 0, // tp_descr_get 0, // tp_descr_set 0, // tp_dictoffset 0, // tp_init 0, // tp_alloc 0, // newfunc tp_new; }; PyDSOP_FILTER_FLAGS::PyDSOP_FILTER_FLAGS(PyDSOP_SCOPE_INIT_INFO *_owner) { ob_type = &PyDSOP_FILTER_FLAGSType; owner = _owner; Py_INCREF(owner); _Py_NewReference(this); } PyDSOP_FILTER_FLAGS::~PyDSOP_FILTER_FLAGS() { Py_DECREF(owner); } PyObject * PyDSOP_FILTER_FLAGS::getattro(PyObject *self, PyObject *obname) { PyDSOP_FILTER_FLAGS *p = (PyDSOP_FILTER_FLAGS *)self; char *name=PyString_AsString(obname); if (!name) return NULL; DSOP_SCOPE_INIT_INFO *psii = p->owner->owner->pScopes + p->owner->index; // @prop <o PyDSOP_UPLEVEL_FILTER_FLAGS>|uplevel| if (strcmp(name, "uplevel")==0) return new PyDSOP_UPLEVEL_FILTER_FLAGS(p->owner); // @prop int|downlevel| if (strcmp(name, "downlevel")==0) return PyInt_FromLong(psii->FilterFlags.flDownlevel); return PyObject_GenericGetAttr(self,obname); } int PyDSOP_FILTER_FLAGS::setattro(PyObject *self, PyObject *obname, PyObject *val) { PyDSOP_FILTER_FLAGS *p = (PyDSOP_FILTER_FLAGS *)self; char *name=PyString_AsString(obname); if (!name) return NULL; DSOP_SCOPE_INIT_INFO *psii = p->owner->owner->pScopes + p->owner->index; PyErr_Clear(); if (strcmp(name, "downlevel")==0) { psii->FilterFlags.flDownlevel = PyInt_AsLong(val); if (PyErr_Occurred()) return -1; } else if (strcmp(name, "uplevel")==0) { PyErr_SetString(PyExc_AttributeError, "uplevel attribute can not be set (try setting attributes on the object itself)"); return -1; } else { return PyObject_GenericSetAttr(self, obname, val); } return 0; } void PyDSOP_FILTER_FLAGS::deallocFunc(PyObject *ob) { delete (PyDSOP_FILTER_FLAGS *)ob; } //////////////////////////////////////////////////////////////////////////// // PyDSOP_UPLEVEL_FILTER_FLAGS //////////////////////////////////////////////////////////////////////////// // @object PyDSOP_UPLEVEL_FILTER_FLAGS|An object representing an ActiveDirectory // DSOP_UPLEVEL_FILTER_FLAGS structure. // <nl>These objects can only be accessed via a <o PyDSOP_FILTER_FLAGS> object. PyTypeObject PyDSOP_UPLEVEL_FILTER_FLAGSType = { PyObject_HEAD_INIT(&PyType_Type) 0, "PyDSOP_UPLEVEL_FILTER_FLAGS", sizeof(PyDSOP_UPLEVEL_FILTER_FLAGS), 0, PyDSOP_UPLEVEL_FILTER_FLAGS::deallocFunc, // tp_dealloc 0, // tp_print 0, // tp_getattr 0, // tp_setattr 0, // tp_compare 0, // tp_repr 0, // PyNumberMethods *tp_as_number 0, // PySequenceMethods *tp_as_sequence 0, // PyMappingMethods *tp_as_mapping 0, // hashfunc tp_hash 0, // tp_call 0, // tp_str PyDSOP_UPLEVEL_FILTER_FLAGS::getattro, // tp_getattro PyDSOP_UPLEVEL_FILTER_FLAGS::setattro, // tp_setattro 0, // PyBufferProcs *tp_as_buffer Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, // tp_flags 0, // tp_doc 0, // traverseproc tp_traverse 0, // tp_clear 0, // richcmpfunc tp_richcompare 0, // tp_weaklistoffset 0, // getiterfunc tp_iter 0, // iternextfunc tp_iternext 0, // methods 0, // members 0, // tp_getset; 0, // tp_base; 0, // tp_dict; 0, // tp_descr_get 0, // tp_descr_set 0, // tp_dictoffset 0, // tp_init 0, // tp_alloc 0, // newfunc tp_new; }; PyDSOP_UPLEVEL_FILTER_FLAGS::PyDSOP_UPLEVEL_FILTER_FLAGS(PyDSOP_SCOPE_INIT_INFO *_owner) { ob_type = &PyDSOP_UPLEVEL_FILTER_FLAGSType; owner = _owner; Py_INCREF(owner); _Py_NewReference(this); } PyDSOP_UPLEVEL_FILTER_FLAGS::~PyDSOP_UPLEVEL_FILTER_FLAGS() { Py_DECREF(owner); } PyObject * PyDSOP_UPLEVEL_FILTER_FLAGS::getattro(PyObject *self, PyObject *obname) { PyDSOP_UPLEVEL_FILTER_FLAGS *p = (PyDSOP_UPLEVEL_FILTER_FLAGS *)self; DSOP_SCOPE_INIT_INFO *psii = p->owner->owner->pScopes + p->owner->index; char *name=PyString_AsString(obname); if (!name) return NULL; // @prop int|bothModes| if (strcmp(name, "bothModes")==0) return PyInt_FromLong(psii->FilterFlags.Uplevel.flBothModes); // @prop int|mixedModeOnly| if (strcmp(name, "mixedModeOnly")==0) return PyInt_FromLong(psii->FilterFlags.Uplevel.flMixedModeOnly); // @prop int|nativeModeOnly| if (strcmp(name, "nativeModeOnly")==0) return PyInt_FromLong(psii->FilterFlags.Uplevel.flNativeModeOnly); return PyObject_GenericGetAttr(self,obname); } int PyDSOP_UPLEVEL_FILTER_FLAGS::setattro(PyObject *self, PyObject *obname, PyObject *val) { PyDSOP_UPLEVEL_FILTER_FLAGS *p = (PyDSOP_UPLEVEL_FILTER_FLAGS *)self; DSOP_SCOPE_INIT_INFO *psii = p->owner->owner->pScopes + p->owner->index; char *name=PyString_AsString(obname); if (!name) return NULL; PyErr_Clear(); if (strcmp(name, "bothModes")==0) { psii->FilterFlags.Uplevel.flBothModes = PyInt_AsLong(val); if (PyErr_Occurred()) return -1; } else if (strcmp(name, "mixedModeOnly")==0) { psii->FilterFlags.Uplevel.flMixedModeOnly = PyInt_AsLong(val); if (PyErr_Occurred()) return -1; } else if (strcmp(name, "nativeModeOnly")==0) { psii->FilterFlags.Uplevel.flNativeModeOnly = PyInt_AsLong(val); if (PyErr_Occurred()) return -1; } else { return PyObject_GenericSetAttr(self, obname, val); } return 0; } void PyDSOP_UPLEVEL_FILTER_FLAGS::deallocFunc(PyObject *ob) { delete (PyDSOP_UPLEVEL_FILTER_FLAGS *)ob; } |
From: Mark H. <mha...@us...> - 2005-05-26 11:39:27
|
Update of /cvsroot/pywin32/pywin32/com/win32comext/adsi/demos In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26331/demos Added Files: objectPicker.py Log Message: Add support for IDsObjectPicker --- NEW FILE: objectPicker.py --- # A demo for the IDsObjectPicker interface. import win32clipboard import pythoncom from win32com.adsi import adsi from win32com.adsi.adsicon import * cf_objectpicker = win32clipboard.RegisterClipboardFormat(CFSTR_DSOP_DS_SELECTION_LIST) def main(): hwnd = 0 # Create an instance of the object picker. picker = pythoncom.CoCreateInstance(adsi.CLSID_DsObjectPicker, None, pythoncom.CLSCTX_INPROC_SERVER, adsi.IID_IDsObjectPicker) # Create our scope init info. siis = adsi.DSOP_SCOPE_INIT_INFOs(1) sii = siis[0] # Combine multiple scope types in a single array entry. sii.type = DSOP_SCOPE_TYPE_UPLEVEL_JOINED_DOMAIN | \ DSOP_SCOPE_TYPE_DOWNLEVEL_JOINED_DOMAIN # Set uplevel and downlevel filters to include only computer objects. # Uplevel filters apply to both mixed and native modes. # Notice that the uplevel and downlevel flags are different. sii.filterFlags.uplevel.bothModes = DSOP_FILTER_COMPUTERS sii.filterFlags.downlevel = DSOP_DOWNLEVEL_FILTER_COMPUTERS # Initialize the interface. picker.Initialize( None, # Target is the local computer. siis, # scope infos DSOP_FLAG_MULTISELECT, # options ('objectGUID','displayName') ) # attributes to fetch do = picker.InvokeDialog(hwnd) # Extract the data from the IDataObject. format_etc = (cf_objectpicker, None, pythoncom.DVASPECT_CONTENT, -1, pythoncom.TYMED_HGLOBAL) medium = do.GetData(format_etc) data = adsi.StringAsDS_SELECTION_LIST(medium.data) for item in data: name, klass, adspath, upn, attrs, flags = item print "Item", name print " Class:", klass print " AdsPath:", adspath print " UPN:", upn print " Attrs:", attrs print " Flags:", flags if __name__=='__main__': main() |
From: Mark H. <mha...@us...> - 2005-05-26 11:35:23
|
Update of /cvsroot/pywin32/pywin32/com/win32comext/adsi/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25596 Modified Files: adsilib.i Log Message: Remove stale confusing comments. Index: adsilib.i =================================================================== RCS file: /cvsroot/pywin32/pywin32/com/win32comext/adsi/src/adsilib.i,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** adsilib.i 24 Sep 2004 07:25:12 -0000 1.2 --- adsilib.i 26 May 2005 11:35:13 -0000 1.3 *************** *** 49,71 **** typedef long ADS_SEARCH_HANDLE - /*** - // Some ** special cases. - %typemap(python,freearg) IMsgStore **INPUT - { - if ($source && *$source) (*$source)->Release(); - } - - %typemap(python,arginit) IMsgStore ** { - $target = NULL; - } - - %typemap(python,in) IMsgStore **INPUT(IMsgStore *temp) - { - $target = &temp; - if (!PyCom_InterfaceFromPyInstanceOrObject($source, IID_IMsgStore, (void **)$target, 0)) - return NULL; - } - ***/ - // The types and structures. --- 49,52 ---- *************** *** 143,203 **** if ($source) FreeADsMem($source); } - - /*** - - %typemap(python,ignore) MAPIINIT_0 *OUTPUT (MAPIINIT_0 temp) { - $target = &temp; - } - - %typemap(python,argout) MAPIINIT_0 *OUTPUT { - Py_DECREF($target); - $target = Py_BuildValue("ll", - $source->ulVersion, - $source->ulFlags); - } - - %typemap(python,in) MAPIINIT_0 *INPUT(MAPIINIT_0 temp) - { - $target = &temp; - if ($source==Py_None) - $target = NULL; - else { - if (!PyArg_ParseTuple($source, "ii:MAPIINIT_0 tuple", &($target->ulVersion), &($target->ulFlags))) { - $cleanup; - return NULL; - } - } - } - - // A "MAPISTRINGARRAY" object - not a real type at all - // but suitable for "returned array of strings" - %typemap(python,ignore) TCHAR **OUTPUT_ARRAY(TCHAR *temp) - { - $target = &temp; - } - - %typemap(python,argout) TCHAR **OUTPUT_ARRAY { - $target = PyList_New(0); - for (int __i=0; $source[__i] != NULL ;__i++) { - PyObject *obNew = PyWinObject_FromTCHAR($source[__i]); - PyList_Append($target, obNew); - Py_XDECREF(obNew); - } - MAPIFreeBuffer($source); - } - - %typemap(python,ignore) TCHAR **OUTPUT_MAPI(TCHAR *temp) - { - $target = &temp; - } - - %typemap(python,argout) TCHAR **OUTPUT_MAPI { - if (*$source==NULL) { - $target = Py_None; - Py_INCREF(Py_None); - } else { - $target = PyWinObject_FromTCHAR(*$source); - MAPIFreeBuffer(*$source); - } - } - ***/ \ No newline at end of file --- 124,125 ---- |
From: Mark H. <mha...@us...> - 2005-05-25 02:11:25
|
Update of /cvsroot/pywin32/pywin32/com/win32comext/adsi/demos In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13773 Modified Files: scp.py Log Message: Beef up this demo significantly Index: scp.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/com/win32comext/adsi/demos/scp.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** scp.py 8 Oct 2004 23:37:27 -0000 1.1 --- scp.py 25 May 2005 02:11:15 -0000 1.2 *************** *** 1,12 **** ! # re-implementation of the MS "Scp" sample functions ! # Adds and removes an ActiveDirectory "Service Connection Point", ! # including managing the security on the object. ! # This is likely to become a 'module' rather than a demo, once ! # we had reasonable Python signatures for the functions ! # (ie, once we have one, real, service that uses it :) from win32com.adsi.adsicon import * from win32com.adsi import adsi ! import win32api, win32con from win32com.client import Dispatch # Returns distinguished name of SCP. --- 1,58 ---- ! """A re-implementation of the MS DirectoryService samples related to services. ! ! * Adds and removes an ActiveDirectory "Service Connection Point", ! including managing the security on the object. ! * Creates and registers Service Principal Names. ! * Changes the username for a domain user. ! ! Some of these functions are likely to become move to a module - but there ! is also a little command-line-interface to try these functions out. ! ! For example: ! ! scp.py --account-name=domain\user --service-class=PythonScpTest \\ ! --keyword=foo --keyword=bar --binding-string=bind_info \\ ! ScpCreate SpnCreate SpnRegister ! ! would: ! * Attempt to delete a Service Connection Point for the service class ! 'PythonScpTest' ! * Attempt to create a Service Connection Point for that class, with 2 ! keywords and a binding string of 'bind_info' ! * Create a Service Principal Name for the service and register it ! ! to undo those changes, you could execute: ! ! scp.py --account-name=domain\user --service-class=PythonScpTest \\ ! SpnCreate SpnUnregister ScpDelete ! ! which will: ! * Create a SPN ! * Unregister that SPN from the Active Directory. ! * Delete the Service Connection Point ! ! Executing with --test will create and remove one of everything. ! """ ! from win32com.adsi.adsicon import * from win32com.adsi import adsi ! import win32api, win32con, winerror from win32com.client import Dispatch + import ntsecuritycon as dscon + import win32security + import optparse, textwrap + import traceback + import types + + verbose = 1 + g_createdSCP = None + g_createdSPNs = [] + g_createdSPNLast = None + + import logging + + logger = logging # use logging module global methods for now. + + # still a bit confused about log(n, ...) vs logger.info/debug() # Returns distinguished name of SCP. *************** *** 20,27 **** dns_name_type = "A", dn = None, ): container_name = container_name or service_class_name ! # Get the DNS name of the local computer ! dns_name = win32api.GetComputerNameEx(win32con.ComputerNameDnsFullyQualified) # Get the distinguished name of the computer object for the local computer if dn is None: --- 66,75 ---- dns_name_type = "A", dn = None, + dns_name = None, ): container_name = container_name or service_class_name ! if not dns_name: ! # Get the DNS name of the local computer ! dns_name = win32api.GetComputerNameEx(win32con.ComputerNameDnsFullyQualified) # Get the distinguished name of the computer object for the local computer if dn is None: *************** *** 32,36 **** # Publish the SCP as a child of the computer object - keywords = keywords or [] # Fill in the attribute values to be stored in the SCP. --- 80,83 ---- *************** *** 45,52 **** ] new = comp.CreateDSObject("cn=" + container_name, attrs) ! print "got new", new # Wrap in a usable IDispatch object. new = Dispatch(new) AllowAccessToScpProperties(account_name, new) def ScpDelete(service_class_name, container_name = None, dn = None): --- 92,101 ---- ] new = comp.CreateDSObject("cn=" + container_name, attrs) ! logger.info("New connection point is at %s", container_name) # Wrap in a usable IDispatch object. new = Dispatch(new) + # And allow access to the SCP for the specified account name AllowAccessToScpProperties(account_name, new) + return new def ScpDelete(service_class_name, container_name = None, dn = None): *************** *** 54,70 **** if dn is None: dn = win32api.GetComputerObjectName(win32con.NameFullyQualifiedDN) ! print "DN is", dn # Compose the ADSpath and bind to the computer object for the local computer comp = adsi.ADsGetObject("LDAP://" + dn, adsi.IID_IDirectoryObject) comp.DeleteDSObject("cn=" + container_name) ! print "Deleted!" def AllowAccessToScpProperties( accountSAM, #Service account to allow access. ! scpObject): # The IADs SCP object. - attribute = "nTSecurityDescriptor"; - # If no service account is specified, service runs under LocalSystem. # So allow access to the computer account of the service's host. --- 103,138 ---- if dn is None: dn = win32api.GetComputerObjectName(win32con.NameFullyQualifiedDN) ! logger.debug("Removing connection point from %s", dn) # Compose the ADSpath and bind to the computer object for the local computer comp = adsi.ADsGetObject("LDAP://" + dn, adsi.IID_IDirectoryObject) comp.DeleteDSObject("cn=" + container_name) ! logger.info("Deleted service connection point '%s'", container_name) ! ! # This function is described in detail in the MSDN article titled ! # "Enabling Service Account to Access SCP Properties" ! # From that article: ! # The following sample code sets a pair of ACEs on a service connection point ! # (SCP) object. The ACEs grant read/write access to the user or computer account ! # under which the service instance will be running. Your service installation ! # program calls this code to ensure that the service will be allowed to update ! # its properties at run time. If you don't set ACEs like these, your service ! # will get access-denied errors if it tries to modify the SCP's properties. ! # ! # The code uses the IADsSecurityDescriptor, IADsAccessControlList, and ! # IADsAccessControlEntry interfaces to do the following: ! # * Get the SCP object's security descriptor. ! # * Set ACEs in the DACL of the security descriptor. ! # * Set the security descriptor back on the SCP object. def AllowAccessToScpProperties( accountSAM, #Service account to allow access. ! scpObject, # The IADs SCP object. ! schemaIDGUIDs = # Attributes to allow write-access to. ! ("{28630eb8-41d5-11d1-a9c1-0000f80367c1}", # serviceDNSName ! "{b7b1311c-b82e-11d0-afee-0000f80367c1}", # serviceBindingInformation ! ) ! ): # If no service account is specified, service runs under LocalSystem. # So allow access to the computer account of the service's host. *************** *** 75,119 **** trustee = win32api.GetComputerObjectName(win32con.NameSamCompatible) ! # Get the nTSecurityDescriptor sd = getattr(scpObject, attribute) - acl = sd.DiscretionaryAcl ! ace1 = Dispatch(adsi.CLSID_AccessControlEntry) ! ace2 = Dispatch(adsi.CLSID_AccessControlEntry) - # Set the properties of the two ACEs. - - # Allow read and write access to the property. - ace1.AccessMask = ADS_RIGHT_DS_READ_PROP | ADS_RIGHT_DS_WRITE_PROP - ace2.AccessMask = ADS_RIGHT_DS_READ_PROP | ADS_RIGHT_DS_WRITE_PROP - - # Set the trustee, which is either the service account or the - # host computer account. - ace1.Trustee = trustee - ace2.Trustee = trustee - - # Set the ACE type. - ace1.AceType = ADS_ACETYPE_ACCESS_ALLOWED_OBJECT - ace2.AceType = ADS_ACETYPE_ACCESS_ALLOWED_OBJECT - - # Set AceFlags to zero because ACE is not inheritable. - ace1.AceFlags = 0 - ace2.AceFlags = 0 - - # Set Flags to indicate an ACE that protects a specified object. - ace1.Flags = ADS_FLAG_OBJECT_TYPE_PRESENT - ace2.Flags = ADS_FLAG_OBJECT_TYPE_PRESENT - - # Set ObjectType to the schemaIDGUID of the attribute. - ace1.ObjectType = "{28630eb8-41d5-11d1-a9c1-0000f80367c1}" # serviceDNSName - ace2.ObjectType = "{b7b1311c-b82e-11d0-afee-0000f80367c1}" # serviceBindingInformation - - # Add the ACEs to the DACL. - acl.AddAce(ace1) - - # Do it again for the second ACE. - acl.AddAce(ace2) - # Write the modified DACL back to the security descriptor. sd.DiscretionaryAcl = acl --- 143,177 ---- trustee = win32api.GetComputerObjectName(win32con.NameSamCompatible) ! # Get the nTSecurityDescriptor attribute ! attribute = "nTSecurityDescriptor" sd = getattr(scpObject, attribute) acl = sd.DiscretionaryAcl ! for sguid in schemaIDGUIDs: ! ace = Dispatch(adsi.CLSID_AccessControlEntry) ! ! # Set the properties of the ACE. ! # Allow read and write access to the property. ! ace.AccessMask = ADS_RIGHT_DS_READ_PROP | ADS_RIGHT_DS_WRITE_PROP ! ! # Set the trustee, which is either the service account or the ! # host computer account. ! ace.Trustee = trustee ! ! # Set the ACE type. ! ace.AceType = ADS_ACETYPE_ACCESS_ALLOWED_OBJECT ! ! # Set AceFlags to zero because ACE is not inheritable. ! ace.AceFlags = 0 ! ! # Set Flags to indicate an ACE that protects a specified object. ! ace.Flags = ADS_FLAG_OBJECT_TYPE_PRESENT ! ! # Set ObjectType to the schemaIDGUID of the attribute. ! ace.ObjectType = sguid ! ! # Add the ACEs to the DACL. ! acl.AddAce(ace) # Write the modified DACL back to the security descriptor. sd.DiscretionaryAcl = acl *************** *** 122,128 **** # SetInfo updates the SCP object in the directory. scpObject.SetInfo() ! print "Set security on object for account '%s'" % (trustee,) if __name__=='__main__': ! ScpDelete("PythonSCPTest") ! ScpCreate("2222", "PythonSCPTest", None, keywords = "mark was here".split()) --- 180,492 ---- # SetInfo updates the SCP object in the directory. scpObject.SetInfo() ! logger.info("Set security on object for account '%s'" % (trustee,)) ! ! # Service Principal Names functions from the same sample. ! # The example calls the DsWriteAccountSpn function, which stores the SPNs in ! # Microsoft Active Directory under the servicePrincipalName attribute of the ! # account object specified by the serviceAcctDN parameter. The account object ! # corresponds to the logon account specified in the CreateService call for this ! # service instance. If the logon account is a domain user account, ! # serviceAcctDN must be the distinguished name of the account object in ! # Active Directory for that user account. If the service's logon account is the ! # LocalSystem account, serviceAcctDN must be the distinguished name of the ! # computer account object for the host computer on which the service is ! # installed. win32api.TranslateNames and win32security.DsCrackNames can ! # be used to convert a domain\account format name to a distinguished name. ! def SpnRegister( ! serviceAcctDN, # DN of the service's logon account ! spns, # List of SPNs to register ! operation, # Add, replace, or delete SPNs ! ): ! assert spns not in types.StringTypes and hasattr(spns, "__iter__"), \ ! "spns must be a sequence of strings (got %r)" % spns ! # Bind to a domain controller. ! # Get the domain for the current user. ! samName = win32api.GetUserNameEx(win32api.NameSamCompatible) ! samName = samName.split('\\', 1)[0] ! ! if not serviceAcctDN: ! # Get the SAM account name of the computer object for the server. ! serviceAcctDN = win32api.GetComputerObjectName(win32con.NameFullyQualifiedDN) ! logger.debug("SpnRegister using DN '%s'", serviceAcctDN) ! ! # Get the name of a domain controller in that domain. ! info = win32security.DsGetDcName( ! domainName=samName, ! flags=dscon.DS_IS_FLAT_NAME | ! dscon.DS_RETURN_DNS_NAME | ! dscon.DS_DIRECTORY_SERVICE_REQUIRED) ! # Bind to the domain controller. ! handle = win32security.DsBind( info['DomainControllerName'] ) ! ! # Write the SPNs to the service account or computer account. ! logger.debug("DsWriteAccountSpn with spns %s") ! win32security.DsWriteAccountSpn( ! handle, # handle to the directory ! operation, # Add or remove SPN from account's existing SPNs ! serviceAcctDN, # DN of service account or computer account ! spns) # names ! ! # Unbind the DS in any case (but Python would do it anyway) ! handle.Close() ! ! def UserChangePassword(username_dn, new_password): ! # set the password on the account. ! # Use the distinguished name to bind to the account object. ! accountPath = "LDAP://" + username_dn ! user = adsi.ADsGetObject(accountPath, adsi.IID_IADsUser) ! ! # Set the password on the account. ! user.SetPassword(new_password) ! ! # functions related to the command-line interface ! def log(level, msg, *args): ! if verbose >= level: ! print msg % args ! ! class _NoDefault: pass ! ! def _get_option(po, opt_name, default = _NoDefault): ! parser, options = po ! ret = getattr(options, opt_name, default) ! if not ret and default is _NoDefault: ! parser.error("The '%s' option must be specified for this operation" % opt_name) ! if not ret: ! ret = default ! return ret ! ! def _option_error(po, why): ! parser = po[0] ! parser.error(why) ! ! def do_ScpCreate(po): ! """Create a Service Connection Point""" ! global g_createdSCP ! scp = ScpCreate(_get_option(po, "binding_string"), ! _get_option(po, "service_class"), ! _get_option(po, "account_name_sam", None), ! keywords=_get_option(po, "keywords", None)) ! g_createdSCP = scp ! return scp.distinguishedName ! ! def do_ScpDelete(po): ! """Delete a Service Connection Point""" ! sc = _get_option(po, "service_class") ! try: ! ScpDelete(sc) ! except adsi.error, details: ! if details[0] != winerror.ERROR_DS_OBJ_NOT_FOUND: ! raise ! log(2, "ScpDelete ignoring ERROR_DS_OBJ_NOT_FOUND for service-class '%s'", ! sc) ! return sc ! ! def do_SpnCreate(po): ! """Create a Service Principal Name""" ! # The 'service name' is the dn of our scp. ! if g_createdSCP is None: ! # Could accept an arg to avoid this? ! _option_error(po, "ScpCreate must have been specified before SpnCreate") ! # Create a Service Principal Name" ! spns = win32security.DsGetSpn(dscon.DS_SPN_SERVICE, ! _get_option(po, "service_class"), ! g_createdSCP.distinguishedName, ! _get_option(po, "port", 0), ! None, None) ! spn = spns[0] ! log(2, "Created SPN: %s", spn) ! global g_createdSPNLast ! g_createdSPNLast = spn ! g_createdSPNs.append(spn) ! return spn ! ! def do_SpnRegister(po): ! """Register a previously created Service Principal Name""" ! if not g_createdSPNLast: ! _option_error(po, "SpnCreate must appear before SpnRegister") ! ! SpnRegister(_get_option(po, "account_name_dn", None), ! (g_createdSPNLast,), ! dscon.DS_SPN_ADD_SPN_OP) ! return g_createdSPNLast ! ! def do_SpnUnregister(po): ! """Unregister a previously created Service Principal Name""" ! if not g_createdSPNLast: ! _option_error(po, "SpnCreate must appear before SpnUnregister") ! SpnRegister(_get_option(po, "account_name_dn", None), ! (g_createdSPNLast,), ! dscon.DS_SPN_DELETE_SPN_OP) ! return g_createdSPNLast ! ! def do_UserChangePassword(po): ! """Change the password for a specified user""" ! UserChangePassword(_get_option(po, "account_name_dn"), ! _get_option(po, "password")) ! return "Password changed OK" ! ! handlers = ( ! ('ScpCreate', do_ScpCreate), ! ('ScpDelete', do_ScpDelete), ! ('SpnCreate', do_SpnCreate), ! ('SpnRegister', do_SpnRegister), ! ('SpnUnregister', do_SpnUnregister), ! ('UserChangePassword', do_UserChangePassword), ! ) ! ! class HelpFormatter(optparse.IndentedHelpFormatter): ! def format_description(self, description): ! return description ! ! def main(): ! global verbose ! _handlers_dict = {} ! ! arg_descs = [] ! for arg, func in handlers: ! this_desc = "\n".join(textwrap.wrap(func.__doc__, ! subsequent_indent = " " * 8)) ! arg_descs.append(" %s: %s" % (arg, this_desc)) ! _handlers_dict[arg.lower()] = func ! ! description = __doc__ + "\ncommands:\n" + "\n".join(arg_descs) + "\n" ! ! parser = optparse.OptionParser(usage = "%prog [options] command ...", ! description=description, ! formatter=HelpFormatter()) ! ! parser.add_option("-v", action="count", ! dest="verbose", default=1, ! help="increase the verbosity of status messages") ! ! parser.add_option("-q", "--quiet", action="store_true", ! help="Don't print any status messages") ! ! parser.add_option("-t", "--test", action="store_true", ! help="Execute a mini-test suite, providing defaults for most options and args"), ! ! parser.add_option("", "--show-tracebacks", action="store_true", ! help="Show the tracebacks for any exceptions") ! ! parser.add_option("", "--service-class", ! help="The service class name to use") ! ! parser.add_option("", "--port", default=0, ! help="The port number to associate with the SPN") ! ! parser.add_option("", "--binding-string", ! help="The binding string to use for SCP creation") ! ! parser.add_option("", "--account-name", ! help="The account name to use (default is LocalSystem)") ! ! parser.add_option("", "--password", ! help="The password to set.") ! ! parser.add_option("", "--keyword", action="append", dest="keywords", ! help="""A keyword to add to the SCP. May be specified ! multiple times""") ! ! parser.add_option("", "--log-level", ! help="""The log-level to use - may be a number or a logging ! module constant""", default=str(logging.WARNING)) ! ! options, args = parser.parse_args() ! po = (parser, options) ! # fixup misc ! try: ! options.port = int(options.port) ! except (TypeError, ValueError): ! parser.error("--port must be numeric") ! # fixup log-level ! try: ! log_level = int(options.log_level) ! except (TypeError, ValueError): ! try: ! log_level = int(getattr(logging, options.log_level.upper())) ! except (ValueError, TypeError, AttributeError): ! parser.error("Invalid --log-level value") ! try: ! sl = logger.setLevel ! # logger is a real logger ! except AttributeError: ! # logger is logging module ! sl = logging.getLogger().setLevel ! sl(log_level) ! # Check -q/-v ! if options.quiet and options.verbose: ! parser.error("Can't specify --quiet and --verbose") ! if options.quiet: ! options.verbose -= 1 ! verbose = options.verbose ! # --test ! if options.test: ! if args: ! parser.error("Can't specify args with --test") ! ! args = "ScpDelete ScpCreate SpnCreate SpnRegister SpnUnregister ScpDelete" ! log(1, "--test - pretending args are:\n %s", args) ! args = args.split() ! if not options.service_class: ! options.service_class = "PythonScpTest" ! log(2, "--test: --service-class=%s", options.service_class) ! if not options.keywords: ! options.keywords = "Python Powered".split() ! log(2, "--test: --keyword=%s", options.keywords) ! if not options.binding_string: ! options.binding_string = "test binding string" ! log(2, "--test: --binding-string=%s", options.binding_string) ! ! # check args ! if not args: ! parser.error("No command specified (use --help for valid commands)") ! for arg in args: ! if arg.lower() not in _handlers_dict: ! parser.error("Invalid command '%s' (use --help for valid commands)" % arg) ! ! # Patch up account-name. ! if options.account_name: ! log(2, "Translating account name '%s'", options.account_name) ! options.account_name_sam = win32security.TranslateName(options.account_name, ! win32api.NameUnknown, ! win32api.NameSamCompatible) ! log(2, "NameSamCompatible is '%s'",options.account_name_sam) ! options.account_name_dn = win32security.TranslateName(options.account_name, ! win32api.NameUnknown, ! win32api.NameFullyQualifiedDN) ! log(2, "NameFullyQualifiedDNis '%s'",options.account_name_dn) ! ! # do it. ! for arg in args: ! handler = _handlers_dict[arg.lower()] # already been validated ! if handler is None: ! parser.error("Invalid command '%s'" % arg) ! err_msg = None ! try: ! try: ! log(2, "Executing '%s'...", arg) ! result = handler(po) ! log(1, "%s: %s", arg, result) ! except: ! if options.show_tracebacks: ! print "--show-tracebacks specified - dumping exception" ! traceback.print_exc() ! raise ! except adsi.error, (hr, desc, exc, argerr): ! if exc: ! extra_desc = exc[2] ! else: ! extra_desc = "" ! err_msg = desc ! if extra_desc: ! err_msg += "\n\t" + extra_desc ! except win32api.error, (hr, func, msg): ! err_msg = msg ! if err_msg: ! log(1, "Command '%s' failed: %s", arg, err_msg) if __name__=='__main__': ! try: ! main() ! except KeyboardInterrupt: ! print "*** Interrupted" |
From: Mark H. <mha...@us...> - 2005-05-25 01:26:17
|
Update of /cvsroot/pywin32/pywin32/com/win32comext/adsi/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5816 Modified Files: PyIADsUser.i Log Message: Add SetPassword and ChangePassword Index: PyIADsUser.i =================================================================== RCS file: /cvsroot/pywin32/pywin32/com/win32comext/adsi/src/PyIADsUser.i,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** PyIADsUser.i 5 May 2000 00:42:00 -0000 1.1 --- PyIADsUser.i 25 May 2005 01:26:04 -0000 1.2 *************** *** 108,109 **** --- 108,118 ---- // @pyparm unicode|val|| HRESULT put_LoginScript(OLECHAR *val); + + // @pyswig |SetPassword| + // @pyparm unicode|val|| + HRESULT SetPassword(OLECHAR *val); + + // @pyswig |ChangePassword| + // @pyparm unicode|oldval|| + // @pyparm unicode|newval|| + HRESULT ChangePassword(OLECHAR *val, OLECHAR *val); |
From: Mark H. <mha...@us...> - 2005-05-24 14:47:38
|
Update of /cvsroot/pywin32/pywin32/isapi In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28709 Modified Files: simple.py Log Message: Correct typo in docstring. Index: simple.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/isapi/simple.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** simple.py 6 Oct 2004 05:11:52 -0000 1.1 --- simple.py 24 May 2005 14:47:15 -0000 1.2 *************** *** 10,14 **** class SimpleExtension: ! "Base class for a a simple ISAPI extension" def __init__(self): pass --- 10,14 ---- class SimpleExtension: ! "Base class for a simple ISAPI extension" def __init__(self): pass |
From: Mark H. <mha...@us...> - 2005-05-24 14:46:27
|
Update of /cvsroot/pywin32/pywin32/isapi In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28574 Modified Files: install.py Log Message: Allow --server to specify either a site description or a site instance ID. Index: install.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/isapi/install.py,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** install.py 28 Apr 2005 22:42:19 -0000 1.5 --- install.py 24 May 2005 14:46:17 -0000 1.6 *************** *** 134,144 **** server = _IIS_OBJECT+"/1" else: ! # Assume the user has passed a "server description" - loop over ! # all objects until we find it. ob = GetObject(_IIS_OBJECT) look = server_desc.lower().strip() for sub in ob: ! this_comment = getattr(sub, "ServerComment", "") ! if this_comment.lower().strip() == look: server = sub.AdsPath break --- 134,146 ---- server = _IIS_OBJECT+"/1" else: ! # Assume the user has passed either the instance_id or "server ! # description" - loop over all objects until we find it. ob = GetObject(_IIS_OBJECT) look = server_desc.lower().strip() for sub in ob: ! # ID is generally a number, but no need to assume that. ! this_id = getattr(sub, "Name", "").lower().strip() ! this_comment = getattr(sub, "ServerComment", "").lower().strip() ! if this_id == look or this_comment == look: server = sub.AdsPath break |