Browse Source

PEP8 fixed

master
Julio Biason 15 years ago
parent
commit
32f26f20d0
  1. 4
      mitterlib/__init__.py
  2. 3
      mitterlib/network/__init__.py
  3. 12
      mitterlib/network/networkbase.py
  4. 4
      mitterlib/network/twitter.py
  5. 1
      mitterlib/ui/__init__.py
  6. 1
      mitterlib/ui/helpers/console_utils.py
  7. 3
      mitterlib/ui/helpers/image_helpers.py
  8. 1
      mitterlib/ui/helpers/timesince.py
  9. 4
      mitterlib/ui/ui_cmd.py
  10. 5
      mitterlib/ui/ui_pygtk.py
  11. 3
      mitterlib/ui/ui_tty.py
  12. 7
      mitterlib/ui/ui_zork.py
  13. 6
      tests.py

4
mitterlib/__init__.py

@ -21,6 +21,7 @@ import os.path
import glob import glob
import htmlentitydefs import htmlentitydefs
def module_search(source, ignore): 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.""" indicated."""
@ -39,6 +40,7 @@ def module_search(source, ignore):
# "importable" # "importable"
yield module_name yield module_name
def htmlize(text): def htmlize(text):
"""Convert accented characters to their HTML entities.""" """Convert accented characters to their HTML entities."""
new = [] new = []
@ -50,5 +52,3 @@ def htmlize(text):
else: else:
new.append(char) new.append(char)
return ''.join(new) return ''.join(new)

3
mitterlib/network/__init__.py

@ -32,7 +32,6 @@ SKIPPABLES = ('__init__.py', 'networkbase.py')
# Helper functions # Helper functions
#-------------------------------------------------------------------- #--------------------------------------------------------------------
def _import_name(module): def _import_name(module):
"""Based on the name of the module, return the proper "import" """Based on the name of the module, return the proper "import"
statement.""" statement."""
@ -44,7 +43,6 @@ def _import_name(module):
# Exceptions # Exceptions
#-------------------------------------------------------------------- #--------------------------------------------------------------------
class NetworksError(Exception): class NetworksError(Exception):
"""Basic Networks exception.""" """Basic Networks exception."""
pass pass
@ -151,7 +149,6 @@ class Networks(object):
# This is basically a copy of all methods available in NetworkBase, with # This is basically a copy of all methods available in NetworkBase, with
# the additional parameter "network" (to request data from just one # the additional parameter "network" (to request data from just one
# source) # source)
def messages(self, network=None): def messages(self, network=None):
"""Return a list of NetworkData objects for the main "timeline" (the """Return a list of NetworkData objects for the main "timeline" (the
default list presented to the user.)""" default list presented to the user.)"""

12
mitterlib/network/networkbase.py

@ -44,7 +44,6 @@ def auth_options(namespace, options, auths):
# Exceptions # Exceptions
#-------------------------------------------------------------------- #--------------------------------------------------------------------
class NetworkError(Exception): class NetworkError(Exception):
"""Base class for all network related exceptions.""" """Base class for all network related exceptions."""
pass pass
@ -92,10 +91,12 @@ class NetworkPermissionDeniedError(NetworkError):
#-------------------------------------------------------------------- #--------------------------------------------------------------------
# Warnings # Warnings
#-------------------------------------------------------------------- #--------------------------------------------------------------------
class NetworkWarning(Warning): class NetworkWarning(Warning):
"""Base warning for networks.""" """Base warning for networks."""
pass pass
class MessageTooLongWarning(NetworkWarning): class MessageTooLongWarning(NetworkWarning):
"""The message is too long for the network.""" """The message is too long for the network."""
pass pass
@ -104,7 +105,6 @@ class MessageTooLongWarning(NetworkWarning):
# The classes # The classes
#-------------------------------------------------------------------- #--------------------------------------------------------------------
class NetworkData(object): class NetworkData(object):
"""Provides an uniform way to access information about posts. The """Provides an uniform way to access information about posts. The
following fields should appear: following fields should appear:
@ -143,6 +143,7 @@ class NetworkData(object):
worry about this field themselves; :class:`Networks` will set it when worry about this field themselves; :class:`Networks` will set it when
merging information from all networks. merging information from all networks.
""" """
def __init__(self): def __init__(self):
self.id = '' self.id = ''
self.name = '' self.name = ''
@ -189,7 +190,6 @@ class NetworkBase(object):
if possible. if possible.
""" """
def is_setup(self): def is_setup(self):
"""Should return a boolean indicating if the network have all """Should return a boolean indicating if the network have all
necessary options set up so it can retrieve information. necessary options set up so it can retrieve information.
@ -244,12 +244,12 @@ class NetworkBase(object):
def can_delete(self, message): def can_delete(self, message):
"""Return True if the message can be deleted; False otherwise.""" """Return True if the message can be deleted; False otherwise."""
return False; return False
def can_reply(self, message): def can_reply(self, message):
"""Return True if the message can be replied; False otherwise.""" """Return True if the message can be replied; False otherwise."""
return False; return False
def can_repost(self, message): def can_repost(self, message):
"""Return True if the message can be resposted; False otherwise.""" """Return True if the message can be resposted; False otherwise."""
return False; return False

4
mitterlib/network/twitter.py

@ -365,7 +365,6 @@ class Connection(NetworkBase):
_log.debug('Requests: %s', data) _log.debug('Requests: %s', data)
return int(data['remaining_hits']) return int(data['remaining_hits'])
def update(self, status, reply_to=None): def update(self, status, reply_to=None):
"""Update the user status.""" """Update the user status."""
if len(status) > 140: if len(status) > 140:
@ -423,7 +422,6 @@ class Connection(NetworkBase):
_log.debug('Delete response: %s', response) _log.debug('Delete response: %s', response)
return True # Either we get a response or an exception before we reach return True # Either we get a response or an exception before we reach
# this. # this.
def can_delete(self, message): def can_delete(self, message):
"""Check if the message belongs to the user. If so, returns True; """Check if the message belongs to the user. If so, returns True;
False otherwise.""" False otherwise."""
@ -432,7 +430,7 @@ class Connection(NetworkBase):
def can_reply(self, message): def can_reply(self, message):
"""Always return True; Twitter allows replying to any messages, """Always return True; Twitter allows replying to any messages,
including the ones from the user.""" including the ones from the user."""
return True; return True
def can_repost(self, message): def can_repost(self, message):
"""Twitter ignores retweets from the user.""" """Twitter ignores retweets from the user."""

1
mitterlib/ui/__init__.py

@ -31,7 +31,6 @@ SKIPPABLES = ('__init__.py')
# Helper functions # Helper functions
#-------------------------------------------------------------------- #--------------------------------------------------------------------
def _import_name(module): def _import_name(module):
"""Based on the name of the module, return the proper "import" """Based on the name of the module, return the proper "import"
statement.""" statement."""

1
mitterlib/ui/helpers/console_utils.py

@ -189,6 +189,7 @@ def print_thread(thread_list, connection):
pos += 1 pos += 1
return return
def make_retweet(message): def make_retweet(message):
"""Creates the text for a reweet.""" """Creates the text for a reweet."""
if not message.message.lower().startswith('rt @'): if not message.message.lower().startswith('rt @'):

3
mitterlib/ui/helpers/image_helpers.py

@ -21,8 +21,9 @@ import os.path
import sys import sys
import logging import logging
def find_image(image_name): 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.""" the image or None if the image couldn't be found."""
# just because I'm a logging nut # just because I'm a logging nut

1
mitterlib/ui/helpers/timesince.py

@ -26,7 +26,6 @@ import time
# http://code.djangoproject.com/browser/django/trunk/django/utils/timesince.py # http://code.djangoproject.com/browser/django/trunk/django/utils/timesince.py
# My version expects time to be given in UTC & returns timedelta from UTC. # My version expects time to be given in UTC & returns timedelta from UTC.
def pluralize(singular, plural, count): def pluralize(singular, plural, count):
if count == 1: if count == 1:
return singular return singular

4
mitterlib/ui/ui_cmd.py

@ -40,7 +40,6 @@ class Interface(cmd.Cmd):
# ----------------------------------------------------------------------- # -----------------------------------------------------------------------
# Methods required by cmd.Cmd (our commands) # Methods required by cmd.Cmd (our commands)
# ----------------------------------------------------------------------- # -----------------------------------------------------------------------
def do_config(self, line=None): def do_config(self, line=None):
"""Setup the networks.""" """Setup the networks."""
options = self._connection.settings() options = self._connection.settings()
@ -157,7 +156,6 @@ class Interface(cmd.Cmd):
# ----------------------------------------------------------------------- # -----------------------------------------------------------------------
# Helper functions # Helper functions
# ----------------------------------------------------------------------- # -----------------------------------------------------------------------
def _check_message(self, message_id): def _check_message(self, message_id):
"""Check if a message is valid in the current list.""" """Check if a message is valid in the current list."""
if message_id < 1 or message_id > len(self._messages): if message_id < 1 or message_id > len(self._messages):
@ -234,11 +232,9 @@ class Interface(cmd.Cmd):
(update_text, ', '.join(available))) (update_text, ', '.join(available)))
return return
# ----------------------------------------------------------------------- # -----------------------------------------------------------------------
# Methods required by the main Mitter code # Methods required by the main Mitter code
# ----------------------------------------------------------------------- # -----------------------------------------------------------------------
def __init__(self, connection, options): def __init__(self, connection, options):
"""Class initialization.""" """Class initialization."""

