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 jimjjewett
Recipients
Date 2006-08-31.13:26:18
SpamBayes Score
Marked as misclassified
Message-id
In-reply-to
Content
Logged In: YES 
user_id=764593

I think the patch is still missing a case or two.  

plen represents the length of the path prefix to ignore.  

Today's code computes this as (len(src_dir) + 1) where the 
+1 is for the "/" added by os.path.join().  As you found, 
src_dir won't add anything (including the "/") if src_dir 
is empty.  

But it also won't add the "/" if src_dir already ends in "/
", and it won't even add the src_dir if the path is already 
absolute.

I'm not certain that either of these two cases can occur, 
but it would be safer to assume they can.

My suggestion is that the stripping be smarter -- change

"""
            # Strip directory from globbed filenames
            filenames = [
                file[plen:] for file in 
self.find_data_files(package, src_dir)
                ]
"""

to 

"""
            # Strip directory from globbed filenames
            filenames = [
                filetail(name, src_dir) for name in 
self.find_data_files(package, src_dir)
                ]
"""
where filetail is a helper function defined as
"""
def filetail(name, strip_path):
    if name.startswith(strip_path):
        kill=len(strip_path)
        if name[kill] == "/":
            kill +=1
        name=name[kill:]
    return name
"""
with tests
"""
>>> filetail("asdf/bdededf", "asdf")
'bdededf'
>>> filetail("asdf/bdededf", "asdf/")
'bdededf'    
"""

History
Date User Action Args
2007-08-23 15:42:44adminlinkissue1183712 messages
2007-08-23 15:42:44admincreate