Mercurial > moin > 1.9
changeset 4308:3a4426122606
Code review: factor in the simple spider check
author | Florian Krupicka <florian.krupicka@googlemail.com> |
---|---|
date | Thu, 14 Aug 2008 22:35:27 +0200 |
parents | dca46d0c55f6 |
children | 7d97ce960ec2 |
files | MoinMoin/web/contexts.py MoinMoin/web/utils.py |
diffstat | 2 files changed, 8 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/MoinMoin/web/contexts.py Thu Aug 14 17:25:20 2008 +0200 +++ b/MoinMoin/web/contexts.py Thu Aug 14 22:35:27 2008 +0200 @@ -19,7 +19,7 @@ from MoinMoin.theme import load_theme_fallback from MoinMoin.util.clock import Clock from MoinMoin.web.request import Request, MoinMoinFinish -from MoinMoin.web.utils import check_spider, UniqueIDGenerator +from MoinMoin.web.utils import UniqueIDGenerator from MoinMoin.web.exceptions import Forbidden, SurgeProtection from MoinMoin import log @@ -228,7 +228,12 @@ abort(redirect(url)) def isSpiderAgent(self): - return check_spider(self.request.user_agent, self.cfg) + """ Simple check if useragent is a spider bot. """ + cfg = self.cfg + useragent = self.request.useragent + if useragent and cfg.cache.ua_spiders: + return cfg.cache.ua_spiders.search(seluseragent.browser) is not None + return False isSpiderAgent = EnvironProxy(isSpiderAgent) class ActionMixin(object):
--- a/MoinMoin/web/utils.py Thu Aug 14 17:25:20 2008 +0200 +++ b/MoinMoin/web/utils.py Thu Aug 14 22:35:27 2008 +0200 @@ -19,17 +19,6 @@ logging = log.getLogger(__name__) -def check_spider(useragent, cfg): - """ Simple check if useragent is a spider bot - - @param useragent: werkzeug.useragents.UserAgent - @param cfg: wikiconfig instance - """ - is_spider = False - if useragent and cfg.cache.ua_spiders: - is_spider = cfg.cache.ua_spiders.search(useragent.browser) is not None - return is_spider - def check_setuid(request, userobj): """ Check for setuid conditions. Returns a tuple of either new user and old user @@ -59,7 +48,7 @@ if ((args or request.method != 'GET') and action not in ['rss_rc', 'show', 'sitemap'] and not (action == 'AttachFile' and args.get('do') == 'get')): - if check_spider(request.user_agent, request.cfg): + if request.isSpiderAgent: raise Forbidden() if request.cfg.hosts_deny: remote_addr = request.remote_addr