[Zodb-checkins] CVS: Packages/ZConfig - url.py:1.3
Fred L. Drake, Jr.
fred@zope.com
Fri, 3 Jan 2003 18:01:10 -0500
Update of /cvs-repository/Packages/ZConfig
In directory cvs.zope.org:/tmp/cvs-serv32640
Modified Files:
url.py
Log Message:
- remove support for the zconfig: URL scheme; it's no longer needed
- add the standard copyright statement
=== Packages/ZConfig/url.py 1.2 => 1.3 ===
--- Packages/ZConfig/url.py:1.2 Fri Jan 3 16:05:51 2003
+++ Packages/ZConfig/url.py Fri Jan 3 18:01:07 2003
@@ -1,9 +1,27 @@
-"""urlparse-like helpers that support the zconfig scheme."""
+##############################################################################
+#
+# Copyright (c) 2002, 2003 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (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.
+#
+##############################################################################
+"""urlparse-like helpers that normalize file: URLs.
+
+ZConfig and urllib2 expect file: URLs to consistently use the '//'
+hostpart seperator; the functions here enforce this constraint.
+"""
import posixpath as _posixpath
import urlparse as _urlparse
from urllib import splittype as _splittype
+from urlparse import urlsplit
def urlnormalize(url):
@@ -27,68 +45,12 @@
def urldefrag(url):
- parts = urlsplit(url)
- if parts[0] == "zconfig":
- return "zconfig:" + parts[2], parts[4]
- else:
- url, fragment = _urlparse.urldefrag(url)
- return urlnormalize(url), fragment
+ url, fragment = _urlparse.urldefrag(url)
+ return urlnormalize(url), fragment
def urljoin(base, relurl):
- scheme = _splittype(base)[0]
- if scheme != "zconfig":
- url = _urlparse.urljoin(base, relurl)
- if url.startswith("file:/") and not url.startswith("file:///"):
- url = "file://" + url[5:]
- return url
- relscheme = _splittype(relurl)[0]
- if relscheme and relscheme != "zconfig":
- return _urlparse.urljoin(base, relurl)
- baseparts = urlsplit(base)
- relparts = urlsplit(relurl, "zconfig")
- if relparts[2]:
- d = _posixpath.dirname(baseparts[2])
- if d:
- d += "/"
- path = _posixpath.normpath(_posixpath.join(d, relparts[2]))
- else:
- path = baseparts[2]
- parts = path.split('/')
- if '..' in parts:
- raise ValueError("zconfig URIs cannot include '..' references: "
- + `path`)
- s = "zconfig:" + path
- if relparts[4]:
- s += "#" + relparts[4]
- return s
-
-
-def urlsplit(url, scheme=''):
- stated_scheme = _splittype(url)[0]
- scheme = stated_scheme or scheme
- parts = _urlparse.urlsplit(url, scheme=scheme)
- if scheme == "zconfig":
- path = parts[2]
- if stated_scheme:
- # These constraints only apply to absolute zconfig: URLs
- if not path:
- # Require a non-empty path; empty path is ok for
- # relative URL ("#frag").
- raise ValueError(
- "zconfig URIs require a non-empty path component")
- if '..' in path.split('/'):
- raise ValueError(
- "zconfig URIs cannot include '..' references: " + `url`)
- # Split the fragment ourselves since the urlparse module
- # doesn't know about the zconfig: scheme.
- if '#' in path:
- path, fragment = path.split('#', 1)
- parts = "zconfig", '', path, '', fragment
- if path[:1] == '/':
- raise ValueError(
- "path component of zconfig: URIs may not start with '/'")
- if '?' in path:
- raise ValueError("zconfig: URIs may not contain queries: "
- + `url`)
- return parts
+ url = _urlparse.urljoin(base, relurl)
+ if url.startswith("file:/") and not url.startswith("file:///"):
+ url = "file://" + url[5:]
+ return url