[Zodb-checkins] CVS: Packages/ZConfig - url.py:1.1.2.3
Fred L. Drake, Jr.
fred@zope.com
Thu, 2 Jan 2003 10:43:27 -0500
Update of /cvs-repository/Packages/ZConfig
In directory cvs.zope.org:/tmp/cvs-serv2641
Modified Files:
Tag: zconfig-schema-devel-branch
url.py
Log Message:
Several more fixes for the URL helper functions, with improved tests.
=== Packages/ZConfig/url.py 1.1.2.2 => 1.1.2.3 ===
--- Packages/ZConfig/url.py:1.1.2.2 Thu Jan 2 09:49:23 2003
+++ Packages/ZConfig/url.py Thu Jan 2 10:42:54 2003
@@ -4,7 +4,7 @@
import urlparse as _urlparse
from urllib import splittype as _splittype
-from urlparse import urlunsplit
+from urlparse import urlunsplit # part of public API
def urldefrag(url):
@@ -24,7 +24,9 @@
baseparts = urlsplit(base)
relparts = urlsplit(relurl, "zconfig")
if relparts[2]:
- d = _posixpath.dirname(baseparts[2]) + '/'
+ d = _posixpath.dirname(baseparts[2])
+ if d:
+ d += "/"
path = _posixpath.normpath(_posixpath.join(d, relparts[2]))
else:
path = baseparts[2]
@@ -39,24 +41,32 @@
def urlsplit(url, scheme=''):
- parts = _urlparse.urlsplit(url)
- scheme = parts[0] or scheme
+ stated_scheme = _splittype(url)[0]
+ scheme = stated_scheme or scheme
+ parts = _urlparse.urlsplit(url, scheme=scheme)
if scheme == "zconfig":
path = parts[2]
- if not path:
- raise ValueError("zconfig URIs require a non-empty path component")
- if parts[0] and '..' in path.split('/'):
- raise ValueError("zconfig URIs cannot include '..' references: "
- + `url`)
+ 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[0] == '/':
+ 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`)
+## import sys
+## print >>sys.__stderr__, "%r -> %r" % (url, parts)
return parts