PEP8 style fixes and other small style fixes

I used autopep8 on some files and did carefully check the changes.
I ignored E501,E302,E231,E225,E222,E221,E241,E203 in my search, and at
least E501 on any autopep8 run.

Other style fixes not related to PEP8:
* Only use new-style classes. I don't think the usage of old-style
  classes was voluntary. Old-style classes are removed in Python 3.
* Convert an if/else to a one-liner in mediawiki, change docstring style
  change to a comment something that wasn't really appropriate for a
  docstring.
* Unneeded first if condition in meteofrance
This commit is contained in:
Laurent Bachelier 2012-03-14 03:24:02 +01:00
commit 006e97a8be
32 changed files with 441 additions and 350 deletions

View file

@ -1 +0,0 @@

View file

@ -1 +0,0 @@

View file

@ -49,6 +49,7 @@ class QifFormatter(IFormatter):
self.count += 1
return result
class TransactionsFormatter(IFormatter):
MANDATORY_FIELDS = ('date', 'label', 'amount')
TYPES = ['', 'Transfer', 'Order', 'Check', 'Deposit', 'Payback', 'Withdrawal', 'Card', 'Loan', 'Bank']
@ -82,6 +83,7 @@ class TransactionsFormatter(IFormatter):
result += ' %-10s %-12s %-50s %10.2f' % (item['date'].strftime('%Y-%m-%d'), _type, label[:50], item['amount'])
return result
class TransferFormatter(IFormatter):
MANDATORY_FIELDS = ('id', 'date', 'origin', 'recipient', 'amount')
@ -96,6 +98,7 @@ class TransferFormatter(IFormatter):
result += u'Amount: %.2f\n' % item['amount']
return result
class RecipientListFormatter(IFormatter):
MANDATORY_FIELDS = ('id', 'label')
@ -115,6 +118,7 @@ class RecipientListFormatter(IFormatter):
return u'%s %-30s %s %s' % (self.BOLD, id, self.NC, item['label'])
class AccountListFormatter(IFormatter):
MANDATORY_FIELDS = ('id', 'label', 'balance', 'coming')
@ -122,13 +126,12 @@ class AccountListFormatter(IFormatter):
tot_balance = 0.0
tot_coming = 0.0
def flush(self):
if self.count < 1:
return
result = u'------------------------------------------%s+----------+----------\n' % (('-' * 15) if not self.interactive else '')
result +=u'%s Total %8s %8s' % ((' ' * 15) if not self.interactive else '',
result += u'%s Total %8s %8s' % ((' ' * 15) if not self.interactive else '',
'%.2f' % self.tot_balance, '%.2f' % self.tot_coming)
self.after_format(result)
self.tot_balance = 0.0
@ -156,6 +159,7 @@ class AccountListFormatter(IFormatter):
self.tot_coming += item['coming']
return result
class Boobank(ReplApplication):
APPNAME = 'boobank'
VERSION = '0.b'
@ -278,7 +282,7 @@ class Boobank(ReplApplication):
try:
amount = float(amount)
except (TypeError,ValueError):
except (TypeError, ValueError):
print >>sys.stderr, 'Error: please give a decimal amount to transfer'
return 2

View file

@ -124,7 +124,7 @@ class MasstransitHildon():
self.main_window.connect("destroy", self.on_main_window_destroy)
self.refresh_button.connect("clicked", self.on_refresh_button_clicked)
self.retour_button.set_sensitive(False)
self.retour_button.connect("clicked", self.on_retour_button_clicked)
@ -165,8 +165,8 @@ class MasstransitHildon():
text=4
))
vertical_box = gtk.VBox()
vertical_box.pack_start(horizontal_box)
horizontal_box.pack_start(self.retour_button)
@ -187,7 +187,7 @@ class MasstransitHildon():
def fill_touch_selector_entry(self):
liste = []
for backend in self.weboob.iter_backends():
for station in backend.iter_station_search(""):
liste.append(station.name.capitalize())
@ -272,7 +272,7 @@ class MasstransitHildon():
self.refresh_in_progress = False
banner.set_timeout(1)
hildon.hildon_gtk_window_set_progress_indicator(self.main_window, 0)
hildon.hildon_gtk_window_set_progress_indicator(self.main_window, 0)
class Masstransit(BaseApplication):

View file

@ -1,3 +1,4 @@
from .qwebcontentedit import QWebContentEdit
__all__ = ['QWebContentEdit']
__all__ = ['QWebContentEdit']

View file

