From 05b9bbdb2eb135cd30b61ec966eeb9ff500b1742 Mon Sep 17 00:00:00 2001 From: Laurent Bachelier Date: Tue, 10 Aug 2010 18:15:22 +0200 Subject: [PATCH] Fix for ClientForm in mechanize >=0.2 refs #362 --- weboob/backends/bnporc/pages/login.py | 2 +- weboob/backends/cragr/pages/login.py | 7 ++----- weboob/backends/youporn/pages/base.py | 6 ++---- weboob/tools/browser/browser.py | 6 ++---- weboob/tools/mech.py | 23 +++++++++++++++++++++++ 5 files changed, 30 insertions(+), 14 deletions(-) create mode 100644 weboob/tools/mech.py diff --git a/weboob/backends/bnporc/pages/login.py b/weboob/backends/bnporc/pages/login.py index a8f7499b..ffbfd464 100644 --- a/weboob/backends/bnporc/pages/login.py +++ b/weboob/backends/bnporc/pages/login.py @@ -16,7 +16,7 @@ # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -import ClientForm +from weboob.tools.mech import ClientForm import sys from weboob.tools.browser import BasePage diff --git a/weboob/backends/cragr/pages/login.py b/weboob/backends/cragr/pages/login.py index c3ca9d5f..9a7e1db6 100644 --- a/weboob/backends/cragr/pages/login.py +++ b/weboob/backends/cragr/pages/login.py @@ -16,11 +16,8 @@ # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -try: - from mechanize import ControlNotFoundError -except ImportError: - from ClientForm import ControlNotFoundError -import ClientForm +from weboob.tools.mech import ClientForm +ControlNotFoundError = ClientForm.ControlNotFoundError from .base import CragrBasePage diff --git a/weboob/backends/youporn/pages/base.py b/weboob/backends/youporn/pages/base.py index 382f4998..2ecc609d 100644 --- a/weboob/backends/youporn/pages/base.py +++ b/weboob/backends/youporn/pages/base.py @@ -15,10 +15,8 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -try: - from mechanize import ControlNotFoundError -except ImportError: - from ClientForm import ControlNotFoundError +from weboob.tools.mech import ClientForm +ControlNotFoundError = ClientForm.ControlNotFoundError from mechanize import FormNotFoundError from weboob.tools.browser import BasePage diff --git a/weboob/tools/browser/browser.py b/weboob/tools/browser/browser.py index c64e0e9d..dd146a3f 100644 --- a/weboob/tools/browser/browser.py +++ b/weboob/tools/browser/browser.py @@ -19,10 +19,8 @@ import mechanize import urllib import urllib2 -try: - from mechanize import ControlNotFoundError -except ImportError: - from ClientForm import ControlNotFoundError +from weboob.tools.mech import ClientForm +ControlNotFoundError = ClientForm.ControlNotFoundError import re import time from logging import warning, debug diff --git a/weboob/tools/mech.py b/weboob/tools/mech.py new file mode 100644 index 00000000..1790be0a --- /dev/null +++ b/weboob/tools/mech.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- + +# Copyright(C) 2010 Laurent Bachelier +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, version 3 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +import mechanize +if hasattr(mechanize, "FormParser"): + ClientForm = mechanize +else: + import ClientForm +