euscan/helpers: use HEAD in tryurl

Signed-off-by: Corentin Chary <corentincj@iksaif.net>
This commit is contained in:
Corentin Chary 2011-09-06 15:47:54 +02:00
parent 454d369ced
commit bd75e1af4e

View File

@ -189,15 +189,28 @@ def gen_versions(components, level):
return versions
def urlopen(url, timeout=None):
if not timeout:
def timeout_for_url(url):
if 'sourceforge' in url:
timeout = 15
else:
timeout = 5
return timeout
class HeadRequest(urllib2.Request):
def get_method(self):
return "HEAD"
def urlopen(url, timeout=None, verb="GET"):
if not timeout:
timeout = timeout_for_url(url)
if verb == 'GET':
request = urllib2.Request(url)
elif verb == 'HEAD':
request = HeadRequest(url)
else:
return None
request.add_header('User-Agent', CONFIG['user-agent'])
return urllib2.urlopen(request, None, timeout)
@ -209,7 +222,7 @@ def tryurl(fileurl, template):
try:
basename = os.path.basename(fileurl)
fp = urlopen(fileurl)
fp = urlopen(fileurl, verb='HEAD')
headers = fp.info()
if 'Content-disposition' in headers and basename not in headers['Content-disposition']: