[Zope3-dev] Notations for paths (was comments on Guido's diary)

Steve Alexander steve@cat-box.net
Sat, 14 Dec 2002 16:15:12 +0200


> 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.


> - 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.

 >>> root_string = '/'
 >>> root_tuple = ('',)
 >>>
 >>> '/'.join(root_tuple)
''
 >>> root_string.split('/')
['', '']
 >>> tuple(root_string.split('/'))
('', '')


I would recommend that, for correctness, code always uses the 
convenience functions in Zope.App.Traversing.


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.

We could then say that relative paths must start with "./" or ('.',).

Examples of relative paths:

   ('.', 'foo', 'bar')
   './foo/bar'

--
Steve Alexander