Glenn Linderman <v+pyt...@g.nevcal.com> added the comment:

I note that there is no test for tail_part == '.'.  I suggest adding a couple, 
such as the following which I added to my local copy for testing of the next 
item:

            '/a/b/.': ('/a/b', ''),
            '/a/b/c/../d/e/../../../../f/../.': ('/', ''),

Given your comment that you found bugs in my code, I figured out how to run the 
tests against my code, and found the bugs. Here is a slightly shorter, more 
efficient (it cuts 40% off the execution time, see time_test.py), and to me 
much clearer version of _url_collapse_path_split, and it passes all the tests:

def _url_collapse_path_split(path):
    # Similar to os.path.split(os.path.normpath(path)) but specific to URL
    # path semantics rather than local operating system semantics.
    path_parts = path.split('/')
    head_parts = []
    for part in path_parts[:-1]:
        if part == '..':
            head_parts.pop() # IndexError if more '..' than prior parts
        elif part and part != '.':
            head_parts.append( part )
    if path_parts:
        tail_part = path_parts.pop()
        if tail_part:
            if tail_part == '..':
                head_parts.pop()
                tail_part = ''
            elif tail_part == '.':
                tail_part = ''
    else:
        tail_part = ''        
    return ('/' + '/'.join(head_parts), tail_part)

----------
Added file: http://bugs.python.org/file25175/time_test.py

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue10484>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to