[MERGE] Bugfix #68124: Allow import plugins from zip archives

Alexander Belchenko bialix at ukr.net
Tue Jan 2 16:30:11 GMT 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Aaron Bentley пишет:
> Alexander Belchenko wrote:
>>> Certainly, it behaves differently on Windows vs Unix:
>>>
>>>>>> a = 'a\\b\\c'
>>>>>> os.path.split(a)
>>>
>>> ('', 'a\\b\\c')
>>
>>
>> This example unrelated to my code, because inside zip archives always
>> used
>> '/' as path separator.
> 
> It is not unrelated to your code, because it shows that os.path.split is
> sensitive to platform differences.
> 
> It is possible that your code would fail on Mac OS classic, because it
> used ':' as a separator, and '/' may have been valid as a filename
> character.

I wonder how zip works on MacOS classic in the case when '/'
is valid filename character?

>>> AFAIK, the only OSes that used something other than '/' are Windows, DOS
>>> and MacOS 1-9.  So it's unlikely that your code will run on a platform
>>> where '/' isn't supported as a separator.
>>>
>>> But still, I think using osutils makes the code clearly correct, whereas
>>> os.path makes it suspect.
>>
>>
>> osutils won't help me here because it does not have corresponding
>> function
>> to os.path.split.
> 
> It has basename and dirname, which together are equivalent to split.  So
> yes, it has functionality you can use.

- From osutils.py:

dirname = os.path.dirname
basename = os.path.basename

Looking at the source of ntpath.py (os.path module on win32):

def basename(p):
    """Returns the final component of a pathname"""
    return split(p)[1]

def dirname(p):
    """Returns the directory component of a pathname"""
    return split(p)[0]

This functions use os.path.split.
Here the code of ntpath.py split:

def split(p):
    """Split a pathname.

    Return tuple (head, tail) where tail is everything after the final slash.
    Either part may be empty."""

    d, p = splitdrive(p)
    # set i to index beyond p's last slash
    i = len(p)
    while i and p[i-1] not in '/\\':
        i = i - 1
    head, tail = p[:i], p[i:]  # now tail has no slashes
    # remove trailing slashes from head, unless it's all slashes
    head2 = head
    while head2 and head2[-1] in '/\\':
        head2 = head2[:-1]
    head = head2 or head
    return d + head, tail


So, we at the point from what we start.

> Or better yet, you can add 'split' to osutils.

I think better way doing this is adding to osutils:

import ntpath
split = ntpath.split

But after your comment about MacOS, I feel it's not enough.

Alexander
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFmoiTzYr338mxwCURAsohAJ96N4kX2zHQU9n9O5dX8m/Id8TKQACfSPsJ
Vhj3655FSLtInC+/JcpcMf8=
=lMhB
-----END PGP SIGNATURE-----





More information about the bazaar mailing list