From 32f26f20d00b3850c7b1fc91d9649f6b1dbdb6b9 Mon Sep 17 00:00:00 2001 From: Julio Biason Date: Wed, 16 Dec 2009 07:35:53 -0200 Subject: [PATCH] PEP8 fixed --- mitterlib/__init__.py | 6 +++--- mitterlib/network/__init__.py | 3 --- mitterlib/network/networkbase.py | 12 ++++++------ mitterlib/network/twitter.py | 4 +--- mitterlib/ui/__init__.py | 1 - mitterlib/ui/helpers/console_utils.py | 1 + mitterlib/ui/helpers/image_helpers.py | 3 ++- mitterlib/ui/helpers/timesince.py | 1 - mitterlib/ui/ui_cmd.py | 4 ---- mitterlib/ui/ui_pygtk.py | 17 ++++++++--------- mitterlib/ui/ui_tty.py | 3 --- mitterlib/ui/ui_zork.py | 11 ++++------- tests.py | 6 +++--- 13 files changed, 28 insertions(+), 44 deletions(-) diff --git a/mitterlib/__init__.py b/mitterlib/__init__.py index e3074ea..7161516 100644 --- a/mitterlib/__init__.py +++ b/mitterlib/__init__.py @@ -21,8 +21,9 @@ import os.path import glob import htmlentitydefs + def module_search(source, ignore): - """Search for modules in the source directory. Ignore any modules + """Search for modules in the source directory. Ignore any modules indicated.""" base_dir = os.path.dirname(source) @@ -39,6 +40,7 @@ def module_search(source, ignore): # "importable" yield module_name + def htmlize(text): """Convert accented characters to their HTML entities.""" new = [] @@ -50,5 +52,3 @@ def htmlize(text): else: new.append(char) return ''.join(new) - - diff --git a/mitterlib/network/__init__.py b/mitterlib/network/__init__.py index d44e41f..f3c2e8c 100644 --- a/mitterlib/network/__init__.py +++ b/mitterlib/network/__init__.py @@ -32,7 +32,6 @@ SKIPPABLES = ('__init__.py', 'networkbase.py') # Helper functions #-------------------------------------------------------------------- - def _import_name(module): """Based on the name of the module, return the proper "import" statement.""" @@ -44,7 +43,6 @@ def _import_name(module): # Exceptions #-------------------------------------------------------------------- - class NetworksError(Exception): """Basic Networks exception.""" pass @@ -151,7 +149,6 @@ class Networks(object): # This is basically a copy of all methods available in NetworkBase, with # the additional parameter "network" (to request data from just one # source) - def messages(self, network=None): """Return a list of NetworkData objects for the main "timeline" (the default list presented to the user.)""" diff --git a/mitterlib/network/networkbase.py b/mitterlib/network/networkbase.py index 95d2844..dfed705 100644 --- a/mitterlib/network/networkbase.py +++ b/mitterlib/network/networkbase.py @@ -44,7 +44,6 @@ def auth_options(namespace, options, auths): # Exceptions #-------------------------------------------------------------------- - class NetworkError(Exception): """Base class for all network related exceptions.""" pass @@ -92,10 +91,12 @@ class NetworkPermissionDeniedError(NetworkError): #-------------------------------------------------------------------- # Warnings #-------------------------------------------------------------------- + class NetworkWarning(Warning): """Base warning for networks.""" pass + class MessageTooLongWarning(NetworkWarning): """The message is too long for the network.""" pass @@ -104,7 +105,6 @@ class MessageTooLongWarning(NetworkWarning): # The classes #-------------------------------------------------------------------- - class NetworkData(object): """Provides an uniform way to access information about posts. The following fields should appear: @@ -143,6 +143,7 @@ class NetworkData(object): worry about this field themselves; :class:`Networks` will set it when merging information from all networks. """ + def __init__(self): self.id = '' self.name = '' @@ -189,7 +190,6 @@ class NetworkBase(object): if possible. """ - def is_setup(self): """Should return a boolean indicating if the network have all necessary options set up so it can retrieve information. @@ -244,12 +244,12 @@ class NetworkBase(object): def can_delete(self, message): """Return True if the message can be deleted; False otherwise.""" - return False; + return False def can_reply(self, message): """Return True if the message can be replied; False otherwise.""" - return False; + return False def can_repost(self, message): """Return True if the message can be resposted; False otherwise.""" - return False; + return False diff --git a/mitterlib/network/twitter.py b/mitterlib/network/twitter.py index 90b9c16..c875885 100644 --- a/mitterlib/network/twitter.py +++ b/mitterlib/network/twitter.py @@ -365,7 +365,6 @@ class Connection(NetworkBase): _log.debug('Requests: %s', data) return int(data['remaining_hits']) - def update(self, status, reply_to=None): """Update the user status.""" if len(status) > 140: @@ -423,7 +422,6 @@ class Connection(NetworkBase): _log.debug('Delete response: %s', response) return True # Either we get a response or an exception before we reach # this. - def can_delete(self, message): """Check if the message belongs to the user. If so, returns True; False otherwise.""" @@ -432,7 +430,7 @@ class Connection(NetworkBase): def can_reply(self, message): """Always return True; Twitter allows replying to any messages, including the ones from the user.""" - return True; + return True def can_repost(self, message): """Twitter ignores retweets from the user.""" diff --git a/mitterlib/ui/__init__.py b/mitterlib/ui/__init__.py index 917ab82..0c673a5 100644 --- a/mitterlib/ui/__init__.py +++ b/mitterlib/ui/__init__.py @@ -31,7 +31,6 @@ SKIPPABLES = ('__init__.py') # Helper functions #-------------------------------------------------------------------- - def _import_name(module): """Based on the name of the module, return the proper "import" statement.""" diff --git a/mitterlib/ui/helpers/console_utils.py b/mitterlib/ui/helpers/console_utils.py index 31eacf2..cf4a9cb 100644 --- a/mitterlib/ui/helpers/console_utils.py +++ b/mitterlib/ui/helpers/console_utils.py @@ -189,6 +189,7 @@ def print_thread(thread_list, connection): pos += 1 return + def make_retweet(message): """Creates the text for a reweet.""" if not message.message.lower().startswith('rt @'): diff --git a/mitterlib/ui/helpers/image_helpers.py b/mitterlib/ui/helpers/image_helpers.py index 5dd13e8..24a9459 100644 --- a/mitterlib/ui/helpers/image_helpers.py +++ b/mitterlib/ui/helpers/image_helpers.py @@ -21,8 +21,9 @@ import os.path import sys import logging + def find_image(image_name): - """Using the iamge_name, search in the common places. Return the path for + """Using the image_name, search in the common places. Return the path for the image or None if the image couldn't be found.""" # just because I'm a logging nut diff --git a/mitterlib/ui/helpers/timesince.py b/mitterlib/ui/helpers/timesince.py index 7083be2..2f2c69d 100644 --- a/mitterlib/ui/helpers/timesince.py +++ b/mitterlib/ui/helpers/timesince.py @@ -26,7 +26,6 @@ import time # http://code.djangoproject.com/browser/django/trunk/django/utils/timesince.py # My version expects time to be given in UTC & returns timedelta from UTC. - def pluralize(singular, plural, count): if count == 1: return singular diff --git a/mitterlib/ui/ui_cmd.py b/mitterlib/ui/ui_cmd.py index 3aa7b02..53bba10 100644 --- a/mitterlib/ui/ui_cmd.py +++ b/mitterlib/ui/ui_cmd.py @@ -40,7 +40,6 @@ class Interface(cmd.Cmd): # ----------------------------------------------------------------------- # Methods required by cmd.Cmd (our commands) # ----------------------------------------------------------------------- - def do_config(self, line=None): """Setup the networks.""" options = self._connection.settings() @@ -157,7 +156,6 @@ class Interface(cmd.Cmd): # ----------------------------------------------------------------------- # Helper functions # ----------------------------------------------------------------------- - def _check_message(self, message_id): """Check if a message is valid in the current list.""" if message_id < 1 or message_id > len(self._messages): @@ -234,11 +232,9 @@ class Interface(cmd.Cmd): (update_text, ', '.join(available))) return - # ----------------------------------------------------------------------- # Methods required by the main Mitter code # ----------------------------------------------------------------------- - def __init__(self, connection, options): """Class initialization.""" diff --git a/mitterlib/ui/ui_pygtk.py b/mitterlib/ui/ui_pygtk.py index 09b3bfc..0779126 100644 --- a/mitterlib/ui/ui_pygtk.py +++ b/mitterlib/ui/ui_pygtk.py @@ -67,6 +67,7 @@ class _IdleObject(gobject.GObject): Override gobject.GObject to always emit signals in the main thread by emmitting on an idle handler """ + def __init__(self): gobject.GObject.__init__(self) @@ -82,12 +83,11 @@ class _WorkerThread(threading.Thread, _IdleObject): "completed": ( gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, - (gobject.TYPE_PYOBJECT,)), # list/networkdata + (gobject.TYPE_PYOBJECT, )), # list/networkdata "exception": ( gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, - (gobject.TYPE_PYOBJECT,)) # The exception - } + (gobject.TYPE_PYOBJECT, ))} # The exception def __init__(self, function, *args, **kwargs): threading.Thread.__init__(self) @@ -666,9 +666,8 @@ class Interface(object): popup.show_all() popup.popup(None, None, None, event.button, event.time) - - return True + return True # ------------------------------------------------------------ # Widget callback functions @@ -730,7 +729,7 @@ class Interface(object): gtk.main_quit() return - def _grid_resize(self, widget, requisition, data=None): + def _grid_resize(self, widget, requisition, data=None): """Called when the window is resized. We use it to set the proper word-wrapping in the message column.""" @@ -786,8 +785,8 @@ class Interface(object): cannot do.""" (model, iter) = view.get_selection().get_selected() - if not iter: - return + if not iter: + return data = model.get_value(iter, 0) self._delete_action.set_property('sensitive', @@ -847,7 +846,7 @@ class Interface(object): parent=self._main_window, flags=gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, buttons=(gtk.STOCK_OK, 0)) - + # the tabs tabs = gtk.Notebook() diff --git a/mitterlib/ui/ui_tty.py b/mitterlib/ui/ui_tty.py index 1300192..ea89116 100644 --- a/mitterlib/ui/ui_tty.py +++ b/mitterlib/ui/ui_tty.py @@ -35,7 +35,6 @@ class Interface(object): # ----------------------------------------------------------------------- # Private functions # ----------------------------------------------------------------------- - def _config(self): """Set up the networks.""" options = self._connection.settings() @@ -75,11 +74,9 @@ class Interface(object): return - # ----------------------------------------------------------------------- # Methods required by the main Mitter code # ----------------------------------------------------------------------- - def __init__(self, connection, options): """Class initialization.""" self._connection = connection diff --git a/mitterlib/ui/ui_zork.py b/mitterlib/ui/ui_zork.py index b0134eb..50ed6d9 100644 --- a/mitterlib/ui/ui_zork.py +++ b/mitterlib/ui/ui_zork.py @@ -37,7 +37,6 @@ class Interface(cmd.Cmd): # ----------------------------------------------------------------------- # Commands # ----------------------------------------------------------------------- - def do_config(self, line=None): """Setup the networks.""" options = self._connection.settings() @@ -127,9 +126,9 @@ class Interface(cmd.Cmd): """Update your status.""" if self._update(line): print 'Status updated' - self.lastcmd = None - # So we don't send the same message if the user pressed enter - # again + # clear the message so it's not send if the user press enter + # twice. + self.lastcmd = None def do_thread(self, line): """Display the conversation thread with the message pointed by the @@ -153,7 +152,6 @@ class Interface(cmd.Cmd): # ----------------------------------------------------------------------- # Helper functions # ----------------------------------------------------------------------- - def _update(self, status, reply_to=None): """Send the update to the server.""" try: @@ -179,13 +177,12 @@ class Interface(cmd.Cmd): requests[network], self._connection.name(network))) - print 'You have %s' % (', '. join(available)) + print 'You have %s' % (', '. join(available)) print # ----------------------------------------------------------------------- # Methods required by the main Mitter code # ----------------------------------------------------------------------- - def __init__(self, connection, options): """Class initialization.""" diff --git a/tests.py b/tests.py index 4f145c2..950d81c 100644 --- a/tests.py +++ b/tests.py @@ -38,12 +38,12 @@ class TwitterEncodingTests(unittest.TestCase): def setUp(self): # Generate a set of options required for starting the Twitter # connection. - options = ConfigOpt() - twitter.Connection.options(options) - self.connection = twitter.Connection(options) # we don't call options(), so it won't load the options in the config # file. If tests need to test specific options, they can change # options directly. + options = ConfigOpt() + twitter.Connection.options(options) + self.connection = twitter.Connection(options) def test_twitter_unhtml(self): """Test the _unhtml() function inside the Twitter."""