From af329545fbc1410390acd8277b6509bb3fce82b1 Mon Sep 17 00:00:00 2001 From: Metallicow Date: Sun, 12 Jan 2014 10:28:54 -0600 Subject: [PATCH 1/2] PY3 pubsub Fixs --- wx/lib/pubsub/core/callables.py | 6 +++--- wx/lib/pubsub/core/imp2.py | 2 +- wx/lib/pubsub/core/kwargs/datamsg.py | 6 +++--- wx/lib/pubsub/core/kwargs/publisher.py | 2 +- wx/lib/pubsub/core/topicobj.py | 6 +++--- wx/lib/pubsub/policies.py | 10 ++++++---- wx/lib/pubsub/utils/xmltopicdefnprovider.py | 2 +- 7 files changed, 18 insertions(+), 16 deletions(-) diff --git a/wx/lib/pubsub/core/callables.py b/wx/lib/pubsub/core/callables.py index e94032ee..00c8a061 100644 --- a/wx/lib/pubsub/core/callables.py +++ b/wx/lib/pubsub/core/callables.py @@ -57,16 +57,16 @@ def getRawFunction(callable_): recognized type (function, method or has __call__ method).""" firstArg = 0 if isfunction(callable_): - #print 'Function', getID(callable_) + #print('Function', getID(callable_)) func = callable_ elif ismethod(callable_): - #print 'Method', getID(callable_) + #print('Method', getID(callable_)) func = callable_ if func.__self__ is not None: # Method is bound, don't care about the self arg firstArg = 1 elif hasattr(callable_, '__call__'): - #print 'Functor', getID(callable_) + #print('Functor', getID(callable_)) func = callable_.__call__ firstArg = 1 # don't care about the self arg else: diff --git a/wx/lib/pubsub/core/imp2.py b/wx/lib/pubsub/core/imp2.py index c4641e33..9ae28b87 100644 --- a/wx/lib/pubsub/core/imp2.py +++ b/wx/lib/pubsub/core/imp2.py @@ -49,7 +49,7 @@ def load_module(moduleName, searchPath): try: module = _import_module(moduleName) - except: + except Exception: import imp fp, pathname, description = imp.find_module(moduleName, searchPath) try: diff --git a/wx/lib/pubsub/core/kwargs/datamsg.py b/wx/lib/pubsub/core/kwargs/datamsg.py index f6a24ea2..ef68b770 100644 --- a/wx/lib/pubsub/core/kwargs/datamsg.py +++ b/wx/lib/pubsub/core/kwargs/datamsg.py @@ -12,9 +12,9 @@ class Message: via Message.data, while the topic name is available in Message.topic:: def listener(msg): - print "data is ", msg.data - print "topic name is ", msg.topic - print msg + print("data is ", msg.data) + print("topic name is ", msg.topic) + print(msg) The example also shows (last line) how a message is convertible to a string. """ diff --git a/wx/lib/pubsub/core/kwargs/publisher.py b/wx/lib/pubsub/core/kwargs/publisher.py index 7575be6a..5e3fd255 100644 --- a/wx/lib/pubsub/core/kwargs/publisher.py +++ b/wx/lib/pubsub/core/kwargs/publisher.py @@ -72,6 +72,6 @@ class PublisherArg1Stage2(Publisher): if policies.msgProtocolTransStage is not None: Publisher = PublisherArg1Stage2 - #print 'Using protocol', Publisher + #print('Using protocol', Publisher) diff --git a/wx/lib/pubsub/core/topicobj.py b/wx/lib/pubsub/core/topicobj.py index 716fa21e..368ffecc 100644 --- a/wx/lib/pubsub/core/topicobj.py +++ b/wx/lib/pubsub/core/topicobj.py @@ -409,7 +409,7 @@ class Topic(PublisherMixin): self.__handlingUncaughtListenerExc = False except Exception: exc = py2and3.getexcobj() - #print 'exception raised', exc + #print('exception raised', exc) self.__handlingUncaughtListenerExc = False raise ExcHandlerError(listener.name(), topicObj, exc) @@ -437,13 +437,13 @@ class Topic(PublisherMixin): """Unsubscribe all our listeners, remove all subtopics from self, then detach from parent. Parent is not notified, because method assumes it has been called by parent""" - #print 'Remove %s listeners (%s)' % (self.getName(), self.getNumListeners()) + #print('Remove %s listeners (%s)' % (self.getName(), self.getNumListeners())) self.unsubscribeAllListeners() self.__parentTopic = None for subName, subObj in py2and3.iteritems(self.__subTopics): assert isinstance(subObj, Topic) - #print 'Unlinking %s from parent' % subObj.getName() + #print('Unlinking %s from parent' % subObj.getName()) subObj.__undefineBranch(topicsMap) self.__subTopics = {} diff --git a/wx/lib/pubsub/policies.py b/wx/lib/pubsub/policies.py index bc296ce5..239c0054 100644 --- a/wx/lib/pubsub/policies.py +++ b/wx/lib/pubsub/policies.py @@ -1,5 +1,5 @@ """ -Aggregates policies for pubsub. Mainly, related to messaging protocol. +Aggregates policies for pubsub. Mainly, related to messaging protocol. :copyright: Copyright since 2006 by Oliver Schoenborn, all rights reserved. :license: BSD, see LICENSE_BSD_Simple.txt for details. @@ -19,6 +19,8 @@ def setMsgDataArgName(stage, listenerArgName, senderArgNameAny=False): senderKwargNameAny = senderArgNameAny msgDataArgName = listenerArgName msgProtocolTransStage = stage - #print `policies.msgProtocolTransStage`, `policies.msgDataProtocol`, \ - # `policies.senderKwargNameAny`, `policies.msgDataArgName` - #print 'override "arg1" protocol arg name:', argName + #print(repr(policies.msgProtocolTransStage), + # repr(policies.msgDataProtocol), + # repr(policies.senderKwargNameAny), + # repr(policies.msgDataArgName)) + #print('override "arg1" protocol arg name:', argName) diff --git a/wx/lib/pubsub/utils/xmltopicdefnprovider.py b/wx/lib/pubsub/utils/xmltopicdefnprovider.py index b135e38c..41540492 100644 --- a/wx/lib/pubsub/utils/xmltopicdefnprovider.py +++ b/wx/lib/pubsub/utils/xmltopicdefnprovider.py @@ -79,7 +79,7 @@ def _get_elem(elem): if not ET.iselement(elem): try: elem = ET.fromstring(elem) - except: + except Exception: py2and3.print_("Value Error", elem) raise ValueError("Cannot convert to element") return elem From 0496c8b6103f641ded5f1fd60d0f0feb4432f844 Mon Sep 17 00:00:00 2001 From: Metallicow Date: Tue, 14 Jan 2014 05:30:19 -0600 Subject: [PATCH 2/2] prefer str not tuple for print statements --- wx/lib/pubsub/core/callables.py | 6 +++--- wx/lib/pubsub/core/kwargs/datamsg.py | 4 ++-- wx/lib/pubsub/core/kwargs/publisher.py | 2 +- wx/lib/pubsub/core/topicobj.py | 2 +- wx/lib/pubsub/policies.py | 10 +++++----- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/wx/lib/pubsub/core/callables.py b/wx/lib/pubsub/core/callables.py index 00c8a061..3c4a9b10 100644 --- a/wx/lib/pubsub/core/callables.py +++ b/wx/lib/pubsub/core/callables.py @@ -57,16 +57,16 @@ def getRawFunction(callable_): recognized type (function, method or has __call__ method).""" firstArg = 0 if isfunction(callable_): - #print('Function', getID(callable_)) + #print('Function %s' % getID(callable_)) func = callable_ elif ismethod(callable_): - #print('Method', getID(callable_)) + #print('Method %s' % getID(callable_)) func = callable_ if func.__self__ is not None: # Method is bound, don't care about the self arg firstArg = 1 elif hasattr(callable_, '__call__'): - #print('Functor', getID(callable_)) + #print('Functor %s' % getID(callable_)) func = callable_.__call__ firstArg = 1 # don't care about the self arg else: diff --git a/wx/lib/pubsub/core/kwargs/datamsg.py b/wx/lib/pubsub/core/kwargs/datamsg.py index ef68b770..15c1ac04 100644 --- a/wx/lib/pubsub/core/kwargs/datamsg.py +++ b/wx/lib/pubsub/core/kwargs/datamsg.py @@ -12,8 +12,8 @@ class Message: via Message.data, while the topic name is available in Message.topic:: def listener(msg): - print("data is ", msg.data) - print("topic name is ", msg.topic) + print("data is %s" % msg.data) + print("topic name is %s" % msg.topic) print(msg) The example also shows (last line) how a message is convertible to a string. diff --git a/wx/lib/pubsub/core/kwargs/publisher.py b/wx/lib/pubsub/core/kwargs/publisher.py index 5e3fd255..ba08cc7e 100644 --- a/wx/lib/pubsub/core/kwargs/publisher.py +++ b/wx/lib/pubsub/core/kwargs/publisher.py @@ -72,6 +72,6 @@ class PublisherArg1Stage2(Publisher): if policies.msgProtocolTransStage is not None: Publisher = PublisherArg1Stage2 - #print('Using protocol', Publisher) + #print('Using protocol %s' % Publisher) diff --git a/wx/lib/pubsub/core/topicobj.py b/wx/lib/pubsub/core/topicobj.py index 368ffecc..5f218f32 100644 --- a/wx/lib/pubsub/core/topicobj.py +++ b/wx/lib/pubsub/core/topicobj.py @@ -409,7 +409,7 @@ class Topic(PublisherMixin): self.__handlingUncaughtListenerExc = False except Exception: exc = py2and3.getexcobj() - #print('exception raised', exc) + #print('Exception raised\n%s' % exc) self.__handlingUncaughtListenerExc = False raise ExcHandlerError(listener.name(), topicObj, exc) diff --git a/wx/lib/pubsub/policies.py b/wx/lib/pubsub/policies.py index 239c0054..16b90200 100644 --- a/wx/lib/pubsub/policies.py +++ b/wx/lib/pubsub/policies.py @@ -19,8 +19,8 @@ def setMsgDataArgName(stage, listenerArgName, senderArgNameAny=False): senderKwargNameAny = senderArgNameAny msgDataArgName = listenerArgName msgProtocolTransStage = stage - #print(repr(policies.msgProtocolTransStage), - # repr(policies.msgDataProtocol), - # repr(policies.senderKwargNameAny), - # repr(policies.msgDataArgName)) - #print('override "arg1" protocol arg name:', argName) + #print('%s' % repr(policies.msgProtocolTransStage)) + #print('%s' % repr(policies.msgDataProtocol)) + #print('%s' % repr(policies.senderKwargNameAny)) + #print('%s' % repr(policies.msgDataArgName)) + #print('override "arg1" protocol arg name: %s' % argName)