[Zope3-dev] Notations for paths (was comments on Guido's diary)
Jim Fulton
jim@zope.com
Fri, 20 Dec 2002 10:02:59 -0500
Steve Alexander wrote:
>
>> I don't like this for two reasons:
>>
>> - It adds yet another way to do it, which is unpythonic. :)
>
>
> I explained my view of the difference between a location and a path in
> another message. In my view, a location is always absolute.
I just responded. Locations are expressed as paths. The interoretation of
a path should be consistent regardless of what it''s used for.
>> - It should be possible to convert between the string and sequence forms
>> with the simple expressions:
>>
>> stringpath = '/'.join(tuplepath)
>>
>> tuplepath = stringpath.split('/')
>
>
> This is not possible in general. I've had to correct code that tries to
> convert between string locations and tuple locations using the simple
> expressions above. They do not work for the root '/' or ('',). Relying
> on the simple expressions caused a number of subtle and hard to track
> down bugs that I fixed a couple of weeks ago.
That's surprizing, because Iv't found this mechanism to be quite robost in
the past.
> >>> root_string = '/'
> >>> root_tuple = ('',)
> >>>
> >>> '/'.join(root_tuple)
> ''
> >>> root_string.split('/')
> ['', '']
> >>> tuple(root_string.split('/'))
> ('', '')
This is interesting. Zope 2 treats trailing slashes as optional.
Still, I'm surprised that this hasn't been more of a problem in Zope 2.
>
> I would recommend that, for correctness, code always uses the
> convenience functions in Zope.App.Traversing.
Yes.
> We could also debate whether to redefine the definition of a location so
> that it doesn't have this irregularity at the root.
>
> 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.
For strings, a leading '/' must be required to indicate an absolute path.
Departing from this would be just to dang weird.
Maybe we should make string paths the only standard path notation.
Jim
--
Jim Fulton mailto:jim@zope.com Python Powered!
CTO (888) 344-4332 http://www.python.org
Zope Corporation http://www.zope.com http://www.zope.org