Introduce local exception for SSL errors

It removes the import of SSL in console applications (SSL -> socket ->
base64 -> ...)
This commit is contained in:
Florent 2014-07-09 11:45:39 +02:00
commit e12485dc84
3 changed files with 8 additions and 5 deletions

View file

@ -27,14 +27,13 @@ import subprocess
import sys
import os
import locale
from ssl import SSLError
from weboob.capabilities import UserError
from weboob.capabilities.account import CapAccount, Account, AccountRegisterError
from weboob.core.backendscfg import BackendAlreadyExists
from weboob.core.modules import ModuleLoadError
from weboob.core.repositories import ModuleInstallError
from weboob.tools.exceptions import BrowserUnavailable, BrowserIncorrectPassword, BrowserForbidden
from weboob.tools.exceptions import BrowserUnavailable, BrowserIncorrectPassword, BrowserForbidden, BrowserSSLError
from weboob.tools.value import Value, ValueBool, ValueFloat, ValueInt, ValueBackendPassword
from weboob.tools.misc import to_unicode
from weboob.tools.ordereddict import OrderedDict
@ -545,7 +544,7 @@ class ConsoleApplication(BaseApplication):
print(u'Error(%s): %s' % (backend.name, to_unicode(error)), file=sys.stderr)
elif isinstance(error, MoreResultsAvailable):
print(u'Hint: There are more results for backend %s' % (backend.name), file=sys.stderr)
elif isinstance(error, SSLError):
elif isinstance(error, BrowserSSLError):
print(u'FATAL(%s): ' % backend.name + self.BOLD + '/!\ SERVER CERTIFICATE IS INVALID /!\\' + self.NC, file=sys.stderr)
else:
print(u'Bug(%s): %s' % (backend.name, to_unicode(error)), file=sys.stderr)

View file

@ -49,7 +49,7 @@ from contextlib import closing
from gzip import GzipFile
import warnings
from weboob.tools.exceptions import BrowserUnavailable, BrowserIncorrectPassword, BrowserPasswordExpired, BrowserForbidden, BrowserBanned, BrowserHTTPNotFound, BrowserHTTPError, FormFieldConversionWarning
from weboob.tools.exceptions import BrowserUnavailable, BrowserIncorrectPassword, BrowserPasswordExpired, BrowserForbidden, BrowserBanned, BrowserHTTPNotFound, BrowserHTTPError, FormFieldConversionWarning, BrowserSSLError
from weboob.tools.decorators import retry
from weboob.tools.log import getLogger
from weboob.tools.mech import ClientForm
@ -409,7 +409,7 @@ class StandardBrowser(mechanize.Browser):
if isinstance(hsh, basestring):
hsh = [hsh]
if certhash not in hsh:
raise ssl.SSLError()
raise BrowserSSLError()
def _certhash(self, domain, port=443):
certs = ssl.get_server_certificate((domain, port))

View file

@ -46,6 +46,10 @@ class BrowserHTTPError(BrowserUnavailable):
pass
class BrowserSSLError(BrowserUnavailable):
pass
class ParseError(Exception):
pass