desc
stringlengths
3
26.7k
decl
stringlengths
11
7.89k
bodies
stringlengths
8
553k
'Return cleanup code for C++ args passed to the interface method.'
def GetInterfaceArgCleanup(self):
if DEBUG: return ('/* GetInterfaceArgCleanup output goes here: %s */\n' % self.arg.name) else: return ''
'Return cleanup code for C++ args passed to the interface method that must be executed with the GIL held'
def GetInterfaceArgCleanupGIL(self):
if DEBUG: return ('/* GetInterfaceArgCleanup (GIL held) output goes here: %s */\n' % self.arg.name) else: return ''
'Declare the variable used as the PyArg_ParseTuple param for a gateway'
def DeclareParseArgTupleInputConverter(self):
if DEBUG: return ('/* Declare ParseArgTupleInputConverter goes here: %s */\n' % self.arg.name) else: return ''
'Get a string of C++ code to be executed after (ie, to finalise) the PyArg_ParseTuple conversion'
def GetParsePostCode(self):
if DEBUG: return ('/* GetParsePostCode code goes here: %s */\n' % self.arg.name) else: return ''
'Get a string of C++ code to be executed before (ie, to initialise) the Py_BuildValue conversion for Interfaces'
def GetBuildForInterfacePreCode(self):
if DEBUG: return ('/* GetBuildForInterfacePreCode goes here: %s */\n' % self.arg.name) else: return ''
'Get a string of C++ code to be executed before (ie, to initialise) the Py_BuildValue conversion for Gateways'
def GetBuildForGatewayPreCode(self):
s = self.GetBuildForInterfacePreCode() if DEBUG: if (s[:4] == '/* G'): s = ('/* GetBuildForGatewayPreCode goes here: %s */\n' % self.arg.name) return s
'Get a string of C++ code to be executed after (ie, to finalise) the Py_BuildValue conversion for Interfaces'
def GetBuildForInterfacePostCode(self):
if DEBUG: return ('/* GetBuildForInterfacePostCode goes here: %s */\n' % self.arg.name) return ''
'Get a string of C++ code to be executed after (ie, to finalise) the Py_BuildValue conversion for Gateways'
def GetBuildForGatewayPostCode(self):
s = self.GetBuildForInterfacePostCode() if DEBUG: if (s[:4] == '/* G'): s = ('/* GetBuildForGatewayPostCode goes here: %s */\n' % self.arg.name) return s
'Returns a string with the description of the type. Used for doco purposes'
def _GetPythonTypeDesc(self):
return None
'Determines if this arg forces a USES_CONVERSION macro'
def NeedUSES_CONVERSION(self):
return 0
'Parse and build my data from a file Reads the next line in the file, and matches it as an argument description. If not a valid argument line, an error_not_found exception is raised.'
def BuildFromFile(self, file):
line = file.readline() mo = self.regex.search(line) if (not mo): raise error_not_found self.name = mo.group(3) self.inout = mo.group(1).split('][') typ = mo.group(2).strip() self.raw_type = typ self.indirectionLevel = 0 if mo.group(4): self.arrayDecl = 1 try: pos = typ.rindex('__RPC_FAR') self.indirectionLevel = (self.indirectionLevel + 1) typ = typ[:pos].strip() except ValueError: pass typ = typ.replace('__RPC_FAR', '') while 1: try: pos = typ.rindex('*') self.indirectionLevel = (self.indirectionLevel + 1) typ = typ[:pos].strip() except ValueError: break self.type = typ if (self.type[:6] == 'const '): self.unc_type = self.type[6:] else: self.unc_type = self.type if VERBOSE: print (' DCTB Arg %s of type %s%s (%s)' % (self.name, self.type, ('*' * self.indirectionLevel), self.inout))
'Determines if the argument has the specific attribute. Argument attributes are specified in the header file, such as "[in][out][retval]" etc. You can pass a specific string (eg "out") to find if this attribute was specified for the argument'
def HasAttribute(self, typ):
return (typ in self.inout)
'Parse and build my data from a file Reads the next line in the file, and matches it as a method description. If not a valid method line, an error_not_found exception is raised.'
def BuildFromFile(self, file):
line = file.readline() mo = self.regex.search(line) if (not mo): raise error_not_found self.name = mo.group(4) self.result = mo.group(2) if (self.result != 'HRESULT'): if (self.result == 'DWORD'): print 'Warning: Old style interface detected - compilation errors likely!' else: print ('Method %s - Only HRESULT return types are supported.' % self.name) print (' DCTB Method %s %s(' % (self.result, self.name)) while 1: arg = Argument(self.good_interface_names) try: arg.BuildFromFile(file) self.args.append(arg) except error_not_found: break
'Build all sub-methods for this interface'
def BuildMethods(self, file):
file.readline() file.readline() while 1: try: method = Method([self.name]) method.BuildFromFile(file) self.methods.append(method) except error_not_found: break
'Dispatch a call to an interface method.'
def dispatch(self, ob, index, argPtr, ReadFromInTuple=_univgw.ReadFromInTuple, WriteFromOutTuple=_univgw.WriteFromOutTuple):
meth = self._methods[index] hr = 0 args = ReadFromInTuple(meth._gw_in_args, argPtr) ob = getattr(ob, 'policy', ob) ob._dispid_to_func_[meth.dispid] = meth.name retVal = ob._InvokeEx_(meth.dispid, 0, meth.invkind, args, None, None) if (type(retVal) == tuple): if (len(retVal) == (len(meth._gw_out_args) + 1)): hr = retVal[0] retVal = retVal[1:] else: raise TypeError(('Expected %s return values, got: %s' % ((len(meth._gw_out_args) + 1), len(retVal)))) else: retVal = [retVal] retVal.extend(([None] * (len(meth._gw_out_args) - 1))) retVal = tuple(retVal) WriteFromOutTuple(retVal, meth._gw_out_args, argPtr) return hr
'Gets the typeinfo for the Source Events for the passed typeinfo'
def GetSourceTypeInfo(self, typeinfo):
attr = typeinfo.GetTypeAttr() cFuncs = attr[6] typeKind = attr[5] if (typeKind not in [pythoncom.TKIND_COCLASS, pythoncom.TKIND_INTERFACE]): RaiseAssert(winerror.E_UNEXPECTED, 'The typeKind of the object is unexpected') cImplType = attr[8] for i in xrange(cImplType): flags = typeinfo.GetImplTypeFlags(i) flagsNeeded = (pythoncom.IMPLTYPEFLAG_FDEFAULT | pythoncom.IMPLTYPEFLAG_FSOURCE) if ((flags & (flagsNeeded | pythoncom.IMPLTYPEFLAG_FRESTRICTED)) == flagsNeeded): href = typeinfo.GetRefTypeOfImplType(i) return typeinfo.GetRefTypeInfo(href)
'Gets the typeinfo for the Default Dispatch for the passed typeinfo'
def GetDefaultSourceTypeInfo(self, typeinfo):
attr = typeinfo.GetTypeAttr() cFuncs = attr[6] typeKind = attr[5] if (typeKind not in [pythoncom.TKIND_COCLASS, pythoncom.TKIND_INTERFACE]): RaiseAssert(winerror.E_UNEXPECTED, 'The typeKind of the object is unexpected') cImplType = attr[8] for i in xrange(cImplType): flags = typeinfo.GetImplTypeFlags(i) if ((flags & ((pythoncom.IMPLTYPEFLAG_FDEFAULT | pythoncom.IMPLTYPEFLAG_FSOURCE) | pythoncom.IMPLTYPEFLAG_FRESTRICTED)) == pythoncom.IMPLTYPEFLAG_FDEFAULT): href = typeinfo.GetRefTypeOfImplType(i) defTypeInfo = typeinfo.GetRefTypeInfo(href) attr = defTypeInfo.GetTypeAttr() typeKind = attr[5] typeFlags = attr[11] if ((typeKind == pythoncom.TKIND_INTERFACE) and (typeFlags & pythoncom.TYPEFLAG_FDUAL)): href = typeinfo.GetRefTypeOfImplType((-1)) return defTypeInfo.GetRefTypeInfo(href) else: return defTypeInfo
'Do we have _any_ debugging interfaces installed?'
def IsAnyHost(self):
return (self.debugApplication is not None)
'Called by the engine when a runtime error occurs. If we have a debugger, we let it know. The result is a boolean which indicates if the error handler should call IActiveScriptSite::OnScriptError()'
def HandleRuntimeError(self):
trace('HandleRuntimeError') fCallOnError = 1 return fCallOnError
'Adds a new engine to the site. engine can be a string, or a fully wrapped engine object.'
def AddEngine(self, engine):
if (type(engine) == type('')): newEngine = AXEngine(util.wrap(self), engine) else: newEngine = engine self.engine = newEngine flags = (((axscript.SCRIPTITEM_ISVISIBLE | axscript.SCRIPTITEM_NOCODE) | axscript.SCRIPTITEM_GLOBALMEMBERS) | axscript.SCRIPTITEM_ISPERSISTENT) for name in self.objModel.iterkeys(): newEngine.AddNamedItem(name, flags) newEngine.SetScriptState(axscript.SCRIPTSTATE_INITIALIZED) return newEngine
'WAVEFORMATEX type'
def test_1_Type(self):
w = pywintypes.WAVEFORMATEX() self.failUnless((type(w) == pywintypes.WAVEFORMATEXType))
'WAVEFORMATEX attribute access'
def test_2_Attr(self):
w = pywintypes.WAVEFORMATEX() w.wFormatTag = pywintypes.WAVE_FORMAT_PCM w.nChannels = 2 w.nSamplesPerSec = 44100 w.nAvgBytesPerSec = 176400 w.nBlockAlign = 4 w.wBitsPerSample = 16 self.failUnless((w.wFormatTag == 1)) self.failUnless((w.nChannels == 2)) self.failUnless((w.nSamplesPerSec == 44100)) self.failUnless((w.nAvgBytesPerSec == 176400)) self.failUnless((w.nBlockAlign == 4)) self.failUnless((w.wBitsPerSample == 16))
'DSCAPS type'
def test_1_Type(self):
c = ds.DSCAPS() self.failUnless((type(c) == ds.DSCAPSType))
'DSCAPS attribute access'
def test_2_Attr(self):
c = ds.DSCAPS() c.dwFlags = 1 c.dwMinSecondarySampleRate = 2 c.dwMaxSecondarySampleRate = 3 c.dwPrimaryBuffers = 4 c.dwMaxHwMixingAllBuffers = 5 c.dwMaxHwMixingStaticBuffers = 6 c.dwMaxHwMixingStreamingBuffers = 7 c.dwFreeHwMixingAllBuffers = 8 c.dwFreeHwMixingStaticBuffers = 9 c.dwFreeHwMixingStreamingBuffers = 10 c.dwMaxHw3DAllBuffers = 11 c.dwMaxHw3DStaticBuffers = 12 c.dwMaxHw3DStreamingBuffers = 13 c.dwFreeHw3DAllBuffers = 14 c.dwFreeHw3DStaticBuffers = 15 c.dwFreeHw3DStreamingBuffers = 16 c.dwTotalHwMemBytes = 17 c.dwFreeHwMemBytes = 18 c.dwMaxContigFreeHwMemBytes = 19 c.dwUnlockTransferRateHwBuffers = 20 c.dwPlayCpuOverheadSwBuffers = 21 self.failUnless((c.dwFlags == 1)) self.failUnless((c.dwMinSecondarySampleRate == 2)) self.failUnless((c.dwMaxSecondarySampleRate == 3)) self.failUnless((c.dwPrimaryBuffers == 4)) self.failUnless((c.dwMaxHwMixingAllBuffers == 5)) self.failUnless((c.dwMaxHwMixingStaticBuffers == 6)) self.failUnless((c.dwMaxHwMixingStreamingBuffers == 7)) self.failUnless((c.dwFreeHwMixingAllBuffers == 8)) self.failUnless((c.dwFreeHwMixingStaticBuffers == 9)) self.failUnless((c.dwFreeHwMixingStreamingBuffers == 10)) self.failUnless((c.dwMaxHw3DAllBuffers == 11)) self.failUnless((c.dwMaxHw3DStaticBuffers == 12)) self.failUnless((c.dwMaxHw3DStreamingBuffers == 13)) self.failUnless((c.dwFreeHw3DAllBuffers == 14)) self.failUnless((c.dwFreeHw3DStaticBuffers == 15)) self.failUnless((c.dwFreeHw3DStreamingBuffers == 16)) self.failUnless((c.dwTotalHwMemBytes == 17)) self.failUnless((c.dwFreeHwMemBytes == 18)) self.failUnless((c.dwMaxContigFreeHwMemBytes == 19)) self.failUnless((c.dwUnlockTransferRateHwBuffers == 20)) self.failUnless((c.dwPlayCpuOverheadSwBuffers == 21))
'DSBCAPS type'
def test_1_Type(self):
c = ds.DSBCAPS() self.failUnless((type(c) == ds.DSBCAPSType))
'DSBCAPS attribute access'
def test_2_Attr(self):
c = ds.DSBCAPS() c.dwFlags = 1 c.dwBufferBytes = 2 c.dwUnlockTransferRate = 3 c.dwPlayCpuOverhead = 4 self.failUnless((c.dwFlags == 1)) self.failUnless((c.dwBufferBytes == 2)) self.failUnless((c.dwUnlockTransferRate == 3)) self.failUnless((c.dwPlayCpuOverhead == 4))
'DSCCAPS type'
def test_1_Type(self):
c = ds.DSCCAPS() self.failUnless((type(c) == ds.DSCCAPSType))
'DSCCAPS attribute access'
def test_2_Attr(self):
c = ds.DSCCAPS() c.dwFlags = 1 c.dwFormats = 2 c.dwChannels = 4 self.failUnless((c.dwFlags == 1)) self.failUnless((c.dwFormats == 2)) self.failUnless((c.dwChannels == 4))
'DSCBCAPS type'
def test_1_Type(self):
c = ds.DSCBCAPS() self.failUnless((type(c) == ds.DSCBCAPSType))
'DSCBCAPS attribute access'
def test_2_Attr(self):
c = ds.DSCBCAPS() c.dwFlags = 1 c.dwBufferBytes = 2 self.failUnless((c.dwFlags == 1)) self.failUnless((c.dwBufferBytes == 2))
'DSBUFFERDESC type'
def test_1_Type(self):
c = ds.DSBUFFERDESC() self.failUnless((type(c) == ds.DSBUFFERDESCType))
'DSBUFFERDESC attribute access'
def test_2_Attr(self):
c = ds.DSBUFFERDESC() c.dwFlags = 1 c.dwBufferBytes = 2 c.lpwfxFormat = pywintypes.WAVEFORMATEX() c.lpwfxFormat.wFormatTag = pywintypes.WAVE_FORMAT_PCM c.lpwfxFormat.nChannels = 2 c.lpwfxFormat.nSamplesPerSec = 44100 c.lpwfxFormat.nAvgBytesPerSec = 176400 c.lpwfxFormat.nBlockAlign = 4 c.lpwfxFormat.wBitsPerSample = 16 self.failUnless((c.dwFlags == 1)) self.failUnless((c.dwBufferBytes == 2)) self.failUnless((c.lpwfxFormat.wFormatTag == 1)) self.failUnless((c.lpwfxFormat.nChannels == 2)) self.failUnless((c.lpwfxFormat.nSamplesPerSec == 44100)) self.failUnless((c.lpwfxFormat.nAvgBytesPerSec == 176400)) self.failUnless((c.lpwfxFormat.nBlockAlign == 4)) self.failUnless((c.lpwfxFormat.wBitsPerSample == 16))
'DSBUFFERDESC invalid lpwfxFormat assignment'
def test_3_invalid_format(self):
c = ds.DSBUFFERDESC() self.failUnlessRaises(ValueError, self.invalid_format, c)
'DSCBUFFERDESC type'
def test_1_Type(self):
c = ds.DSCBUFFERDESC() self.failUnless((type(c) == ds.DSCBUFFERDESCType))
'DSCBUFFERDESC attribute access'
def test_2_Attr(self):
c = ds.DSCBUFFERDESC() c.dwFlags = 1 c.dwBufferBytes = 2 c.lpwfxFormat = pywintypes.WAVEFORMATEX() c.lpwfxFormat.wFormatTag = pywintypes.WAVE_FORMAT_PCM c.lpwfxFormat.nChannels = 2 c.lpwfxFormat.nSamplesPerSec = 44100 c.lpwfxFormat.nAvgBytesPerSec = 176400 c.lpwfxFormat.nBlockAlign = 4 c.lpwfxFormat.wBitsPerSample = 16 self.failUnless((c.dwFlags == 1)) self.failUnless((c.dwBufferBytes == 2)) self.failUnless((c.lpwfxFormat.wFormatTag == 1)) self.failUnless((c.lpwfxFormat.nChannels == 2)) self.failUnless((c.lpwfxFormat.nSamplesPerSec == 44100)) self.failUnless((c.lpwfxFormat.nAvgBytesPerSec == 176400)) self.failUnless((c.lpwfxFormat.nBlockAlign == 4)) self.failUnless((c.lpwfxFormat.wBitsPerSample == 16))
'DSCBUFFERDESC invalid lpwfxFormat assignment'
def test_3_invalid_format(self):
c = ds.DSCBUFFERDESC() self.failUnlessRaises(ValueError, self.invalid_format, c)
'DirectSoundEnumerate() sanity tests'
def testEnumerate(self):
devices = ds.DirectSoundEnumerate() self.failUnless(len(devices)) self.failUnless((len(devices[0]) == 3))
'DirectSoundCreate()'
def testCreate(self):
d = ds.DirectSoundCreate(None, None)
'Mesdames et Messieurs, la cour de Devin Dazzle'
def testPlay(self):
candidates = [os.path.dirname(__file__), os.path.dirname(sys.argv[0]), os.path.join(os.path.dirname(sys.argv[0]), '../../win32comext/directsound/test'), '.'] for candidate in candidates: fname = os.path.join(candidate, '01-Intro.wav') if os.path.isfile(fname): break else: raise TestSkipped("Can't find test .wav file to play") f = open(fname, 'rb') hdr = f.read(WAV_HEADER_SIZE) (wfx, size) = wav_header_unpack(hdr) d = ds.DirectSoundCreate(None, None) d.SetCooperativeLevel(None, ds.DSSCL_PRIORITY) sdesc = ds.DSBUFFERDESC() sdesc.dwFlags = (ds.DSBCAPS_STICKYFOCUS | ds.DSBCAPS_CTRLPOSITIONNOTIFY) sdesc.dwBufferBytes = size sdesc.lpwfxFormat = wfx buffer = d.CreateSoundBuffer(sdesc, None) event = win32event.CreateEvent(None, 0, 0, None) notify = buffer.QueryInterface(ds.IID_IDirectSoundNotify) notify.SetNotificationPositions((ds.DSBPN_OFFSETSTOP, event)) buffer.Update(0, f.read(size)) buffer.Play(0) win32event.WaitForSingleObject(event, (-1))
'DirectSoundCaptureEnumerate() sanity tests'
def testEnumerate(self):
devices = ds.DirectSoundCaptureEnumerate() self.failUnless(len(devices)) self.failUnless((len(devices[0]) == 3))
'DirectSoundCreate()'
def testCreate(self):
d = ds.DirectSoundCaptureCreate(None, None)
'See if the file is a structured storage file or a normal file and then return an ifilter interface by calling the appropriate bind/load function'
def _bind_to_filter(self, fileName):
if pythoncom.StgIsStorageFile(fileName): self.stg = pythoncom.StgOpenStorage(fileName, None, (storagecon.STGM_READ | storagecon.STGM_SHARE_DENY_WRITE)) try: self.f = ifilter.BindIFilterFromStorage(self.stg) except pythoncom.com_error as e: if (e[0] == (-2147467262)): self.f = ifilter.LoadIFilter(fileName) else: raise else: self.f = ifilter.LoadIFilter(fileName) self.stg = None
'Gets all the text for a particular chunk. We need to keep calling get text till all the segments for this chunk are retrieved'
def _get_text(self, body_chunks):
while True: try: body_chunks.append(self.f.GetText()) except pythoncom.com_error as e: if (e[0] in [FILTER_E_NO_MORE_TEXT, FILTER_E_NO_MORE_TEXT, FILTER_E_NO_TEXT]): break else: raise
'Use OLE property sets to get base properties'
def _get_properties(self, properties):
try: pss = self.stg.QueryInterface(pythoncom.IID_IPropertySetStorage) except pythoncom.com_error as e: self._trace('No Property information could be retrieved', e) return ps = pss.Open(PSGUID_SUMMARYINFORMATION) props = (PIDSI_TITLE, PIDSI_SUBJECT, PIDSI_AUTHOR, PIDSI_KEYWORDS, PIDSI_COMMENTS) (title, subject, author, keywords, comments) = ps.ReadMultiple(props) if (title is not None): properties['title'] = title if (subject is not None): properties['description'] = subject if (author is not None): properties['author'] = author if (keywords is not None): properties['keywords'] = keywords if (comments is not None): properties['comments'] = comments
'Returns the thread associated with this stack frame. Result must be a IDebugApplicationThread'
def GetThread(self):
RaiseNotImpl('GetThread')
'Get ready for potential debugging. Must be called on the thread that is being debugged.'
def SetupAXDebugging(self, baseFrame=None, userFrame=None):
if (userFrame is None): userFrame = baseFrame else: userFrame.f_locals['__axstack_address__'] = axdebug.GetStackAddress() traceenter('SetupAXDebugging', self) self._threadprotectlock.acquire() try: thisThread = win32api.GetCurrentThreadId() if (self.debuggingThread is None): self.debuggingThread = thisThread else: if (self.debuggingThread != thisThread): trace('SetupAXDebugging called on other thread - ignored!') return self.recursiveData.insert(0, (self.logicalbotframe, self.stopframe, self.currentframe, self.debuggingThreadStateHandle)) finally: self._threadprotectlock.release() trace('SetupAXDebugging has base frame as', _dumpf(baseFrame)) self.botframe = baseFrame self.stopframe = userFrame self.logicalbotframe = baseFrame self.currentframe = None self.debuggingThreadStateHandle = axdebug.GetThreadStateHandle() self._BreakFlagsChanged()
'Get the one of the name of the document dnt -- int DOCUMENTNAMETYPE'
def GetName(self, dnt):
RaiseNotImpl('GetName')
'Result must be an IID object (or string representing one).'
def GetDocumentClassId(self):
RaiseNotImpl('GetDocumentClassId')
'Params charPos -- integer maxChars -- integer wantAttr -- Should the function compute attributes. Return value must be (string, attribtues). attributes may be None if(not wantAttr)'
def GetText(self, charPos, maxChars, wantAttr):
RaiseNotImpl('GetText')
'Params debugDocumentContext -- a PyIDebugDocumentContext object. Return value must be (charPos, numChars)'
def GetPositionOfContext(self, debugDocumentContext):
RaiseNotImpl('GetPositionOfContext')
'Params are integers. Return value must be PyIDebugDocumentContext object'
def GetContextOfPosition(self, charPos, maxChars):
print self RaiseNotImpl('GetContextOfPosition')
'Return the full path (including file name) to the document\'s source file. Result must be (filename, fIsOriginal), where - if fIsOriginalPath is TRUE if the path refers to the original file for the document. - if fIsOriginalPath is FALSE if the path refers to a newly created temporary file. raise Exception(winerror.E_FAIL) if no source file can be created/determined.'
def GetPathName(self):
RaiseNotImpl('GetPathName')
'Return just the name of the document, with no path information. (Used for "Save As...") Result is a string'
def GetFileName(self):
RaiseNotImpl('GetFileName')
'Notify the host that the document\'s source file has been saved and that its contents should be refreshed.'
def NotifyChanged(self):
RaiseNotImpl('NotifyChanged')
'Return value must be a PyIDebugDocument object'
def GetDocument(self):
RaiseNotImpl('GetDocument')
'Return value must be a PyIEnumDebugCodeContexts object'
def EnumCodeContexts(self):
RaiseNotImpl('EnumCodeContexts')
'Return value must be a PyIDebugDocumentContext object'
def GetDocumentContext(self):
RaiseNotImpl('GetDocumentContext')
'bps -- an integer with flags.'
def SetBreakPoint(self, bps):
RaiseNotImpl('SetBreakPoint')
'Returns the current code context associated with the stack frame. Return value must be a IDebugCodeContext object'
def GetCodeContext(self):
RaiseNotImpl('GetCodeContext')
'Returns a textual description of the stack frame. fLong -- A flag indicating if the long name is requested.'
def GetDescriptionString(self, fLong):
RaiseNotImpl('GetDescriptionString')
'Returns a short or long textual description of the language. fLong -- A flag indicating if the long name is requested.'
def GetLanguageString(self):
RaiseNotImpl('GetLanguageString')
'Returns the thread associated with this stack frame. Result must be a IDebugApplicationThread'
def GetThread(self):
RaiseNotImpl('GetThread')
'appDebugger -- a PyIApplicationDebugger'
def OnConnectDebugger(self, appDebugger):
RaiseNotImpl('OnConnectDebugger')
'rdat -- PyIRemoteDebugApplicationThread'
def OnEnterBreakPoint(self, rdat):
RaiseNotImpl('OnEnterBreakPoint')
'rdat -- PyIRemoteDebugApplicationThread'
def OnLeaveBreakPoint(self, rdat):
RaiseNotImpl('OnLeaveBreakPoint')
'rdat -- PyIRemoteDebugApplicationThread'
def OnCreateThread(self, rdat):
RaiseNotImpl('OnCreateThread')
'rdat -- PyIRemoteDebugApplicationThread'
def OnDestroyThread(self, rdat):
RaiseNotImpl('OnDestroyThread')
'result is IDebugExpression'
def ParseLanguageText(self, code, radix, delim, flags):
RaiseNotImpl('ParseLanguageText')
'result is (string langName, iid langId)'
def GetLanguageInfo(self):
RaiseNotImpl('GetLanguageInfo')
'callback -- an IDebugExpressionCallback result - void'
def Start(self, callback):
RaiseNotImpl('Start')
'no params result -- void'
def Abort(self):
RaiseNotImpl('Abort')
'no params result -- void'
def QueryIsComplete(self):
RaiseNotImpl('QueryIsComplete')
'Identifies object whose security will be modified, and determines options available to the end user'
def GetObjectInformation(self):
flags = (((SI_ADVANCED | SI_EDIT_ALL) | SI_PAGE_TITLE) | SI_RESET) if os.path.isdir(self.FileName): flags |= SI_CONTAINER hinstance = 0 servername = '' objectname = os.path.split(self.FileName)[1] pagetitle = 'Python ACL Editor' if os.path.isdir(self.FileName): pagetitle += ' (dir)' else: pagetitle += ' (file)' objecttype = IID_NULL return (flags, hinstance, servername, objectname, pagetitle, objecttype)
'Requests the existing permissions for object'
def GetSecurity(self, requestedinfo, bdefault):
if bdefault: return win32security.SECURITY_DESCRIPTOR() else: return win32security.GetNamedSecurityInfo(self.FileName, win32security.SE_FILE_OBJECT, requestedinfo)
'Applies permissions to the object'
def SetSecurity(self, requestedinfo, sd):
owner = sd.GetSecurityDescriptorOwner() group = sd.GetSecurityDescriptorGroup() dacl = sd.GetSecurityDescriptorDacl() sacl = sd.GetSecurityDescriptorSacl() win32security.SetNamedSecurityInfo(self.FileName, win32security.SE_FILE_OBJECT, requestedinfo, owner, group, dacl, sacl)
'Returns a tuple of (AccessRights, DefaultAccess), where AccessRights is a sequence of tuples representing SI_ACCESS structs, containing (guid, access mask, Name, flags). DefaultAccess indicates which of the AccessRights will be used initially when a new ACE is added (zero based). Flags can contain SI_ACCESS_SPECIFIC,SI_ACCESS_GENERAL,SI_ACCESS_CONTAINER,SI_ACCESS_PROPERTY, CONTAINER_INHERIT_ACE,INHERIT_ONLY_ACE,OBJECT_INHERIT_ACE'
def GetAccessRights(self, objecttype, flags):
if ((objecttype is not None) and (objecttype != IID_NULL)): raise NotImplementedError('Object type is not supported') if os.path.isdir(self.FileName): file_append_data_desc = 'Create subfolders' file_write_data_desc = 'Create Files' else: file_append_data_desc = 'Append data' file_write_data_desc = 'Write data' accessrights = [(IID_NULL, FILE_GENERIC_READ, 'Generic read', (((SI_ACCESS_GENERAL | SI_ACCESS_SPECIFIC) | OBJECT_INHERIT_ACE) | CONTAINER_INHERIT_ACE)), (IID_NULL, FILE_GENERIC_WRITE, 'Generic write', (((SI_ACCESS_GENERAL | SI_ACCESS_SPECIFIC) | OBJECT_INHERIT_ACE) | CONTAINER_INHERIT_ACE)), (IID_NULL, win32con.DELETE, 'Delete', ((SI_ACCESS_SPECIFIC | OBJECT_INHERIT_ACE) | CONTAINER_INHERIT_ACE)), (IID_NULL, WRITE_OWNER, 'Change owner', ((SI_ACCESS_SPECIFIC | OBJECT_INHERIT_ACE) | CONTAINER_INHERIT_ACE)), (IID_NULL, READ_CONTROL, 'Read Permissions', ((SI_ACCESS_SPECIFIC | OBJECT_INHERIT_ACE) | CONTAINER_INHERIT_ACE)), (IID_NULL, WRITE_DAC, 'Change permissions', ((SI_ACCESS_SPECIFIC | OBJECT_INHERIT_ACE) | CONTAINER_INHERIT_ACE)), (IID_NULL, FILE_APPEND_DATA, file_append_data_desc, ((SI_ACCESS_SPECIFIC | OBJECT_INHERIT_ACE) | CONTAINER_INHERIT_ACE)), (IID_NULL, FILE_WRITE_DATA, file_write_data_desc, ((SI_ACCESS_SPECIFIC | OBJECT_INHERIT_ACE) | CONTAINER_INHERIT_ACE))] return (accessrights, 0)
'Converts generic access rights to specific rights. This implementation uses standard file system rights, but you can map them any way that suits your application.'
def MapGeneric(self, guid, aceflags, mask):
return win32security.MapGenericMask(mask, (FILE_GENERIC_READ, FILE_GENERIC_WRITE, FILE_GENERIC_EXECUTE, FILE_ALL_ACCESS))
'Specifies which types of ACE inheritance are supported. Returns a sequence of tuples representing SI_INHERIT_TYPE structs, containing (object type guid, inheritance flags, display name). Guid is usually only used with Directory Service objects.'
def GetInheritTypes(self):
return ((IID_NULL, 0, 'Only current object'), (IID_NULL, OBJECT_INHERIT_ACE, 'Files inherit permissions'), (IID_NULL, CONTAINER_INHERIT_ACE, 'Sub Folders inherit permissions'), (IID_NULL, (CONTAINER_INHERIT_ACE | OBJECT_INHERIT_ACE), 'Files and subfolders'))
'Invoked each time a property sheet page is created or destroyed.'
def PropertySheetPageCallback(self, hwnd, msg, pagetype):
return None
'Creates an ACL editor dialog based on parameters returned by interface methods'
def EditSecurity(self, owner_hwnd=0):
isi = pythoncom.WrapObject(self, authorization.IID_ISecurityInformation, pythoncom.IID_IUnknown) authorization.EditSecurity(owner_hwnd, isi)
'Identifies object whose security will be modified, and determines options available to the end user'
def GetObjectInformation(self):
flags = (((SI_ADVANCED | SI_EDIT_ALL) | SI_PAGE_TITLE) | SI_RESET) hinstance = 0 servername = '' objectname = os.path.split(self.ServiceName)[1] pagetitle = ('Service Permissions for ' + self.ServiceName) objecttype = IID_NULL return (flags, hinstance, servername, objectname, pagetitle, objecttype)
'Requests the existing permissions for object'
def GetSecurity(self, requestedinfo, bdefault):
if bdefault: return win32security.SECURITY_DESCRIPTOR() else: return win32security.GetNamedSecurityInfo(self.ServiceName, win32security.SE_SERVICE, requestedinfo)
'Applies permissions to the object'
def SetSecurity(self, requestedinfo, sd):
owner = sd.GetSecurityDescriptorOwner() group = sd.GetSecurityDescriptorGroup() dacl = sd.GetSecurityDescriptorDacl() sacl = sd.GetSecurityDescriptorSacl() win32security.SetNamedSecurityInfo(self.ServiceName, win32security.SE_SERVICE, requestedinfo, owner, group, dacl, sacl)
'Returns a tuple of (AccessRights, DefaultAccess), where AccessRights is a sequence of tuples representing SI_ACCESS structs, containing (guid, access mask, Name, flags). DefaultAccess indicates which of the AccessRights will be used initially when a new ACE is added (zero based). Flags can contain SI_ACCESS_SPECIFIC,SI_ACCESS_GENERAL,SI_ACCESS_CONTAINER,SI_ACCESS_PROPERTY, CONTAINER_INHERIT_ACE,INHERIT_ONLY_ACE,OBJECT_INHERIT_ACE'
def GetAccessRights(self, objecttype, flags):
if ((objecttype is not None) and (objecttype != IID_NULL)): raise NotImplementedError('Object type is not supported') accessrights = [(IID_NULL, win32service.SERVICE_ALL_ACCESS, 'Full control', SI_ACCESS_GENERAL), (IID_NULL, SERVICE_GENERIC_READ, 'Generic read', SI_ACCESS_GENERAL), (IID_NULL, SERVICE_GENERIC_WRITE, 'Generic write', SI_ACCESS_GENERAL), (IID_NULL, SERVICE_GENERIC_EXECUTE, 'Start/Stop/Pause service', SI_ACCESS_GENERAL), (IID_NULL, READ_CONTROL, 'Read Permissions', SI_ACCESS_GENERAL), (IID_NULL, WRITE_DAC, 'Change permissions', SI_ACCESS_GENERAL), (IID_NULL, WRITE_OWNER, 'Change owner', SI_ACCESS_GENERAL), (IID_NULL, win32con.DELETE, 'Delete service', SI_ACCESS_GENERAL), (IID_NULL, win32service.SERVICE_START, 'Start service', SI_ACCESS_SPECIFIC), (IID_NULL, win32service.SERVICE_STOP, 'Stop service', SI_ACCESS_SPECIFIC), (IID_NULL, win32service.SERVICE_PAUSE_CONTINUE, 'Pause/unpause service', SI_ACCESS_SPECIFIC), (IID_NULL, win32service.SERVICE_USER_DEFINED_CONTROL, 'Execute user defined operations', SI_ACCESS_SPECIFIC), (IID_NULL, win32service.SERVICE_QUERY_CONFIG, 'Read configuration', SI_ACCESS_SPECIFIC), (IID_NULL, win32service.SERVICE_CHANGE_CONFIG, 'Change configuration', SI_ACCESS_SPECIFIC), (IID_NULL, win32service.SERVICE_ENUMERATE_DEPENDENTS, 'List dependent services', SI_ACCESS_SPECIFIC), (IID_NULL, win32service.SERVICE_QUERY_STATUS, 'Query status', SI_ACCESS_SPECIFIC), (IID_NULL, win32service.SERVICE_INTERROGATE, 'Query status (immediate)', SI_ACCESS_SPECIFIC)] return (accessrights, 0)
'Converts generic access rights to specific rights.'
def MapGeneric(self, guid, aceflags, mask):
return win32security.MapGenericMask(mask, (SERVICE_GENERIC_READ, SERVICE_GENERIC_WRITE, SERVICE_GENERIC_EXECUTE, win32service.SERVICE_ALL_ACCESS))
'Specifies which types of ACE inheritance are supported. Services don\'t use any inheritance'
def GetInheritTypes(self):
return ((IID_NULL, 0, 'Only current object'),)
'Invoked each time a property sheet page is created or destroyed.'
def PropertySheetPageCallback(self, hwnd, msg, pagetype):
return None
'Creates an ACL editor dialog based on parameters returned by interface methods'
def EditSecurity(self, owner_hwnd=0):
isi = pythoncom.WrapObject(self, authorization.IID_ISecurityInformation, pythoncom.IID_IUnknown) authorization.EditSecurity(owner_hwnd, isi)
'If the window is minimised or maximised, restore it.'
def AutoRestore(self):
p = self.GetWindowPlacement() if ((p[1] == win32con.SW_MINIMIZE) or (p[1] == win32con.SW_SHOWMINIMIZED)): self.SetWindowPlacement(p[0], win32con.SW_RESTORE, p[2], p[3], p[4])
'Returns a list of property pages'
def GetPythonPropertyPages(self):
import configui return [configui.EditorPropertyPage(), configui.EditorWhitespacePropertyPage()]
'Reloads the document from disk. Assumes the file has been saved and user has been asked if necessary - it just does it!'
def ReloadDocument(self):
win32ui.SetStatusText('Reloading document. Please wait...', 1) self.SetModifiedFlag(0) views = self.GetAllViews() states = [] for view in views: try: info = view._PrepareUserStateChange() except AttributeError: info = None states.append(info) self.OnOpenDocument(self.GetPathName()) for (view, info) in zip(views, states): if (info is not None): view._EndUserStateChange(info) self._DocumentStateChanged() win32ui.SetStatusText('Document reloaded.')
'Called whenever the documents state (on disk etc) has been changed by the editor (eg, as the result of a save operation)'
def _DocumentStateChanged(self):
if self.GetPathName(): try: self.fileStat = os.stat(self.GetPathName()) except os.error: self.fileStat = None else: self.fileStat = None self.watcherThread._DocumentStateChanged() self._UpdateUIForState() self._ApplyOptionalToViews('_UpdateUIForState') self._ApplyOptionalToViews('SetReadOnly', self._IsReadOnly()) self._ApplyOptionalToViews('SCISetSavePoint') import pywin.debugger if (pywin.debugger.currentDebugger is not None): pywin.debugger.currentDebugger.UpdateDocumentLineStates(self)
'Change the title to reflect the state of the document - eg ReadOnly, Dirty, etc'
def _UpdateUIForState(self):
filename = self.GetPathName() if (not filename): return try: self.GetFirstView().ShowWindow(win32con.SW_SHOW) title = win32ui.GetFileTitle(filename) except win32ui.error: title = filename if self._IsReadOnly(): title = (title + ' (read-only)') self.SetTitle(title)
'Given raw data read from a file, massage it suitable for the edit window'
def TranslateLoadedData(self, data):
if (data[:250].find('\r') == (-1)): win32ui.SetStatusText('Translating from Unix file format - please wait...', 1) return re.sub('\r*\n', '\r\n', data) else: return data
'Color a line of all views'
def SetLineColor(self, lineNo, color):
for view in self.GetAllViews(): view.SetLineColor(lineNo, color)
'Return selection, lineindex, etc info, so it can be restored'
def _PrepareUserStateChange(self):
self.SetRedraw(0) return (self.GetModify(), self.GetSel(), self.GetFirstVisibleLine())
'lineNo is the 1 based line number to set. If color is None, default color is used.'
def SetLineColor(self, lineNo, color):
if isRichText: info = self._PrepareUserStateChange() try: if (color is None): color = self.defCharFormat[4] lineNo = (lineNo - 1) startIndex = self.LineIndex(lineNo) if (startIndex != (-1)): self.SetSel(startIndex, self.LineIndex((lineNo + 1))) self.SetSelectionCharFormat((win32con.CFM_COLOR, 0, 0, 0, color)) finally: self._EndUserStateChange(info)
'Insert an indent to move the cursor to the next tab position. Honors the tab size and \'use tabs\' settings. Assumes the cursor is already at the position to be indented, and the selection is a single character (ie, not a block)'
def Indent(self):
(start, end) = self._obj_.GetSel() startLine = self._obj_.LineFromChar(start) line = self._obj_.GetLine(startLine) realCol = (start - self._obj_.LineIndex(startLine)) curCol = 0 for ch in line[:realCol]: if (ch == ' DCTB '): curCol = (((curCol / self.tabSize) + 1) * self.tabSize) else: curCol = (curCol + 1) nextColumn = (((curCol / self.indentSize) + 1) * self.indentSize) ins = None if self.bSmartTabs: if (realCol == 0): lookLine = (startLine - 1) while (lookLine >= 0): check = self._obj_.GetLine(lookLine)[0:1] if (check in [' DCTB ', ' ']): ins = check break lookLine = (lookLine - 1) else: check = line[(realCol - 1)] if (check in [' DCTB ', ' ']): ins = check if (ins is None): if (self.bUseTabs and ((nextColumn % self.tabSize) == 0)): ins = ' DCTB ' else: ins = ' ' if (ins == ' '): ins = (ins * (nextColumn - curCol)) self._obj_.ReplaceSel(ins)
'Indent/Undent all lines specified'
def BlockDent(self, isIndent, startLine, endLine):
if (not self.GetDocument().CheckMakeDocumentWritable()): return 0 tabSize = self.tabSize info = self._PrepareUserStateChange() try: for lineNo in range(startLine, endLine): pos = self._obj_.LineIndex(lineNo) self._obj_.SetSel(pos, pos) if isIndent: self.Indent() else: line = self._obj_.GetLine(lineNo) try: noToDel = 0 if (line[0] == ' DCTB '): noToDel = 1 elif (line[0] == ' '): for noToDel in range(0, tabSize): if (line[noToDel] != ' '): break else: noToDel = tabSize if noToDel: self._obj_.SetSel(pos, (pos + noToDel)) self._obj_.Clear() except IndexError: pass finally: self._EndUserStateChange(info) self.GetDocument().SetModifiedFlag(1) self._obj_.SetSel(self.LineIndex(startLine), self.LineIndex(endLine))
'Toggle a bookmark at the specified or current position'
def ToggleBookmarkEvent(self, event, pos=(-1)):
if (pos == (-1)): (pos, end) = self.GetSel() startLine = self.LineFromChar(pos) self.GetDocument().MarkerToggle((startLine + 1), MARKER_BOOKMARK) return 0