Show
Ignore:
Timestamp:
07/07/08 12:32:30 (5 months ago)
Author:
rob
Message:

Quick fix to only allow numeric fragments in file URLs

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/peppy/vfs/itools/uri/generic.py

    r1462 r1466  
    738738        scheme, authority, path, query, fragment = urlsplit(data) 
    739739         
     740        # Convenience function to break out the fragment from a file URL.  This 
     741        # assumes that the only allowed fragments are digits, specifying line 
     742        # numbers. 
     743        def find_fragment(path, fragment): 
     744            if "#" in path: 
     745                # the fragment is improperly placed in the path 
     746                path1, fragment1 = path.rsplit("#", 1) 
     747                if fragment1.isdigit(): 
     748                    return path1, fragment1 
     749            return path, fragment 
     750             
    740751        # Some special cases for Windows paths c:/a/b#4 and file:///c:/a/b#4. 
    741752        # urlsplit has problems with the scheme, leading slashes in the path, 
     
    744755            # found a windows drive name instead of path, because urlsplit 
    745756            # thinks the scheme is "c" for Windows paths like "c:/a/b" 
    746             if "#" in path: 
    747                 # the fragment is improperly placed in the path 
    748                 path, fragment = path.rsplit("#", 1) 
     757            path, fragment = find_fragment(path, fragment) 
    749758            path = "%s:%s" % (scheme, path) 
    750759            scheme = "file" 
     
    755764            drive = path[1].lower() 
    756765            path = path[3:] 
    757             if "#" in path: 
    758                 path, fragment = path.rsplit("#", 1) 
     766            path, fragment = find_fragment(path, fragment) 
    759767            path = "%s:%s" % (drive, path) 
    760768