/usr/lib/python2.7/dist-packages/sagenb/misc/remote_file.py is in python-sagenb 0.13+ds1-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | # -*- coding: utf-8 -*
import os, sys
def get_remote_file(filename, verbose=True):
"""
INPUT:
filename -- the URL of a file on the web, e.g.,
"http://modular.math.washington.edu/myfile.txt"
verbose -- whether to display download status
OUTPUT:
creates a file in the temp directory and returns the
absolute path to that file.
EXAMPLES:
sage: g = get_remote_file("http://sagemath.org/ack.html", verbose=False) # optional -- requires the internet
sage: len(open(g).read()) # optional and randomly growing.
10198
"""
if verbose:
print "Attempting to load remote file: " + filename
from misc import tmp_filename
temp_name = tmp_filename() + '.' + os.path.splitext(filename)[1][1:]
# IMPORTANT -- urllib takes a long time to load,
# so do not import it in the module scope.
import urllib
global cur
cur = 0
if verbose:
sys.stdout.write("Loading: [")
sys.stdout.flush()
urllib.urlretrieve(filename, temp_name, report_hook)
print "]"
else:
urllib.urlretrieve(filename, temp_name)
return temp_name
cur = 0
def report_hook(block, size, total):
global cur
n = block*size*50/total
if n > cur:
cur = n
sys.stdout.write('.')
sys.stdout.flush()
|