From 619b97669dfd006bb0817ebad9ac47d861c03d2a Mon Sep 17 00:00:00 2001 From: Laurent Bachelier Date: Thu, 21 Apr 2011 20:12:00 +0200 Subject: [PATCH] Enhance domain checking of url2id * Do not check for the domain if it is empty in the Browser class * Better check of the domain (actually parse the URL domain) * Add docstring --- weboob/tools/browser/decorators.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/weboob/tools/browser/decorators.py b/weboob/tools/browser/decorators.py index 85a1b9fc..bbaa731c 100644 --- a/weboob/tools/browser/decorators.py +++ b/weboob/tools/browser/decorators.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright(C) 2010-2011 Christophe Benz +# Copyright(C) 2010-2011 Christophe Benz, Laurent Bachelier # # This file is part of weboob. # @@ -20,6 +20,7 @@ __all__ = ['check_domain', 'id2url'] +from urlparse import urlsplit def check_domain(domain): def wrapper(func): @@ -32,11 +33,20 @@ def check_domain(domain): def id2url(id2url): + """ + If the first argument is not an URL, this decorator will try to + convert it to one, by calling the id2url function. + If id2url returns None (because the id is invalid), the decorated + function will not be called and None will be returned. + If the DOMAIN attribute of the method's class is not empty, it will + also check it. If it does not match, the decorated function will not + be called and None will be returned. + """ def wrapper(func): def inner(self, *args, **kwargs): arg = unicode(args[0]) if arg.startswith('http://') or arg.startswith('https://'): - if self.DOMAIN in arg: + if self.DOMAIN and self.DOMAIN == urlsplit(arg).netloc: url = arg else: return None