1 """
2 Read or download files from the internet.
3 """
4 import urllib
5 from ivs.aux import decorators
6
7
9 """
10 Download a file from a link.
11
12 If you want to download the contents to a file, supply C{filename}. The
13 function will return that filename as a check.
14
15 If you want to read the contents immediately from the url, just give the link,
16 and a fileobject B{and} the url object will be returned. Remember
17 to close the url after finishing reading!
18
19 @parameter link: the url of the file
20 @type link: string
21 @parameter filename: the name of the file to write to (optional)
22 @type filename: str
23 @return: output filename(, url object)
24 @rtype: string(, FancyURLopener)
25 """
26 url = urllib.FancyURLopener()
27 myfile,msg = url.retrieve(link,filename=filename)
28 if filename is not None:
29 url.close()
30 return myfile
31 else:
32 return myfile,url
33