Commit 78c58c2b authored by Sebastian Wehrmann's avatar Sebastian Wehrmann

Restore compatibility to Windows XP and Python2.4.

parent 6278119a
......@@ -1262,7 +1262,8 @@ def _open(base, filename, seen, dl_options, override):
if filename in seen:
if is_temp:
os.unlink(path)
fp.close()
os.remove(path)
raise zc.buildout.UserError("Recursive file include", seen, filename)
root_config_file = not seen
......@@ -1274,7 +1275,8 @@ def _open(base, filename, seen, dl_options, override):
parser.optionxform = lambda s: s
parser.readfp(fp)
if is_temp:
os.unlink(path)
fp.close()
os.remove(path)
extends = extended_by = None
for section in parser.sections():
......
......@@ -21,6 +21,7 @@ from zc.buildout.easy_install import realpath
import logging
import os
import os.path
import re
import shutil
import tempfile
import urllib
......@@ -148,6 +149,8 @@ class Download(object):
returned and the client code is responsible for cleaning it up.
"""
if re.match(r"^[A-Za-z]:\\", url):
url = 'file:' + url
parsed_url = urlparse.urlparse(url, 'file')
url_scheme, _, url_path = parsed_url[:3]
if url_scheme == 'file':
......@@ -171,11 +174,11 @@ class Download(object):
if not check_md5sum(tmp_path, md5sum):
raise ChecksumError(
'MD5 checksum mismatch downloading %r' % url)
except:
os.remove(tmp_path)
raise
finally:
os.close(handle)
finally:
os.close(handle)
except:
os.remove(tmp_path)
raise
if path:
shutil.move(tmp_path, path)
......@@ -190,14 +193,25 @@ class Download(object):
if self.hash_name:
return md5(url).hexdigest()
else:
parsed = urlparse.urlparse(url)
if re.match(r"^[A-Za-z]:\\", url):
url = 'file:' + url
parsed = urlparse.urlparse(url, 'file')
url_path = parsed[2]
for name in reversed(url_path.split('/')):
if name:
return name
if parsed[0] == 'file':
while True:
url_path, name = os.path.split(url_path)
if name:
return name
if not url_path:
break
else:
url_host, url_port = parsed[-2:]
return '%s:%s' % (url_host, url_port)
for name in reversed(url_path.split('/')):
if name:
return name
url_host, url_port = parsed[-2:]
return '%s:%s' % (url_host, url_port)
def check_md5sum(path, md5sum):
......
......@@ -121,7 +121,7 @@ scheme will still work:
>>> cat(download(join(server_data, 'foo.txt'))[0])
This is a foo text.
>>> cat(download('file://%s/foo.txt' % server_data)[0])
>>> cat(download('file:' + join(server_data, 'foo.txt'))[0])
This is a foo text.
>>> remove(path)
......@@ -231,7 +231,7 @@ sometimes used to create source distributions:
>>> write(server_data, 'foo.txt', 'This is a foo text.')
>>> download = Download(cache=cache)
>>> cat(download('file://' + join(server_data, 'foo.txt'), path=path)[0])
>>> cat(download('file:' + join(server_data, 'foo.txt'), path=path)[0])
This is a foo text.
>>> ls(cache)
- foo.txt
......@@ -260,7 +260,7 @@ as a directory in the file system yet:
>>> Download(cache=join(cache, 'non-existent'))(server_url+'foo.txt')
Traceback (most recent call last):
UserError: The directory:
'/tmp/tmpZ2cwCfbuildoutSetUp/_TEST_/download-cache/non-existent'
'/download-cache/non-existent'
to be used as a download cache doesn't exist.
Using namespace sub-directories of the download cache
......@@ -337,7 +337,7 @@ checksum since we don't know which port the server happens to listen at when
the test is run, so we don't actually know the full URL of the file. Let's
check that the checksum actually belongs to the particular URL used:
>>> path == join(cache, md5(server_url+'foo.txt').hexdigest())
>>> path.lower() == join(cache, md5(server_url+'foo.txt').hexdigest()).lower()
True
The cached copy is used when downloading the file again:
......@@ -359,7 +359,7 @@ cache under a different name:
/download-cache/537b6d73267f8f4447586989af8c470e
>>> path == path2
False
>>> path2 == join(cache, md5(server_url+'other/foo.txt').hexdigest())
>>> path2.lower() == join(cache, md5(server_url+'other/foo.txt').hexdigest()).lower()
True
>>> cat(path)
This is a foo text.
......
......@@ -2818,7 +2818,7 @@ def test_suite():
tearDown=zc.buildout.testing.buildoutTearDown,
optionflags=doctest.NORMALIZE_WHITESPACE | doctest.ELLIPSIS,
checker=renormalizing.RENormalizing([
(re.compile('0x[0-9a-f]+'), '<MEM ADDRESS>'),
(re.compile('0x[0-9a-fA-F]+'), '<MEM ADDRESS>'),
(re.compile('http://localhost:[0-9]{4,5}/'),
'http://localhost/'),
(re.compile('[0-9a-f]{32}'), '<MD5 CHECKSUM>'),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment