Use flake8 if available instead of pyflakes

With flake8, we can check for more issues and ignore those who are not
real issues.

This allowed me to find genuine errors in:
- modules/boursorama/pages/account_history.py
- modules/ing/pages/login.py
- weboob/tools/application/qt/qt.py
I left one in weboob/tools/browser/browser.py for the time being.

Some PEP8 fixes on other files.
This commit is contained in:
Laurent Bachelier 2012-11-24 19:46:34 +01:00
commit 541d080c9d
18 changed files with 54 additions and 45 deletions

View file

@ -21,7 +21,7 @@
try: try:
import sqlite3 as sqlite import sqlite3 as sqlite
except ImportError, e: except ImportError, e:
from pysqlite2 import dbapi2 as sqlite from pysqlite2 import dbapi2 as sqlite # NOQA
from weboob.core import Weboob from weboob.core import Weboob
from weboob.core.modules import ModuleLoadError from weboob.core.modules import ModuleLoadError
@ -30,6 +30,7 @@ import logging
level = logging.DEBUG level = logging.DEBUG
logging.basicConfig(stream=sys.stdout, level=level) logging.basicConfig(stream=sys.stdout, level=level)
def main(filename): def main(filename):
weboob = Weboob() weboob = Weboob()
try: try:

View file

@ -23,7 +23,6 @@ from datetime import date
import re import re
from weboob.tools.browser import BasePage from weboob.tools.browser import BasePage
from weboob.capabilities.bank import Transaction
from weboob.tools.capabilities.bank.transactions import FrenchTransaction from weboob.tools.capabilities.bank.transactions import FrenchTransaction

View file

@ -25,7 +25,7 @@ from logging import warning, debug
try: try:
from urlparse import parse_qs from urlparse import parse_qs
except ImportError: except ImportError:
from cgi import parse_qs from cgi import parse_qs # NOQA
from weboob.tools.misc import html2text, get_bytes_size from weboob.tools.misc import html2text, get_bytes_size
from weboob.capabilities.torrent import Torrent from weboob.capabilities.torrent import Torrent
@ -69,7 +69,7 @@ class TorrentsPage(BasePage):
current_group += ' - ' current_group += ' - '
current_group += a.text current_group += a.text
elif tr.attrib.get('class', '').startswith('group_torrent') or \ elif tr.attrib.get('class', '').startswith('group_torrent') or \
tr.attrib.get('class', '').startswith('torrent'): tr.attrib.get('class', '').startswith('torrent'):
tds = tr.findall('td') tds = tr.findall('td')
title = current_group title = current_group
@ -100,9 +100,9 @@ class TorrentsPage(BasePage):
continue continue
id = '%s.%s' % (params['id'][0], m.group(1)) id = '%s.%s' % (params['id'][0], m.group(1))
try: try:
size, unit = tds[i+3].text.split() size, unit = tds[i + 3].text.split()
except ValueError: except ValueError:
size, unit = tds[i+2].text.split() size, unit = tds[i + 2].text.split()
size = get_bytes_size(float(size.replace(',', '')), unit) size = get_bytes_size(float(size.replace(',', '')), unit)
seeders = int(tds[-2].text) seeders = int(tds[-2].text)
leechers = int(tds[-1].text) leechers = int(tds[-1].text)
@ -159,8 +159,8 @@ class TorrentsPage(BasePage):
torrent.seeders = int(tds[3].text) torrent.seeders = int(tds[3].text)
torrent.leechers = int(tds[4].text) torrent.leechers = int(tds[4].text)
break break
elif not is_table and tr.attrib.get('class', '').startswith('torrent_widget') and \ elif not is_table and tr.attrib.get('class', '').startswith('torrent_widget') \
tr.attrib.get('class', '').endswith('pad'): and tr.attrib.get('class', '').endswith('pad'):
url = tr.cssselect('a[title=Download]')[0].attrib['href'] url = tr.cssselect('a[title=Download]')[0].attrib['href']
m = self.TORRENTID_REGEXP.match(url) m = self.TORRENTID_REGEXP.match(url)
if not m: if not m:

View file

