File: twlib.py

package info (click to toggle)
teeworlds 0.7.5-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 16,068 kB
  • sloc: cpp: 58,010; ansic: 14,468; python: 3,763; asm: 946; objc: 107; makefile: 36; xml: 21; sh: 7
file content (23 lines) | stat: -rw-r--r-- 544 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import sys
if sys.version_info[0] == 2:
	import urllib
	url_lib = urllib
elif sys.version_info[0] == 3:
	import urllib.request
	url_lib = urllib.request

def fetch_file(url):
	print("trying %s" % url)
	try:
		local = dict(url_lib.urlopen(url).info())
		if "Content-Disposition" in local:
			key_name = "Content-Disposition"
		elif "content-disposition" in local:
			key_name = "content-disposition"
		else:
			return False
		local = local[key_name].split("=")[1]
		url_lib.urlretrieve(url, local)
		return local
	except IOError:
		return False