Skip to content

Commit 831df1a

Browse files
committed
Cleanup win32comext.axdebug
1 parent 03a8bb1 commit 831df1a

12 files changed

Lines changed: 93 additions & 192 deletions

File tree

com/win32comext/axdebug/Test/host.py

Lines changed: 10 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,9 @@
33

44
import pythoncom
55
import win32api
6-
import win32com.server.util
76
import winerror
8-
from win32com.axdebug import adb, axdebug, codecontainer, contexts, documents, gateways
9-
from win32com.axdebug.util import _wrap, _wrap_remove, trace
10-
from win32com.axscript import axscript
11-
from win32com.client.util import Enumerator
7+
from win32com.axdebug import codecontainer, gateways
8+
from win32com.axdebug.util import _wrap, trace
129
from win32com.server.exception import Exception
1310

1411

@@ -26,8 +23,10 @@ def ReleaseConnection(self, extconn, reserved, fLastReleaseCloses):
2623
return self.numExtRefs
2724

2825

29-
# externalConnectionManager = ExternalConnection()
30-
# wrappedExternalConnectionManager = _wrap(externalConnectionManager, pythoncom.IID_IExternalConnection)
26+
externalConnectionManager = ExternalConnection()
27+
wrappedExternalConnectionManager = _wrap(
28+
externalConnectionManager, pythoncom.IID_IExternalConnection
29+
)
3130

3231

3332
def DelegatedExternalConnectionQI(iid):
@@ -97,71 +96,25 @@ def GetPathName(self):
9796
try:
9897
return win32api.GetFullPathName(self.module.__file__), 1
9998
except (AttributeError, win32api.error):
100-
raise Exception(scode == E_FAIL)
99+
raise Exception(scode=winerror.E_FAIL)
101100

102101
def GetFileName(self):
103102
# Result is a string with just the name of the document, no path information.
104103
trace("GetFileName")
105-
return os.path.split(module.__file__)
104+
return os.path.split(self.module.__file__)
106105

107106
def NotifyChanged():
108107
trace("NotifyChanged")
109108
raise Exception(scode=winerror.E_NOTIMPL)
110109

111110

112-
def TestSmartHelper():
113-
pdm = pythoncom.CoCreateInstance(
114-
axdebug.CLSID_ProcessDebugManager,
115-
None,
116-
pythoncom.CLSCTX_ALL,
117-
axdebug.IID_IProcessDebugManager,
118-
)
119-
app = pdm.CreateApplication()
120-
app.SetName("Python Process")
121-
122-
pydebugger = adb.Debugger()
123-
124-
nodes = BuildModuleTree()
125-
126-
all_real_nodes = CreateDebugDocumentHelperNodes(pdm, app, nodes)
127-
root = app.GetRootNode()
128-
AttachParentNodes(root, nodes, all_real_nodes)
129-
130-
pydebugger.AttachApp(app)
131-
cookie = pdm.AddApplication(app)
132-
input("Waiting...")
133-
ttest.test()
134-
135-
pdm.RemoveApplication(cookie)
136-
print("Done")
137-
138-
139-
def testdumb():
140-
pdm = pythoncom.CoCreateInstance(
141-
axdebug.CLSID_ProcessDebugManager,
142-
None,
143-
pythoncom.CLSCTX_ALL,
144-
axdebug.IID_IProcessDebugManager,
145-
)
146-
app = pdm.GetDefaultApplication()
147-
148-
nodes = BuildModuleTree()
149-
all_real_nodes = CreateDebugDocumentHelperNodes(pdm, app, nodes)
150-
AttachParentNodes(None, nodes, all_real_nodes)
151-
152-
parentNode = None
153-
all_real_nodes = {}
154-
input("Waiting...")
155-
print("Done")
156-
157-
158111
def TestSmartProvider():
159112
import ttest
160113
from win32com.axdebug import debugger
161114

162115
d = debugger.AXDebugger()
163-
# d.StartDebugger()
164-
# d.Attach()
116+
# d.StartDebugger()
117+
# d.Attach()
165118
d.Break()
166119
input("Waiting...")
167120
ttest.test()
@@ -171,21 +124,13 @@ def TestSmartProvider():
171124

172125
def test():
173126
try:
174-
# app = TestSmartHelper()
175127
app = TestSmartProvider()
176-
# app = testdumb()
177128
except:
178129
traceback.print_exc()
179130

180131

