# HG changeset patch # User Sverre Rabbelier # Date 1235594566 0 # Node ID 3601ddfe785a87ac4fb01b98141ea8891768c2d2 # Parent a495ae7efc70e1cde81f0ef6079fe562451e6f65 Make validate.isURLValid more robust Also make the control flow more explicit while at it. Patch by: Sverre Rabbelier diff -r a495ae7efc70 -r 3601ddfe785a app/soc/logic/validate.py --- a/app/soc/logic/validate.py Wed Feb 25 20:42:16 2009 +0000 +++ b/app/soc/logic/validate.py Wed Feb 25 20:42:46 2009 +0000 @@ -36,13 +36,31 @@ Args: feed_url: ATOM or RSS feed url """ - if feed_url: + + # a missing or empty feed url is never valid + if not feed_url: + return False + + try: result = urlfetch.fetch(feed_url) - if result.status_code == 200: - parsed_feed = feedparser.parse(result.content) - if parsed_feed.version and (parsed_feed.version != ''): - return True - return False + except urlfetch_errors.Error, e: + return False + + # 200 is the status code for 'all ok' + if result.status_code != 200: + return False + + parsed_feed = feedparser.parse(result.content) + + # version is always present if the feed is valid + if not parsed_feed.version: + return False + + # TODO: isn't this check redunant? + if parsed_feed.version == '': + return False + + return True def isLinkIdFormatValid(link_id):