@ -23,7 +23,7 @@ import re
try: try:
from urlparse import parse_qs from urlparse import parse_qs
except ImportError: except ImportError:
from cgi import parse_qs from cgi import parse_qs # NOQA
from weboob.capabilities import NotAvailable from weboob.capabilities import NotAvailable
from weboob.tools.browser import BasePage, BrokenPageError from weboob.tools.browser import BasePage, BrokenPageError
@ -87,6 +87,7 @@ class BaseVideoPage(BasePage):
def get_description(self): def get_description(self):
raise NotImplementedError() raise NotImplementedError()
class VideoPage(BaseVideoPage): class VideoPage(BaseVideoPage):
URL_REGEXP = re.compile('http://www.ina.fr/(.+)\.html') URL_REGEXP = re.compile('http://www.ina.fr/(.+)\.html')

View file

@ -104,8 +104,9 @@ class LoginPage(BasePage):
self.browser.submit(nologin=True) self.browser.submit(nologin=True)
def error(self): def error(self):
error = self.document.find('//span[@class="error"]') err = self.document.find('//span[@class="error"]')
return error is not None return err is not None
class LoginPage2(BasePage): class LoginPage2(BasePage):
def on_loaded(self): def on_loaded(self):

View file

@ -21,7 +21,7 @@
try: try:
from urlparse import parse_qs from urlparse import parse_qs
except ImportError: except ImportError:
from cgi import parse_qs from cgi import parse_qs # NOQA
from urlparse import urlsplit from urlparse import urlsplit

View file

@ -29,7 +29,7 @@ import re
try: try:
from urlparse import parse_qs from urlparse import parse_qs
except ImportError: except ImportError:
from cgi import parse_qs from cgi import parse_qs # NOQA
__all__ = ['RadioFranceBrowser', 'RadioFranceVideo'] __all__ = ['RadioFranceBrowser', 'RadioFranceVideo']
@ -93,7 +93,6 @@ class ReplayPage(BasePage):
return (radio_domain, player_id) return (radio_domain, player_id)
class DataPage(BasePage): class DataPage(BasePage):
def get_current(self): def get_current(self):
document = self.document document = self.document

View file

