Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Evict Foul Whitespace Demons 2020 #49

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/development/setup-cxfreeze.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
)
Expand Down
12 changes: 6 additions & 6 deletions docs/development/setup-py2exe.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion docs/usage/helloworld.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 4 additions & 4 deletions examples/advanced/kwargs_topics_out.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class topic_1:
"""
Explain when topic_1 should be used
"""

def msgDataSpec(msg):
"""
- msg: a text string message for recipient
Expand All @@ -21,7 +21,7 @@ class subtopic_11:
"""
Explain when subtopic_11 should be used
"""

def msgDataSpec(msg, msg2, extra=None):
"""
- extra: something optional
Expand All @@ -32,7 +32,7 @@ class topic_2:
"""
Some something useful about topic2
"""

def msgDataSpec(msg=None):
"""
- msg: a text string
Expand All @@ -42,7 +42,7 @@ class subtopic_21:
"""
description for subtopic 21
"""

def msgDataSpec(msg, arg1=None):
"""
- arg1: UNDOCUMENTED
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
)
Expand Down
22 changes: 11 additions & 11 deletions src/contrib/netpubsub.py
Original file line number Diff line number Diff line change
@@ -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
"""
Expand Down
4 changes: 2 additions & 2 deletions src/pubsub/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
44 changes: 22 additions & 22 deletions src/pubsub/utils/notification.py
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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:'
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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.
"""
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
2 changes: 1 addition & 1 deletion tests/suite/test4_prov_module_expect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
58 changes: 29 additions & 29 deletions tools/compare_timings.py
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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',
Expand Down