[Zconfig] SVN: ZConfig/trunk/ fix relative path recognition

Fred Drake fdrake at gmail.com
Wed Oct 14 14:26:30 EDT 2009


Log message for revision 105068:
  fix relative path recognition
  (https://bugs.launchpad.net/zconfig/+bug/405687)
  

Changed:
  U   ZConfig/trunk/NEWS.txt
  U   ZConfig/trunk/ZConfig/loader.py
  U   ZConfig/trunk/ZConfig/tests/test_loader.py

-=-
Modified: ZConfig/trunk/NEWS.txt
===================================================================
--- ZConfig/trunk/NEWS.txt	2009-10-14 15:30:25 UTC (rev 105067)
+++ ZConfig/trunk/NEWS.txt	2009-10-14 18:26:29 UTC (rev 105068)
@@ -2,6 +2,12 @@
 Change History for ZConfig
 ==========================
 
+ZConfig (unreleased)
+--------------------
+
+- Fix relative path recognition.
+  https://bugs.launchpad.net/zconfig/+bug/405687
+
 ZConfig 2.7.1 (2009/06/13)
 --------------------------
 

Modified: ZConfig/trunk/ZConfig/loader.py
===================================================================
--- ZConfig/trunk/ZConfig/loader.py	2009-10-14 15:30:25 UTC (rev 105067)
+++ ZConfig/trunk/ZConfig/loader.py	2009-10-14 18:26:29 UTC (rev 105068)
@@ -15,6 +15,7 @@
 
 import cStringIO
 import os.path
+import re
 import sys
 import urllib
 import urllib2
@@ -128,14 +129,21 @@
                 url)
         return newurl
 
+    # from RFC 3986:
+    # schema = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
+    _pathsep_rx = re.compile(r"[a-zA-Z][-+.a-zA-Z0-9]*:")
+
     def isPath(self, s):
         """Return True iff 's' should be handled as a filesystem path."""
         if ":" in s:
             # XXX This assumes that one-character scheme identifiers
             # are always Windows drive letters; I don't know of any
             # one-character scheme identifiers.
-            scheme, rest = urllib.splittype(s)
-            return len(scheme) == 1
+            m = self._pathsep_rx.match(s)
+            if m is None:
+                return True
+            # Does it look like a drive letter?
+            return len(m.group(0)) == 2
         else:
             return True
 

Modified: ZConfig/trunk/ZConfig/tests/test_loader.py
===================================================================
--- ZConfig/trunk/ZConfig/tests/test_loader.py	2009-10-14 15:30:25 UTC (rev 105067)
+++ ZConfig/trunk/ZConfig/tests/test_loader.py	2009-10-14 18:26:29 UTC (rev 105068)
@@ -230,6 +230,11 @@
         assert_(isPath(r"\abc"))
         assert_(isPath(r"\abc\def"))
         assert_(isPath(r"c:\abc\def"))
+        assert_(isPath("/ab:cd"))
+        assert_(isPath(r"\ab:cd"))
+        assert_(isPath("long name with spaces"))
+        assert_(isPath("long name:with spaces"))
+        assert_(not isPath("ab:cd"))
         assert_(not isPath("http://www.example.com/"))
         assert_(not isPath("http://www.example.com/sample.conf"))
         assert_(not isPath("file:///etc/zope/zope.conf"))



More information about the ZConfig mailing list