@ -22,6 +22,7 @@ from weboob.capabilities.content import ICapContent
from .main_window import MainWindow
class QWebContentEdit(QtApplication):
APPNAME = 'qwebcontentedit'
VERSION = '0.b'
@ -34,5 +35,3 @@ class QWebContentEdit(QtApplication):
self.main_window = MainWindow(self.config, self.weboob)
self.main_window.show()
return self.weboob.loop()

View file

@ -124,8 +124,8 @@ class WeboobRepos(ReplApplication):
'--keyring', os.path.realpath(krname),
'--import', os.path.realpath(keypath)])
# Does not make much sense in our case
if os.path.exists(krname+'~'):
os.remove(krname+'~')
if os.path.exists(krname + '~'):
os.remove(krname + '~')
if not os.path.exists(krname):
raise Exception('No valid key file found.')
kr_mtime = mktime(strptime(str(r.key_update), '%Y%m%d%H%M'))
@ -134,7 +134,6 @@ class WeboobRepos(ReplApplication):
else:
print 'Keyring is up to date'
for name, module in r.modules.iteritems():
tarname = os.path.join(repo_path, '%s.tar.gz' % name)
if r.signed:
@ -185,7 +184,7 @@ class WeboobRepos(ReplApplication):
# Check if all files have an up to date signature
for filename in sigfiles:
filepath = os.path.realpath(os.path.join(repo_path, filename))
sigpath = filepath+'.sig'
sigpath = filepath + '.sig'
file_mtime = int(os.path.getmtime(filepath))
if os.path.exists(sigpath):
sig_mtime = int(os.path.getmtime(sigpath))
@ -202,7 +201,6 @@ class WeboobRepos(ReplApplication):
os.utime(sigpath, (file_mtime, file_mtime))
print 'Signatures are up to date'
@staticmethod
def _find_gpg():
if os.getenv('GPG_EXECUTABLE'):
@ -221,4 +219,3 @@ class WeboobRepos(ReplApplication):
if filename.endswith('.png'):
return True
return False

View file

@ -64,6 +64,7 @@ class NotLoaded(object):
class IBaseCap(object):
pass
class CapBaseObject(object):
FIELDS = None
_attribs = None
@ -128,7 +129,7 @@ class CapBaseObject(object):
if self.FIELDS is None:
yield 'id', self.id
for key, value in iter_fields(self):
if key not in ('id', 'backend','FIELDS'):
if key not in ('id', 'backend', 'FIELDS'):
yield key, value
else:
yield 'id', self.id

View file

@ -24,6 +24,7 @@ from weboob.tools.ordereddict import OrderedDict
__all__ = ['ICapContact', 'Contact']
class ProfileNode(object):
HEAD = 0x01
SECTION = 0x02
@ -38,6 +39,7 @@ class ProfileNode(object):
def __getitem__(self, key):
return self.value[key]
class ContactPhoto(CapBaseObject):
def __init__(self, name):
CapBaseObject.__init__(self, name)
@ -59,6 +61,7 @@ class ContactPhoto(CapBaseObject):
len(self.data) if self.data else 0,
len(self.thumbnail_data) if self.thumbnail_data else 0)
class Contact(CapBaseObject):
STATUS_ONLINE = 0x001
STATUS_AWAY = 0x002
@ -83,14 +86,17 @@ class Contact(CapBaseObject):
for key, value in kwargs.iteritems():
setattr(photo, key, value)
class QueryError(Exception):
pass
class Query(CapBaseObject):
def __init__(self, id, message):
CapBaseObject.__init__(self, id)
self.add_field('message', basestring, message)
class ICapContact(IBaseCap):
def iter_contacts(self, status=Contact.STATUS_ALL, ids=None):
"""
@ -129,20 +135,20 @@ class ICapContact(IBaseCap):
@except QueryError
"""
raise NotImplementedError()
def get_notes(self, id):
"""
Get personal notes about a contact
@param id the ID of the contact
@return a unicode object
"""
raise NotImplementedError
def save_notes(self, id, notes):
"""
Set personal notes about a contact
@param id the ID of the contact
@param notes the unicode object to save as notes
"""

View file

@ -28,9 +28,11 @@ from logging import warning
__all__ = ['BackendsConfig', 'BackendAlreadyExists']
class BackendAlreadyExists(Exception):
pass
class BackendsConfig(object):
class WrongPermissions(Exception):
pass
@ -41,13 +43,13 @@ class BackendsConfig(object):
mode = os.stat(confpath).st_mode
except OSError:
if sys.platform == 'win32':
fptr = open(confpath,'w')
fptr = open(confpath, 'w')
fptr.close()
else:
try:
os.mknod(confpath, 0600)
except OSError:
fptr = open(confpath,'w')
fptr = open(confpath, 'w')
fptr.close()
os.chmod(confpath, 0600)
else:
@ -129,5 +131,3 @@ class BackendsConfig(object):
with open(self.confpath, 'w') as f:
config.write(f)
return True

