[Zope-CVS] SVN: zpkgtools/trunk/zpkg try to work with file: URLs in
a more portable way
Fred L. Drake, Jr.
fdrake at gmail.com
Fri Sep 17 12:33:02 EDT 2004
Log message for revision 27608:
try to work with file: URLs in a more portable way
(trying to solve some of the Windows problems)
Changed:
U zpkgtools/trunk/zpkgsetup/package.py
A zpkgtools/trunk/zpkgsetup/tests/test_urlutils.py
A zpkgtools/trunk/zpkgsetup/urlutils.py
U zpkgtools/trunk/zpkgtools/include.py
U zpkgtools/trunk/zpkgtools/svnloader.py
-=-
Modified: zpkgtools/trunk/zpkgsetup/package.py
===================================================================
--- zpkgtools/trunk/zpkgsetup/package.py 2004-09-17 16:24:14 UTC (rev 27607)
+++ zpkgtools/trunk/zpkgsetup/package.py 2004-09-17 16:33:02 UTC (rev 27608)
@@ -69,6 +69,7 @@
from zpkgsetup import cfgparser
from zpkgsetup import dist
+from zpkgsetup import urlutils
PACKAGE_CONF = "SETUP.cfg"
@@ -131,7 +132,7 @@
path = os.path.join(directory, PACKAGE_CONF)
if os.path.exists(path):
path = os.path.realpath(path)
- url = "file://" + urllib.pathname2url(path)
+ url = urlutils.file_url(urllib.pathname2url(path))
f = open(path)
else:
# Initialize using the cfgparser so we still get a package
Added: zpkgtools/trunk/zpkgsetup/tests/test_urlutils.py
===================================================================
--- zpkgtools/trunk/zpkgsetup/tests/test_urlutils.py 2004-09-17 16:24:14 UTC (rev 27607)
+++ zpkgtools/trunk/zpkgsetup/tests/test_urlutils.py 2004-09-17 16:33:02 UTC (rev 27608)
@@ -0,0 +1,68 @@
+##############################################################################
+#
+# Copyright (c) 2004 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Tests for zpkgtools.urlutils."""
+
+import sys
+import unittest
+
+from zpkgsetup import urlutils
+
+__docformat__ = "reStructuredText"
+
+
+class WindowsUrlutilsTestCase(unittest.TestCase):
+ """Tests of Windows path-to-URL conversions.
+
+ This should only be used on Windows systems.
+ """
+
+ def test_with_drive_letter(self):
+ self.assertEqual(urlutils.file_url("c:\\some\\file.txt"),
+ "file:///c|/some/file.txt")
+ self.assertEqual(urlutils.file_url("c:some\\file.txt"),
+ "file:///c|some/file.txt")
+ self.assertEqual(urlutils.file_url("\\some\\folder"),
+ "file:///c|/some/folder")
+ self.assertEqual(urlutils.file_url("\\some\\folder\\"),
+ "file:///c|/some/folder")
+
+ def test_without_drive_letter(self):
+ self.assertEqual(urlutils.file_url("\\some\\file.txt"),
+ "file:///some/file.txt")
+ self.assertEqual(urlutils.file_url("\\some\\folder"),
+ "file:///some/folder")
+ self.assertEqual(urlutils.file_url("\\some\\folder\\"),
+ "file:///some/folder")
+
+
+class PosixUrlutilsTestCase(unittest.TestCase):
+ """Tests of POSIX path-to-URL conversions.
+
+ This should only be used on Unix-like systems.
+ """
+ def test_paths(self):
+ self.assertEqual(urlutils.file_url("/some/file.txt"),
+ "file:///some/file.txt")
+ self.assertEqual(urlutils.file_url("/some/folder"),
+ "file:///some/folder")
+ self.assertEqual(urlutils.file_url("/some/folder/"),
+ "file:///some/folder")
+
+
+def test_suite():
+ if sys.platform[:3].lower().startswith("win"):
+ testcls = WindowsUrlutilsTestCase
+ else:
+ testcls = PosixUrlutilsTestCase
+ return unittest.makeSuite(testcls)
Property changes on: zpkgtools/trunk/zpkgsetup/tests/test_urlutils.py
___________________________________________________________________
Name: svn:mime-type
+ text/x-python
Name: svn:eol-style
+ native
Added: zpkgtools/trunk/zpkgsetup/urlutils.py
===================================================================
--- zpkgtools/trunk/zpkgsetup/urlutils.py 2004-09-17 16:24:14 UTC (rev 27607)
+++ zpkgtools/trunk/zpkgsetup/urlutils.py 2004-09-17 16:33:02 UTC (rev 27608)
@@ -0,0 +1,27 @@
+##############################################################################
+#
+# Copyright (c) 2004 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Helper functions for dealing with URLs."""
+
+__docformat__ = "reStructuredText"
+
+import posixpath
+import urllib
+
+
+def file_url(path):
+ urlpart = urllib.pathname2url(path)
+ if urlpart.startswith("///"):
+ urlpart = urlpart[2:]
+ urlpart = posixpath.normpath(urlpart)
+ return "file://" + urlpart
Property changes on: zpkgtools/trunk/zpkgsetup/urlutils.py
___________________________________________________________________
Name: svn:mime-type
+ text/x-python
Name: svn:eol-style
+ native
Modified: zpkgtools/trunk/zpkgtools/include.py
===================================================================
--- zpkgtools/trunk/zpkgtools/include.py 2004-09-17 16:24:14 UTC (rev 27607)
+++ zpkgtools/trunk/zpkgtools/include.py 2004-09-17 16:33:02 UTC (rev 27608)
@@ -29,6 +29,7 @@
from zpkgsetup import loggingapi as logging
from zpkgsetup import publication
from zpkgsetup import setup
+from zpkgsetup import urlutils
from zpkgtools import Error
from zpkgtools import loader
@@ -490,8 +491,7 @@
type = urllib.splittype(source)[0] or ''
if len(type) in (0, 1):
# figure it's a path ref, possibly w/ a Windows drive letter
- source = os.path.join(dir, source)
- source = "file://" + urllib.pathname2url(source)
+ source = urlutils.file_url(os.path.join(dir, source))
type = "file"
try:
path = self.loader.load(source)
Modified: zpkgtools/trunk/zpkgtools/svnloader.py
===================================================================
--- zpkgtools/trunk/zpkgtools/svnloader.py 2004-09-17 16:24:14 UTC (rev 27607)
+++ zpkgtools/trunk/zpkgtools/svnloader.py 2004-09-17 16:33:02 UTC (rev 27608)
@@ -25,6 +25,8 @@
import xml.sax
import xml.sax.handler
+from zpkgsetup import urlutils
+
from zpkgtools import LoadingError
from zpkgtools import runlog
from zpkgtools import cvsloader
@@ -219,8 +221,7 @@
p = xml.sax.make_parser()
p.setFeature(xml.sax.handler.feature_namespaces, True)
p.setContentHandler(h)
- s = xml.sax.xmlreader.InputSource(
- "file://" + urllib.pathname2url(entriesfile))
+ s = xml.sax.xmlreader.InputSource(urlutils.file_url(entriesfile))
s.setByteStream(f)
p.parse(s)
if basename in h.entries:
More information about the Zope-CVS
mailing list