diff --git a/docs/development/setup-cxfreeze.py b/docs/development/setup-cxfreeze.py index bdc2a4f..a99d192 100644 --- a/docs/development/setup-cxfreeze.py +++ b/docs/development/setup-cxfreeze.py @@ -26,7 +26,7 @@ name='TestPubSub', description="Script to test pubsub for packaging with cxfreeze", version='0.1', - + options={'build_exe' : opts}, executables=[WIN_Target] ) diff --git a/docs/development/setup-py2exe.py b/docs/development/setup-py2exe.py index a8deb91..00c5b11 100644 --- a/docs/development/setup-py2exe.py +++ b/docs/development/setup-py2exe.py @@ -1,13 +1,13 @@ """ -File based on a contribution from Josh Immanuel. Use via +File based on a contribution from Josh Immanuel. Use via python setup-py2exe.py py2exe -which will create a dist folder containing the .exe, the python DLL, and a -few other DLL deemed by py2exe to be critical to the application execution. +which will create a dist folder containing the .exe, the python DLL, and a +few other DLL deemed by py2exe to be critical to the application execution. -The contents of the dist folder should then be packaged using a tool such -as NSIS or Inno Setup. The py2exe page has an example for NSIS. +The contents of the dist folder should then be packaged using a tool such +as NSIS or Inno Setup. The py2exe page has an example for NSIS. """ from distutils.core import setup @@ -18,7 +18,7 @@ name='TestPubSub', description="Script to test pubsub for packaging", version="0.1", - + console=[{'script': 'testpubsub.py'}], options={ 'py2exe': { 'packages': 'encodings, pubsub', diff --git a/docs/usage/helloworld.py b/docs/usage/helloworld.py index c9ed800..7a71261 100644 --- a/docs/usage/helloworld.py +++ b/docs/usage/helloworld.py @@ -1,6 +1,6 @@ """ One listener is subscribed to a topic called 'rootTopic'. -One 'rootTopic' message gets sent. +One 'rootTopic' message gets sent. """ from pubsub import pub diff --git a/examples/advanced/kwargs_topics_out.py b/examples/advanced/kwargs_topics_out.py index de708ec..4311934 100644 --- a/examples/advanced/kwargs_topics_out.py +++ b/examples/advanced/kwargs_topics_out.py @@ -11,7 +11,7 @@ class topic_1: """ Explain when topic_1 should be used """ - + def msgDataSpec(msg): """ - msg: a text string message for recipient @@ -21,7 +21,7 @@ class subtopic_11: """ Explain when subtopic_11 should be used """ - + def msgDataSpec(msg, msg2, extra=None): """ - extra: something optional @@ -32,7 +32,7 @@ class topic_2: """ Some something useful about topic2 """ - + def msgDataSpec(msg=None): """ - msg: a text string @@ -42,7 +42,7 @@ class subtopic_21: """ description for subtopic 21 """ - + def msgDataSpec(msg, arg1=None): """ - arg1: UNDOCUMENTED diff --git a/setup.py b/setup.py index d026496..84111d2 100644 --- a/setup.py +++ b/setup.py @@ -58,7 +58,7 @@ def getInstallRequires(): 'Topic :: Software Development :: Libraries :: Python Modules', ], python_requires = ">=3.3, <4", - + # use the module docs as the long description: long_description = open('README.rst', 'r').read() ) diff --git a/src/contrib/netpubsub.py b/src/contrib/netpubsub.py index 5f5ba65..3eac9e2 100644 --- a/src/contrib/netpubsub.py +++ b/src/contrib/netpubsub.py @@ -1,17 +1,17 @@ """ Skeleton code (will not load... must be completed): -UDP-based net-centric Pubsub extension so that pubsub can be used over a -network of pubsub-powered applications. Extending to use TCP wouldn't be -too difficult. - -Usage: each of your applications that uses pubsub would create a -suitable AppListener, then call its sendMessage when wanting to -send a message, or call processMessages whenever it is ready to -process queued messages from other applications. In addition, one +UDP-based net-centric Pubsub extension so that pubsub can be used over a +network of pubsub-powered applications. Extending to use TCP wouldn't be +too difficult. + +Usage: each of your applications that uses pubsub would create a +suitable AppListener, then call its sendMessage when wanting to +send a message, or call processMessages whenever it is ready to +process queued messages from other applications. In addition, one of your applications must be the "pubsub server", or the server -could live in its own python program. For it, you would -create a PubsubAppServer then call its processMessages() -in an infinite loop. +could live in its own python program. For it, you would +create a PubsubAppServer then call its processMessages() +in an infinite loop. Oliver Schoenborn """ diff --git a/src/pubsub/utils/__init__.py b/src/pubsub/utils/__init__.py index 32b86cf..ef41c30 100644 --- a/src/pubsub/utils/__init__.py +++ b/src/pubsub/utils/__init__.py @@ -1,6 +1,6 @@ """ -Provides utility functions and classes that are not required for using -pubsub but are likely to be very useful. +Provides utility functions and classes that are not required for using +pubsub but are likely to be very useful. :copyright: Copyright since 2006 by Oliver Schoenborn, all rights reserved. :license: BSD, see LICENSE_BSD_Simple.txt for details. diff --git a/src/pubsub/utils/notification.py b/src/pubsub/utils/notification.py index 9475ffa..fb48118 100644 --- a/src/pubsub/utils/notification.py +++ b/src/pubsub/utils/notification.py @@ -1,19 +1,19 @@ """ -Provide an interface class for handling pubsub notification messages, -and an example class (though very useful in practice) showing how to -use it. +Provide an interface class for handling pubsub notification messages, +and an example class (though very useful in practice) showing how to +use it. Notification messages are generated by pubsub - if a handler has been configured via pub.addNotificationHandler() - when pubsub does certain tasks, such as when a listener subscribes to or unsubscribes from a topic - -Derive from this class to handle notification events from -various parts of pubsub. E.g. when a listener subscribes, -unsubscribes, or dies, a notification handler, if you -specified one via pub.addNotificationHandler(), is given the -relevant information. + +Derive from this class to handle notification events from +various parts of pubsub. E.g. when a listener subscribes, +unsubscribes, or dies, a notification handler, if you +specified one via pub.addNotificationHandler(), is given the +relevant information. :copyright: Copyright since 2006 by Oliver Schoenborn, all rights reserved. :license: BSD, see LICENSE_BSD_Simple.txt for details. @@ -53,7 +53,7 @@ def notifyDelTopic(self, topicName: str): class NotifyByWriteFile(INotificationHandler): """ - Print a message to stdout when a notification is received. + Print a message to stdout when a notification is received. """ defaultPrefix = 'PUBSUB:' @@ -117,19 +117,19 @@ class NotifyByPubsubMessage(INotificationHandler): """ Handle pubsub notification messages by generating messages of a 'pubsub.' subtopic. Also provides - an example of how to create a notification handler. - + an example of how to create a notification handler. + Use it by calling:: - + import pubsub.utils pubsub.utils.useNotifyByPubsubMessage() ... pub.setNotificationFlags(...) # optional - + E.g. whenever a listener is unsubscribed, a 'pubsub.unsubscribe' - message is generated. If you have subscribed a listener of - this topic, your listener will be notified of what listener - unsubscribed from what topic. + message is generated. If you have subscribed a listener of + this topic, your listener will be notified of what listener + unsubscribed from what topic. """ topicRoot = 'pubsub' @@ -196,7 +196,7 @@ def notifyDeadListener(self, pubListener: Listener, topicObj: Topic): def notifySend(self, stage: str, topicObj: Topic, pubListener: Listener = None): """ Stage must be 'pre' or 'post'. Note that any pubsub sendMessage - operation resulting from this notification (which sends a message; + operation resulting from this notification (which sends a message; listener could handle by sending another message!) will NOT themselves lead to a send notification. """ @@ -294,9 +294,9 @@ def useNotifyByPubsubMessage(publisher: Publisher = None, all: bool = True, **kw out as messages. Topic will be 'pubsub' subtopics, such as 'pubsub.newTopic', 'pubsub.delTopic', 'pubsub.sendMessage', etc. - The 'all' and kwargs args are the same as pubsub's setNotificationFlags(), + The 'all' and kwargs args are the same as pubsub's setNotificationFlags(), except that 'all' defaults to True. - + The publisher is rarely needed: * The publisher must be specfied if pubsub is not installed @@ -325,7 +325,7 @@ def useNotifyByWriteFile(fileObj: TextIO = None, prefix: str = None, publisher: Will cause all pubsub notifications of pubsub "actions" (such as new topic created, message sent, listener died etc) to be written to specified file (or stdout if none given). The fileObj need only provide a 'write(string)' method. - + The first two arguments are the same as those of NotifyByWriteFile constructor. The 'all' and kwargs arguments are those of pubsub's setNotificationFlags(), except that 'all' defaults to True. See useNotifyByPubsubMessage() for an explanation of pubModule (typically only if pubsub inside wxPython's wx.lib) @@ -335,6 +335,6 @@ def useNotifyByWriteFile(fileObj: TextIO = None, prefix: str = None, publisher: from .. import pub publisher = pub.getDefaultPublisher() notifHandler = NotifyByWriteFile(fileObj, prefix) - + publisher.addNotificationHandler(notifHandler) publisher.setNotificationFlags(all=all, **kwargs) diff --git a/tests/suite/test4_prov_module_expect.py b/tests/suite/test4_prov_module_expect.py index f5fc50a..892a6cf 100644 --- a/tests/suite/test4_prov_module_expect.py +++ b/tests/suite/test4_prov_module_expect.py @@ -22,7 +22,7 @@ class subtopic_1: Sub topic 1 of root topic. Docs rely on one blank line for topic doc, and indentation for each argument doc. """ - + def msgDataSpec(arg1, arg2=None): """ - arg1: some multiline doc diff --git a/tools/compare_timings.py b/tools/compare_timings.py index f56f2e8..909084f 100644 --- a/tools/compare_timings.py +++ b/tools/compare_timings.py @@ -1,13 +1,13 @@ ''' -Timing helper function to time several Python statements. It makes +Timing helper function to time several Python statements. It makes using the timeit module much more convenient. The only important function is times(), to which you provide the number of iterations -to time, an initialization statement (typically, to initialize some -locals), and the list of statements to time. E.g. +to time, an initialization statement (typically, to initialize some +locals), and the list of statements to time. E.g. - times(init='l=range(1,1000)', - s1='if l!=[]: pass', - s2='if l: pass', + times(init='l=range(1,1000)', + s1='if l!=[]: pass', + s2='if l: pass', s3='if len(l): pass') will print(out) @@ -17,7 +17,7 @@ s3 => 0.121 showing that s2 is the fastest (in fact, two to three times faster -than the alternatives). +than the alternatives). ''' from timeit import Timer @@ -29,18 +29,18 @@ def __init__(self, name, num, init, statement): self.name = name self.statement = statement self.__result = None - + def timeit(self): self.__result = self.__timer.timeit(self.__num) - + def getResult(self): return self.__result - - + + def times(num=1000000, reverse=False, init='', **statements): - '''The num is the number of times that each statement will - be executed. The init statement is executed only once for - statement and is not part of the timing result. The + '''The num is the number of times that each statement will + be executed. The init statement is executed only once for + statement and is not part of the timing result. The statements kwarg is a dict of statements to time, where key is a 'name' for the statement, and value is the statement (as a string). Prints the timings from smallest to largest @@ -51,40 +51,40 @@ def times(num=1000000, reverse=False, init='', **statements): t = Timing(n, num, init, s) t.timeit() timings.append(t) - + # print(results) timings.sort(key=Timing.getResult, reverse=reverse) for t in timings: print(" %10s => %.3f s" % (t.name, t.getResult())) - - + + if __name__ == '__main__': inits = ('l=range(1,1000)', 'l=[]') for ii in inits: print('\nFor %s:' % ii) - times(init=ii, - boolean = 'if l: pass', - empty = 'if l!=[]: pass', + times(init=ii, + boolean = 'if l: pass', + empty = 'if l!=[]: pass', len_ = 'if len(l): pass') - + print('\nFor list -> dict:') - times(100, init='l=range(1,1000)', - zip = 'dict(zip(l[::2], l[1::2]))', + times(100, init='l=range(1,1000)', + zip = 'dict(zip(l[::2], l[1::2]))', listcomp = 'dict((l[i],l[i+1]) for i in range(0,len(l)-1,2))') - + print('\nFor hasattr vs except:') - times(10000, init='class Foo: pass\nfoo = Foo()', + times(10000, init='class Foo: pass\nfoo = Foo()', hasattr = 'if hasattr(foo, "a"): a = getattr(foo, "a")', excep = 'try: a = foo.a\nexcept Exception: pass') - + print('\nFor cost of enumerate:') - times(100, init='l=range(1,1000)\ndef f(v): return (v*10-50)/2', + times(100, init='l=range(1,1000)\ndef f(v): return (v*10-50)/2', enum = 'for i, v in enumerate(l): f(v)', noenum = 'for v in l: f(v)', count = 'ii=0\nfor v in l: \n f(v)\nii += 1') - + print('\nFor slice before/in loop:') - times(100, init='l=range(0,10000)\nl2=range(0,1000)', + times(100, init='l=range(0,10000)\nl2=range(0,1000)', before10k = 'l3=l[9000:]\nfor i in l3: pass', before1k = 'l3=l2[1:]\nfor i in l3: pass', inloop10k = 'for i in l[9000:]: pass',