5
mitterlib/ui/ui_pygtk.py

@ -67,6 +67,7 @@ class _IdleObject(gobject.GObject):
Override gobject.GObject to always emit signals in the main thread Override gobject.GObject to always emit signals in the main thread
by emmitting on an idle handler by emmitting on an idle handler
""" """
def __init__(self): def __init__(self):
gobject.GObject.__init__(self) gobject.GObject.__init__(self)
@ -86,8 +87,7 @@ class _WorkerThread(threading.Thread, _IdleObject):
"exception": ( "exception": (
gobject.SIGNAL_RUN_LAST, gobject.SIGNAL_RUN_LAST,
gobject.TYPE_NONE, gobject.TYPE_NONE,
(gobject.TYPE_PYOBJECT,)) # The exception (gobject.TYPE_PYOBJECT, ))} # The exception
}
def __init__(self, function, *args, **kwargs): def __init__(self, function, *args, **kwargs):
threading.Thread.__init__(self) threading.Thread.__init__(self)
@ -669,7 +669,6 @@ class Interface(object):
return True return True
# ------------------------------------------------------------ # ------------------------------------------------------------
# Widget callback functions # Widget callback functions
# ------------------------------------------------------------ # ------------------------------------------------------------

3
mitterlib/ui/ui_tty.py

@ -35,7 +35,6 @@ class Interface(object):
# ----------------------------------------------------------------------- # -----------------------------------------------------------------------
# Private functions # Private functions
# ----------------------------------------------------------------------- # -----------------------------------------------------------------------
def _config(self): def _config(self):
"""Set up the networks.""" """Set up the networks."""
options = self._connection.settings() options = self._connection.settings()
@ -75,11 +74,9 @@ class Interface(object):
return return
# ----------------------------------------------------------------------- # -----------------------------------------------------------------------
# Methods required by the main Mitter code # Methods required by the main Mitter code
# ----------------------------------------------------------------------- # -----------------------------------------------------------------------
def __init__(self, connection, options): def __init__(self, connection, options):
"""Class initialization.""" """Class initialization."""
self._connection = connection self._connection = connection

7
mitterlib/ui/ui_zork.py

@ -37,7 +37,6 @@ class Interface(cmd.Cmd):
# ----------------------------------------------------------------------- # -----------------------------------------------------------------------
# Commands # Commands
# ----------------------------------------------------------------------- # -----------------------------------------------------------------------
def do_config(self, line=None): def do_config(self, line=None):
"""Setup the networks.""" """Setup the networks."""
options = self._connection.settings() options = self._connection.settings()
@ -127,9 +126,9 @@ class Interface(cmd.Cmd):
"""Update your status.""" """Update your status."""
if self._update(line): if self._update(line):
print 'Status updated' print 'Status updated'
# clear the message so it's not send if the user press enter
# twice.
self.lastcmd = None self.lastcmd = None
# So we don't send the same message if the user pressed enter
# again
def do_thread(self, line): def do_thread(self, line):
"""Display the conversation thread with the message pointed by the """Display the conversation thread with the message pointed by the
@ -153,7 +152,6 @@ class Interface(cmd.Cmd):
# ----------------------------------------------------------------------- # -----------------------------------------------------------------------
# Helper functions # Helper functions
# ----------------------------------------------------------------------- # -----------------------------------------------------------------------
def _update(self, status, reply_to=None): def _update(self, status, reply_to=None):
"""Send the update to the server.""" """Send the update to the server."""
try: try:
@ -185,7 +183,6 @@ class Interface(cmd.Cmd):
# ----------------------------------------------------------------------- # -----------------------------------------------------------------------
# Methods required by the main Mitter code # Methods required by the main Mitter code
# ----------------------------------------------------------------------- # -----------------------------------------------------------------------
def __init__(self, connection, options): def __init__(self, connection, options):
"""Class initialization.""" """Class initialization."""

6
tests.py

@ -38,12 +38,12 @@ class TwitterEncodingTests(unittest.TestCase):
def setUp(self): def setUp(self):
# Generate a set of options required for starting the Twitter # Generate a set of options required for starting the Twitter
# connection. # 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 # 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 # file. If tests need to test specific options, they can change
# options directly. # options directly.
options = ConfigOpt()
twitter.Connection.options(options)
self.connection = twitter.Connection(options)
def test_twitter_unhtml(self): def test_twitter_unhtml(self):
"""Test the _unhtml() function inside the Twitter.""" """Test the _unhtml() function inside the Twitter."""

Loading…
Cancel
Save