Skip to content

Commit

Permalink
Python 3.0 fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
James Rowe authored and JNRowe committed Apr 26, 2009
1 parent 3585238 commit d63b2b8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
29 changes: 17 additions & 12 deletions test/grab_net_sources.py
Expand Up @@ -24,8 +24,13 @@
import os
import sys
import tempfile
import urllib
from urlparse import urlparse
try:
from urllib.parse import urlparse
from urllib.request import (urlopen, urlretrieve)
except ImportError:
from urlparse import urlparse
from urllib import (urlopen, urlretrieve)


SOURCES = [
"http://www.amazon.com/dp/0071148167",
Expand Down Expand Up @@ -74,10 +79,10 @@ def main(argv=None):
Command line arguments
"""
print "*WARNING* This script will fetch some data files that can not be " + \
"distributed legally! In some jurisdictions you may not even be " + \
"entitled to personal use of the data it fetches without express " + \
"consent of the copyright holders."
print("*WARNING* This script will fetch some data files that can not be "
"distributed legally! In some jurisdictions you may not even be "
"entitled to personal use of the data it fetches without express "
"consent of the copyright holders.")
if not argv:
argv = sys.argv
if len(argv) == 2 and argv[1] in ("-f" or "--force"):
Expand All @@ -88,25 +93,25 @@ def main(argv=None):
for resource in SOURCES:
filename = data_file(resource)
if not force and os.path.exists(filename):
print "`%s' already downloaded." % resource
print("`%s' already downloaded." % resource)
cached += 1
else:
print "Fetching `%s'..." % resource
print("Fetching `%s'..." % resource)
if resource.endswith(".gz"):
temp = tempfile.mkstemp()[1]
try:
urllib.urlretrieve(resource, temp)
urlretrieve(resource, temp)
data = gzip.GzipFile(temp).read()
finally:
os.unlink(temp)
open(filename, "w").write(data)
elif resource.endswith(".bz2"):
data = bz2.decompress(urllib.urlopen(resource).read())
data = bz2.decompress(urlopen(resource).read())
open(filename, "w").write(data)
else:
urllib.urlretrieve(resource, filename)
urlretrieve(resource, filename)
if cached > 1:
print "You can force download with the `-f' option to this script."
print("You can force download with the `-f' option to this script.")

if __name__ == '__main__':
main(sys.argv)
Expand Down
5 changes: 4 additions & 1 deletion test/mock.py
Expand Up @@ -19,7 +19,10 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#

import __builtin__
try:
import __builtin__
except ImportError:
import builtins as __builtin__
import os
import urllib

Expand Down

0 comments on commit d63b2b8

Please sign in to comment.