File: download.py

package info (click to toggle)
pgxnclient 1.3.2-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 672 kB
  • sloc: python: 3,545; sh: 71; makefile: 53
file content (22 lines) | stat: -rwxr-xr-x 553 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
#!/usr/bin/env python
"""Download an URL and save it with tne name as the urlquoted url.

The files downloaded are used by the test suite.
"""
import os
import sys
from six.moves.urllib.parse import quote
from six.moves.urllib.request import urlopen

if __name__ == '__main__':
    url = sys.argv[1]
    fn = os.path.join(os.path.dirname(__file__), quote(url, safe=''))
    f = open(fn, "wb")
    try:
        try:
            f.write(urlopen(url).read())
        finally:
            f.close()
    except Exception:
        os.unlink(fn)
        raise