[pywin32-checkins] /hgrepo/p/py/pywin32/pywin32: 2 new changesets
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: <pyw...@li...> - 2011-04-24 04:23:46
|
changeset 6696da02c761 in /hgrepo/p/py/pywin32/pywin32 details: http://pywin32.hg.sourceforge.net/hgweb/pywin32/pywin32/hgrepo/p/py/pywin32/pywin32?cmd=changeset;node=6696da02c761 summary: 3rd time lucky - do the right thing on py3k changeset 7f44ae5e7785 in /hgrepo/p/py/pywin32/pywin32 details: http://pywin32.hg.sourceforge.net/hgweb/pywin32/pywin32/hgrepo/p/py/pywin32/pywin32?cmd=changeset;node=7f44ae5e7785 summary: Fix win32com.client.WithEvents() on py3k (bug 3199843) diffstat: CHANGES.txt | 2 ++ com/win32com/client/__init__.py | 7 +++++-- com/win32com/client/build.py | 6 ++++-- com/win32com/test/testPyComTest.py | 35 +++++++++++++++++++++-------------- 4 files changed, 32 insertions(+), 18 deletions(-) diffs (100 lines): diff -r 816b080c336b -r 7f44ae5e7785 CHANGES.txt --- a/CHANGES.txt Sun Apr 24 13:31:45 2011 +1000 +++ b/CHANGES.txt Sun Apr 24 14:22:25 2011 +1000 @@ -13,6 +13,8 @@ raised) and unsigned integers now allow for values with the high-bit set to be passed correctly. +* Fix win32com.client.WithEvents() on py3k. + * makepy may have generated syntax errors if 'helpstring' elements in typelibs had strange quoting or slashes (bug 3199631) diff -r 816b080c336b -r 7f44ae5e7785 com/win32com/client/__init__.py --- a/com/win32com/client/__init__.py Sun Apr 24 13:31:45 2011 +1000 +++ b/com/win32com/client/__init__.py Sun Apr 24 14:22:25 2011 +1000 @@ -317,11 +317,14 @@ clsid = disp_class.CLSID # Create a new class that derives from 2 classes - the event sink # class and the user class. - import new + try: + from types import ClassType as new_type + except ImportError: + new_type = type # py3k events_class = getevents(clsid) if events_class is None: raise ValueError("This COM object does not support events.") - result_class = new.classobj("COMEventClass", (events_class, user_event_class), {}) + result_class = new_type("COMEventClass", (events_class, user_event_class), {}) instance = result_class(disp) # This only calls the first base class __init__. if hasattr(user_event_class, "__init__"): user_event_class.__init__(instance) diff -r 816b080c336b -r 7f44ae5e7785 com/win32com/client/build.py --- a/com/win32com/client/build.py Sun Apr 24 13:31:45 2011 +1000 +++ b/com/win32com/client/build.py Sun Apr 24 14:22:25 2011 +1000 @@ -28,8 +28,10 @@ # It isn't really clear what the quoting rules are in a C/IDL string and # literals like a quote char and backslashes makes life a little painful to # always render the string perfectly - so just punt and fall-back to a repr() -def _makeDocString(s, encoding="mbcs"): - return repr(s.encode(encoding)) +def _makeDocString(s): + if sys.version_info < (3,): + s = s.encode("mbcs") + return repr(s) error = "PythonCOM.Client.Build error" class NotSupportedException(Exception): pass # Raised when we cant support a param type. diff -r 816b080c336b -r 7f44ae5e7785 com/win32com/test/testPyComTest.py --- a/com/win32com/test/testPyComTest.py Sun Apr 24 13:31:45 2011 +1000 +++ b/com/win32com/test/testPyComTest.py Sun Apr 24 14:22:25 2011 +1000 @@ -205,6 +205,22 @@ TestApplyResult(o.EarliestDate, (now, now), expect) +def TestEvents(o, handler): + sessions = [] + handler._Init() + try: + for i in range(3): + session = o.Start() + sessions.append(session) + time.sleep(.5) + finally: + # Stop the servers + for session in sessions: + o.Stop(session) + handler._DumpFireds() + handler.close() + + def TestGenerated(): # Create an instance of the server. from win32com.client.gencache import EnsureDispatch @@ -408,20 +424,11 @@ # Do the connection point thing... # Create a connection object. progress("Testing connection points") - sessions = [] - o = win32com.client.DispatchWithEvents( o, RandomEventHandler) - o._Init() - - try: - for i in range(3): - session = o.Start() - sessions.append(session) - time.sleep(.5) - finally: - # Stop the servers - for session in sessions: - o.Stop(session) - o._DumpFireds() + o2 = win32com.client.DispatchWithEvents(o, RandomEventHandler) + TestEvents(o2, o2) + # and a plain "WithEvents". + handler = win32com.client.WithEvents(o, RandomEventHandler) + TestEvents(o, handler) progress("Finished generated .py test.") def TestCounter(counter, bIsGenerated): |