181-
# _wrap_remove(externalConnectionManager)
182-
# wrappedExternalConnectionManager = None
183-
184132
if __name__ == "__main__":
185133
test()
186-
import win32com.axdebug.util
187-
188-
win32com.axdebug.util._dump_wrapped()
189134
print(
190135
" %d/%d com objects still alive"
191136
% (pythoncom._GetInterfaceCount(), pythoncom._GetGatewayCount())

com/win32comext/axdebug/adb.py

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
import pythoncom
1010
import win32api
1111
import win32com.client.connect
12-
from win32com.axdebug.util import _wrap, _wrap_remove, trace
13-
from win32com.server.util import unwrap
12+
from win32com.axdebug.util import _wrap, trace
1413

1514
from . import axdebug, gateways, stackframe
1615

@@ -118,8 +117,8 @@ def __xxxxx__set_break(self, filename, lineno, cond=None):
118117
def stop_here(self, frame):
119118
traceenter("stop_here", _dumpf(frame), _dumpf(self.stopframe))
120119
# As per bdb.stop_here, except for logicalbotframe
121-
## if self.stopframe is None:
122-
## return 1
120+
# if self.stopframe is None:
121+
# return 1
123122
if frame is self.stopframe:
124123
return 1
125124

@@ -157,13 +156,13 @@ def dispatch_return(self, frame, arg):
157156
tracev("dispatch_return resetting sys.trace")
158157
sys.settrace(None)
159158
return
160-
# self.bSetTrace = 0
159+
# self.bSetTrace = 0
161160
self.currentframe = frame.f_back
162161
return bdb.Bdb.dispatch_return(self, frame, arg)
163162

164163
def dispatch_line(self, frame):
165164
traceenter("dispatch_line", _dumpf(frame), _dumpf(self.botframe))
166-
# trace("logbotframe is", _dumpf(self.logicalbotframe), "botframe is", self.botframe)
165+
# trace("logbotframe is", _dumpf(self.logicalbotframe), "botframe is", self.botframe)
167166
if frame is self.logicalbotframe:
168167
trace("dispatch_line", _dumpf(frame), "for bottom frame returing tracer")
169168
# The next code executed in the frame above may be a builtin (eg, apply())
@@ -195,13 +194,13 @@ def dispatch_call(self, frame, arg):
195194
trace(
196195
"dispatch_call has no document for", _dumpf(frame), "- skipping trace!"
197196
)
198-
## sys.settrace(None)
197+
# sys.settrace(None)
199198
return None
200199
return self.trace_dispatch
201200

202-
# rc = bdb.Bdb.dispatch_call(self, frame, arg)
203-
# trace("dispatch_call", _dumpf(frame),"returned",rc)
204-
# return rc
201+
# rc = bdb.Bdb.dispatch_call(self, frame, arg)
202+
# trace("dispatch_call", _dumpf(frame),"returned",rc)
203+
# return rc
205204

206205
def trace_dispatch(self, frame, event, arg):
207206
traceenter("trace_dispatch", _dumpf(frame), event, arg)
@@ -213,8 +212,8 @@ def trace_dispatch(self, frame, event, arg):
213212
#
214213
# The user functions do bugger all!
215214
#
216-
# def user_call(self, frame, argument_list):
217-
# traceenter("user_call",_dumpf(frame))
215+
# def user_call(self, frame, argument_list):
216+
# traceenter("user_call",_dumpf(frame))
218217

219218
def user_line(self, frame):
220219
traceenter("user_line", _dumpf(frame))
@@ -226,11 +225,11 @@ def user_line(self, frame):
226225
self._HandleBreakPoint(frame, None, breakReason)
227226

228227
def user_return(self, frame, return_value):
229-
# traceenter("user_return",_dumpf(frame),return_value)
228+
# traceenter("user_return",_dumpf(frame),return_value)
230229
bdb.Bdb.user_return(self, frame, return_value)
231230

232231
def user_exception(self, frame, exc_info):
233-
# traceenter("user_exception")
232+
# traceenter("user_exception")
234233
bdb.Bdb.user_exception(self, frame, exc_info)
235234

236235
def _HandleBreakPoint(self, frame, tb, reason):
@@ -284,8 +283,6 @@ def CloseApp(self):
284283
"*** Could not RemoveStackFrameSniffer %d"
285284
% (self.stackSnifferCookie)
286285
)
287-
if self.stackSniffer:
288-
_wrap_remove(self.stackSniffer)
289286
self.stackSnifferCookie = self.stackSniffer = None
290287

291288
if self.appEventConnection is not None:
@@ -298,7 +295,7 @@ def CloseApp(self):
298295
self.codeContainerProvider = None
299296

