[Zope3-dev] Notations for paths

Steve Alexander steve@cat-box.net
Thu, 19 Dec 2002 16:04:29 +0000


Phillip J. Eby wrote:
> At 03:53 PM 12/19/02 +0100, Florent Guillaume wrote:
> 
>> Steve wrote:
>> > Absolute paths and simple relative names (one step relative paths) are
>> > used in Zope far more than relative paths. If we're always clear when
>> > we're dealing with absolute paths, we don't need the '/' or ('',) at 
>> the
>> > start, so we can use the simple expressions above.
>> >
>> > We could then say that relative paths must start with "./" or ('.',).
>> >
>> > Examples of relative paths:
>> >
>> >    ('.', 'foo', 'bar')
>> >    './foo/bar'
>>
>> I actually quite like this, but it's a big departure from Zope 2 so
>> maybe it would be difficult for developers.
> 
> 
> Maybe I missed something, but why not just consider an empty string in 
> the first element of the tuple to mean the path is absolute?  It works 
> just fine in PEAK.

Because the naive conversion between the string and tuple forms does not 
work at the root.

Python 2.2.2 (#1, Oct 31 2002, 10:45:23)
[GCC 2.96 20000731 (Red Hat Linux 7.2 2.96-108.7.2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
 >>>
 >>> tuple('/'.split('/'))  # convert location '/' to the tuple form
('', '')
 >>> '/'.join(('',))  # convert location ('',) to the string form
''

So, there are special functions for correctly converting between the 
string form and the tuple form.

I've had to correct a number of bugs where the naive conversion had been 
used. These bugs were somewhat tricky to track down, becuase the effects 
didn't point to this as the obvious cause.

--
Steve Alexander