View file

@ -356,7 +356,7 @@ class Versions(object):
with open(os.path.join(self.path, self.VERSIONS_LIST), 'wb') as fp:
config.write(fp)
class IProgress:
class IProgress(object):
def progress(self, percent, message):
print '=== [%3.0f%%] %s' % (percent*100, message)

View file

@ -1 +0,0 @@

View file

@ -1 +0,0 @@

View file

@ -92,7 +92,7 @@ class IFormatter(object):
if sys.platform == 'win32':
self.termrows = WConio.gettextinfo()[8]
else:
self.termrows = int( subprocess.Popen('stty size', shell=True, stdout=subprocess.PIPE).communicate()[0].split()[0])
self.termrows = int(subprocess.Popen('stty size', shell=True, stdout=subprocess.PIPE).communicate()[0].split()[0])
def after_format(self, formatted):
if self.outfile != sys.stdout:

View file

@ -36,9 +36,9 @@ class WebBrowser(gtk.Window):
self.connect('destroy', gtk.main_quit)
self.set_default_size(800, 600)
self.web_view = webkit.WebView()
sw = gtk.ScrolledWindow()
sw.add(self.web_view)
self.add(sw)
sw = gtk.ScrolledWindow()
sw.add(self.web_view)
self.add(sw)
self.show_all()

View file

@ -62,6 +62,7 @@ class BackendStorage(object):
if self.storage:
return self.storage.save('backends', self.name)
class BackendConfig(ValuesDict):
modname = None
instname = None
@ -118,6 +119,7 @@ class BackendConfig(ValuesDict):
self.weboob.backends_config.add_backend(self.instname, self.modname, dump, edit)
class BaseBackend(object):
# Backend name.
NAME = None
@ -149,7 +151,8 @@ class BaseBackend(object):
# NOT yet filled.
OBJECTS = {}
class ConfigError(Exception): pass
class ConfigError(Exception):
pass
def __enter__(self):
self.lock.acquire()
@ -184,6 +187,7 @@ class BaseBackend(object):
class classprop(object):
def __init__(self, fget):
self.fget = fget
def __get__(self, inst, objtype=None):
if inst:
return self.fget(inst)

View file

@ -1 +0,0 @@

View file

@ -28,6 +28,7 @@ from weboob.tools.test import BackendTest
__all__ = ['GenericComicReaderBackend']
class DisplayPage(BasePage):
def get_page(self, gallery):
src = self.document.xpath(self.browser.params['img_src_xpath'])[0]
@ -102,7 +103,6 @@ class GenericComicReaderBackend(BaseBackend, ICapGallery):
else:
return None
gallery = BaseGallery(_id, url=(self.ID_TO_URL % _id))
with self.browser:
return gallery
@ -116,7 +116,7 @@ class GenericComicReaderBackend(BaseBackend, ICapGallery):
OBJECTS = {
BaseGallery: fill_gallery,
BaseImage: fill_image }
BaseImage: fill_image}
class GenericComicReaderTest(BackendTest):
@ -126,4 +126,3 @@ class GenericComicReaderTest(BackendTest):
it.next()
img = it.next()
self.backend.fillobj(img, ('url', 'data'))

View file

@ -20,11 +20,12 @@
# python2.5 compatibility
from __future__ import with_statement
import time
import time
from weboob.capabilities.messages import ICapMessages, Message, Thread
from weboob.tools.backend import BaseBackend
from weboob.tools.newsfeed import Newsfeed
class GenericNewspaperBackend(BaseBackend, ICapMessages):
"GenericNewspaperBackend class"
MAINTAINER = 'Julien Hebert'
@ -71,13 +72,13 @@ class GenericNewspaperBackend(BaseBackend, ICapMessages):
content=content.body,
signature='URL: %s' % content.url,
flags=flags,
children= [])
children=[])
return thread
def iter_threads(self):
for article in Newsfeed(self.RSS_FEED, GenericNewspaperBackend.RSSID).iter_entries():
thread = Thread(article.id)
thread.title = article.title
thread.title = article.title
thread.date = article.datetime
yield(thread)
@ -112,7 +113,7 @@ class GenericNewspaperBackend(BaseBackend, ICapMessages):
if time.time() - lastpurge > 7200:
self.storage.set('lastpurge', time.time())
for id in self.storage.get('seen', default={}):
l.append((int(url2id(id)), id))
l.append((int(url2id(id)), id))
l.sort()
l.reverse()
tosave = [v[1] for v in l[0:self.RSSSIZE + 10]]

Some files were not shown because too many files have changed in this diff Show more