300297
def AttachApp(self, debugApplication, codeContainerProvider):
301-
# traceenter("AttachApp", debugApplication, codeContainerProvider)
298+
# traceenter("AttachApp", debugApplication, codeContainerProvider)
302299
self.codeContainerProvider = codeContainerProvider
303300
self.debugApplication = debugApplication
304301
self.stackSniffer = _wrap(
@@ -307,7 +304,7 @@ def AttachApp(self, debugApplication, codeContainerProvider):
307304
self.stackSnifferCookie = debugApplication.AddStackFrameSniffer(
308305
self.stackSniffer
309306
)
310-
# trace("StackFrameSniffer added (%d)" % self.stackSnifferCookie)
307+
# trace("StackFrameSniffer added (%d)" % self.stackSnifferCookie)
311308

312309
# Connect to the application events.
313310
self.appEventConnection = win32com.client.connect.SimpleConnection(
@@ -321,7 +318,7 @@ def ResetAXDebugging(self):
321318
return
322319

323320
if len(self.recursiveData) == 0:
324-
# print "ResetAXDebugging called for final time."
321+
# print("ResetAXDebugging called for final time.")
325322
self.logicalbotframe = None
326323
self.debuggingThread = None
327324
self.currentframe = None
@@ -432,8 +429,8 @@ def _BreakFlagsChanged(self):
432429
)
433430
trace("_BreakFlagsChanged has breaks", self.breaks)
434431
# If a request comes on our debugging thread, then do it now!
435-
# if self.debuggingThread!=win32api.GetCurrentThreadId():
436-
# return
432+
# if self.debuggingThread!=win32api.GetCurrentThreadId():
433+
# return
437434

438435
if len(self.breaks) or self.breakFlags:
439436
if self.logicalbotframe:

com/win32comext/axdebug/codecontainer.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,16 @@
44
to color the text, and also how to translate lines into offsets, and back.
55
"""
66

7+
import os
78
import sys
89
import tokenize
910

1011
import win32api
1112
import winerror
12-
from win32com.axdebug import axdebug
13+
from win32com.axdebug import axdebug, contexts
14+
from win32com.axdebug.util import _wrap
1315
from win32com.server.exception import Exception
1416

15-
from . import contexts
16-
from .util import RaiseNotImpl, _wrap
17-
1817
_keywords = {} # set of Python keywords
1918
for name in """
2019
and assert break class continue def del elif else except exec
@@ -43,7 +42,7 @@ def __init__(
4342
self.codeContexts = {}
4443
self.site = site
4544
self.startLineNumber = startLineNumber
46-
self.debugDocument = None
45+
self.debugDocument = debugDocument
4746

4847
def _Close(self):
4948
self.text = self.lines = self.lineOffsets = None
@@ -78,9 +77,9 @@ def GetLineOfPosition(self, charPos):
7877
lastOffset = lineOffset
7978
lineNo = lineNo + 1
8079
else: # for not broken.
81-
# print "Cant find", charPos, "in", self.lineOffsets
80+
# print("Cant find", charPos, "in", self.lineOffsets)
8281
raise Exception(scode=winerror.S_FALSE)
83-
# print "GLOP ret=",lineNo, (charPos-lastOffset)
82+
# print("GLOP ret=", lineNo, (charPos - lastOffset))
8483
return lineNo, (charPos - lastOffset)
8584

8685
def GetNextLine(self):
@@ -187,13 +186,13 @@ def _MakeContextAtPosition(self, charPos):
187186

188187
# Returns a DebugCodeContext. debugDocument can be None for smart hosts.
189188
def GetCodeContextAtPosition(self, charPos):
190-
# trace("GetContextOfPos", charPos, maxChars)
189+
# trace("GetContextOfPos", charPos, maxChars)
191190
# Convert to line number.
192191
lineNo, offset = self.GetLineOfPosition(charPos)
193192
charPos = self.GetPositionOfLine(lineNo)
194193
try:
195194
cc = self.codeContexts[charPos]
196-
# trace(" GetContextOfPos using existing")
195+
# trace(" GetContextOfPos using existing")
197196
except KeyError:
198197
cc = self._MakeContextAtPosition(charPos)
199198
self.codeContexts[charPos] = cc
@@ -253,11 +252,10 @@ def GetName(self, dnt):
253252

254253

255254
if __name__ == "__main__":
256-
sys.path.append(".")
257-
import ttest
255+
from Test import ttest
258256

259257
sc = SourceModuleContainer(ttest)
260-
# sc = SourceCodeContainer(open(sys.argv[1], "rb").read(), sys.argv[1])
258+
# sc = SourceCodeContainer(open(sys.argv[1], "rb").read(), sys.argv[1])
261259
attrs = sc.GetSyntaxColorAttributes()
262260
attrlen = 0
263261
for attr in attrs:
@@ -269,8 +267,8 @@ def GetName(self, dnt):
269267
if attrlen != len(text):
270268
print("Lengths dont match!!! (%d/%d)" % (attrlen, len(text)))
271269

272-
# print "Attributes:"
273-
# print attrs
270+
# print("Attributes:")
271+
# print(attrs)
274272
print("GetLineOfPos=", sc.GetLineOfPosition(0))
275273
print("GetLineOfPos=", sc.GetLineOfPosition(4))
276274
print("GetLineOfPos=", sc.GetLineOfPosition(10))

com/win32comext/axdebug/contexts.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
""" A module for managing the AXDebug I*Contexts
22
33
"""
4-
import pythoncom
5-
import win32com.server.util
6-
74
from . import adb, axdebug, gateways
85

96
# Utility function for wrapping object created by this module.
10-
from .util import _wrap, _wrap_remove, trace
7+
from .util import _wrap
118

129

1310
class DebugCodeContext(gateways.DebugCodeContext, gateways.DebugDocumentContext):

0 commit comments

Comments
 (0)