This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author v+python
Recipients Giovanni.Funchal, facundobatista, fdrake, orsenthil, python-dev, v+python
Date 2012-04-11.09:30:13
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1334136614.17.0.242823625004.issue10484@psf.upfronthosting.co.za>
In-reply-to
Content
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)
History
Date User Action Args
2012-04-11 09:30:14v+pythonsetrecipients: + v+python, fdrake, facundobatista, orsenthil, python-dev, Giovanni.Funchal
2012-04-11 09:30:14v+pythonsetmessageid: <1334136614.17.0.242823625004.issue10484@psf.upfronthosting.co.za>
2012-04-11 09:30:13v+pythonlinkissue10484 messages
2012-04-11 09:30:13v+pythoncreate