@ -1,7 +1,12 @@
#!/bin/bash #!/bin/bash -u
cd $(dirname $0) cd $(dirname $0)
cd .. cd ..
# grep will return 0 only if it founds something, but our script if which flake8 >/dev/null 2>&1; then
# wants to return 0 when it founds nothing! set -e
pyflakes weboob modules contrib scripts/* | grep -v redefinition && exit 1 || exit 0 flake8 --ignore=E,W *.py weboob modules contrib scripts/*
else
# grep will return 0 only if it founds something, but our script
# wants to return 0 when it founds nothing!
pyflakes *.py weboob modules contrib scripts/* | grep -v redefinition && exit 1 || exit 0
fi

View file

@ -24,6 +24,7 @@ from logging import warning
import gtk import gtk
class FakeConic(object): class FakeConic(object):
STATUS_CONNECTED = None STATUS_CONNECTED = None
STATUS_DISCONNECTED = None STATUS_DISCONNECTED = None
@ -37,11 +38,11 @@ except ImportError:
else: else:
toolkit = hildon toolkit = hildon
try : try:
import conic import conic
except ImportError: except ImportError:
warning("conic is not found") warning("conic is not found")
conic = FakeConic() conic = FakeConic() # NOQA
from logging import debug from logging import debug
@ -70,7 +71,7 @@ class MasstransitHildon():
self.refresh_in_progress = False self.refresh_in_progress = False
self.connected = False self.connected = False
self.weboob = weboob self.weboob = weboob
try : try:
self.connection = conic.Connection() self.connection = conic.Connection()
self.connection.connect("connection-event", self.connect_event) self.connection.connect("connection-event", self.connect_event)
self.connection.set_property("automatic-connection-events", True) self.connection.set_property("automatic-connection-events", True)
@ -80,7 +81,7 @@ class MasstransitHildon():
horizontal_box = gtk.HBox() horizontal_box = gtk.HBox()
self.main_window = toolkit.Window() self.main_window = toolkit.Window()
try : try:
self.refresh_button = toolkit.Button( self.refresh_button = toolkit.Button(
gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT, gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT,
hildon.BUTTON_ARRANGEMENT_HORIZONTAL, hildon.BUTTON_ARRANGEMENT_HORIZONTAL,
@ -223,7 +224,7 @@ class MasstransitHildon():
"the refresh button is clicked" "the refresh button is clicked"
debug("on_refresh_button_clicked") debug("on_refresh_button_clicked")
self.refresh_in_progress = True self.refresh_in_progress = True
try : try:
self.connection.request_connection(conic.CONNECT_FLAG_NONE) self.connection.request_connection(conic.CONNECT_FLAG_NONE)
except AttributeError: except AttributeError:
if isinstance(conic, FakeConic): if isinstance(conic, FakeConic):
@ -232,7 +233,7 @@ class MasstransitHildon():
raise raise
def check_station_input(self, widget, user_data): def check_station_input(self, widget, user_data):
if self.combo_source.get_current_text() is None : if self.combo_source.get_current_text() is None:
self.picker_button_dest.set_sensitive(False) self.picker_button_dest.set_sensitive(False)
self.refresh_button.set_sensitive(False) self.refresh_button.set_sensitive(False)
self.retour_button.set_sensitive(False) self.retour_button.set_sensitive(False)
@ -251,7 +252,7 @@ class MasstransitHildon():
banner.set_timeout(10000) banner.set_timeout(10000)
hildon.hildon_gtk_window_set_progress_indicator(self.main_window, 1) hildon.hildon_gtk_window_set_progress_indicator(self.main_window, 1)
self.treestore.clear() self.treestore.clear()
try : try:
source_text = self.combo_source.get_current_text() source_text = self.combo_source.get_current_text()
dest_text = self.combo_dest.get_current_text() dest_text = self.combo_dest.get_current_text()
except AttributeError: except AttributeError:

View file

@ -30,7 +30,7 @@ try:
import tty, termios import tty, termios
except ImportError: except ImportError:
PROMPT = '--Press return to continue--' PROMPT = '--Press return to continue--'
def readch(): def readch(): # NOQA
return sys.stdin.readline() return sys.stdin.readline()
else: else:
PROMPT = '--Press a key to continue--' PROMPT = '--Press a key to continue--'
@ -163,7 +163,6 @@ class IFormatter(object):
self.output(formatted) self.output(formatted)
return formatted return formatted
def format_obj(self, obj, alias=None): def format_obj(self, obj, alias=None):
""" """
Format an object to be human-readable. Format an object to be human-readable.

View file

@ -26,8 +26,7 @@ from PyQt4.QtCore import QTimer, SIGNAL, QObject, QString, QSize, QVariant, QMut
from PyQt4.QtGui import QMainWindow, QApplication, QStyledItemDelegate, \ from PyQt4.QtGui import QMainWindow, QApplication, QStyledItemDelegate, \
QStyleOptionViewItemV4, QTextDocument, QStyle, \ QStyleOptionViewItemV4, QTextDocument, QStyle, \
QAbstractTextDocumentLayout, QPalette, QMessageBox, \ QAbstractTextDocumentLayout, QPalette, QMessageBox, \
QSpinBox, QLineEdit, QComboBox, QCheckBox, QInputDialog, \ QSpinBox, QLineEdit, QComboBox, QCheckBox, QInputDialog
QLineEdit
from weboob.core.ouiboube import Weboob from weboob.core.ouiboube import Weboob
from weboob.core.scheduler import IScheduler from weboob.core.scheduler import IScheduler

View file

@ -21,7 +21,7 @@
try: try:
import sqlite3 as sqlite import sqlite3 as sqlite
except ImportError, e: except ImportError, e:
from pysqlite2 import dbapi2 as sqlite from pysqlite2 import dbapi2 as sqlite # NOQA
from mechanize import CookieJar, Cookie from mechanize import CookieJar, Cookie
@ -47,7 +47,8 @@ class FirefoxCookieJar(CookieJar):
def load(self): def load(self):
db = self.__connect() db = self.__connect()
if not db: return if not db:
return
cookies = db.execute("""SELECT host, path, name, value, expiry, lastAccessed, isSecure cookies = db.execute("""SELECT host, path, name, value, expiry, lastAccessed, isSecure
FROM moz_cookies FROM moz_cookies
@ -83,12 +84,15 @@ class FirefoxCookieJar(CookieJar):
def save(self): def save(self):
db = self.__connect() db = self.__connect()
if not db: return if not db:
return
db.execute("DELETE FROM moz_cookies WHERE host LIKE '%%%s%%'" % self.domain) db.execute("DELETE FROM moz_cookies WHERE host LIKE '%%%s%%'" % self.domain)
for cookie in self: for cookie in self:
if cookie.secure: secure = 1 if cookie.secure:
else: secure = 0 secure = 1
else:
secure = 0
if cookie.expires is not None: if cookie.expires is not None:
expires = cookie.expires expires = cookie.expires
else: else:

View file

@ -29,8 +29,8 @@ try:
from yaml import CLoader as Loader from yaml import CLoader as Loader
from yaml import CDumper as Dumper from yaml import CDumper as Dumper
except ImportError: except ImportError:
from yaml import Loader from yaml import Loader # NOQA
from yaml import Dumper from yaml import Dumper # NOQA
from .iconfig import IConfig, ConfigError from .iconfig import IConfig, ConfigError

View file

@ -27,4 +27,4 @@ try:
import simplejson as json import simplejson as json
except ImportError: except ImportError:
# Python 2.6+ has a module similar to simplejson # Python 2.6+ has a module similar to simplejson
import json import json # NOQA

View file

@ -22,16 +22,15 @@ try:
from collections import OrderedDict from collections import OrderedDict
except ImportError: except ImportError:
try: try:
from simplejson import OrderedDict from simplejson import OrderedDict # NOQA
except ImportError: except ImportError:
try: try:
from ordereddict import OrderedDict from ordereddict import OrderedDict # NOQA
except ImportError: except ImportError:
## {{{ http://code.activestate.com/recipes/576693/ (r6) ## {{{ http://code.activestate.com/recipes/576693/ (r6)
from UserDict import DictMixin from UserDict import DictMixin
class OrderedDict(dict, DictMixin): class OrderedDict(dict, DictMixin): # NOQA
def __init__(self, *args, **kwds): def __init__(self, *args, **kwds):
if len(args) > 1: if len(args) > 1:
raise TypeError('expected at most 1 arguments, got %d' % len(args)) raise TypeError('expected at most 1 arguments, got %d' % len(args))
@ -123,7 +122,7 @@ except ImportError:
def __eq__(self, other): def __eq__(self, other):
if isinstance(other, OrderedDict): if isinstance(other, OrderedDict):
return len(self)==len(other) and self.items() == other.items() return len(self) == len(other) and self.items() == other.items()
return dict.__eq__(self, other) return dict.__eq__(self, other)
def __ne__(self, other): def __ne__(self, other):

View file

@ -30,7 +30,7 @@ from elementtidy import TidyHTMLTreeBuilder
try: try:
from xml.etree import cElementTree as ElementTree from xml.etree import cElementTree as ElementTree
except ImportError: except ImportError:
from xml.etree import ElementTree from xml.etree import ElementTree # NOQA
from .iparser import IParser from .iparser import IParser

View file

@ -22,7 +22,7 @@ from html5lib import treebuilders, HTMLParser
try: try:
from xml.etree import cElementTree as ElementTree from xml.etree import cElementTree as ElementTree
except ImportError: except ImportError:
from xml.etree import ElementTree from xml.etree import ElementTree # NOQA
from .iparser import IParser from .iparser import IParser

View file

@ -23,7 +23,7 @@ import htmlentitydefs
try: try:
from xml.etree import cElementTree as ElementTree from xml.etree import cElementTree as ElementTree
except ImportError: except ImportError:
from xml.etree import ElementTree from xml.etree import ElementTree # NOQA
from .iparser import IParser from .iparser import IParser
@ -68,6 +68,7 @@ class HTMLTreeBuilder(_HTMLParser):
except: except:
pass pass
class HTMLParser(IParser): class HTMLParser(IParser):
def parse(self, data, encoding=None): def parse(self, data, encoding=None):
parser = HTMLTreeBuilder(encoding) parser = HTMLTreeBuilder(encoding)