[Zope-CVS] CVS: Packages/zpkgtools/zpkgtools - loader.py:1.15

Fred L. Drake, Jr. fred at zope.com
Thu May 13 11:07:05 EDT 2004


Update of /cvs-repository/Packages/zpkgtools/zpkgtools
In directory cvs.zope.org:/tmp/cvs-serv20088

Modified Files:
	loader.py 
Log Message:
put knowledge about how to compute a "base" URL to a helper function


=== Packages/zpkgtools/zpkgtools/loader.py 1.14 => 1.15 ===
--- Packages/zpkgtools/zpkgtools/loader.py:1.14	Mon May 10 14:48:49 2004
+++ Packages/zpkgtools/zpkgtools/loader.py	Thu May 13 11:06:34 2004
@@ -16,6 +16,7 @@
 This handles tag insertion and URL type dispatch.
 """
 
+import copy
 import errno
 import logging
 import os
@@ -404,3 +405,34 @@
         return b.join(r).getUrl()
     else:
         return relurl
+
+
+def baseUrl(url):
+    """Return the base URL for `url`."""
+    if isinstance(url, basestring):
+        try:
+            url = parse(url)
+        except ValueError:
+            # conventional URL
+            parts = list(urlparse.urlparse(url))
+            if parts[2]:
+                parts[2] = posixpath.join(posixpath.dirname(parts[2]), "")
+                url = urlparse.urlunparse(parts)
+            return url
+    else:
+        # make a copy since we're going to mutate it; don't want to
+        # affect the caller
+        url = copy.deepcopy(url)
+    if isinstance(url, cvsloader.CvsUrl):
+        url.path = posixpath.join(posixpath.dirname(url.path), "")
+        base = url.getUrl()
+    elif isinstance(url, svnloader.TaglessSubversionUrl):
+        url.url = posixpath.join(posixpath.dirname(url.url), "")
+        url.prefix = url.url
+        base = url.getUrl()
+    elif isinstance(url, svnloader.SubversionUrl):
+        url.tail = posixpath.join(posixpath.dirname(url.tail), "")
+        base = url.getUrl()
+    else:
+        base = None
+    return base




More information about the Zope-CVS mailing list