[Zope] ID with Space in Name

Itamar Shtull-Trauring itamars@ibm.net
Mon, 28 Feb 2000 10:51:54 +0200


Jochen Haeberle wrote:
> 
> Hi,
> 
> I have a problem with an object that has a Space in it's ID Name. The
> object causes several problems because it sometimes cannot be found.
> The object is contained in a catalog_aware class and cannot be
> renamed or deleted because an error occurs:
> 
> Error Type: ValueError
> Error Value: Uncatalog of absent id 'Album/Narrentreffen2000/Fete%201'
> 
> Anyone has a clue how I can get rid of such an object?

It's like this - the ZCatalog used to have two ways of cataloging objects - 

	1. as 'Album/Narrentreffen2000/Fete%201'
	2. as '/Album/Narrentreffen2000/Fete 1'

the second way is now the standard
(http://lists.zope.org/pipermail/zope-dev/2000-January/003021.html). 
However, the latest CatalogAwareness is still broken and doesn't support it
yet.

If you replace the url() function in the CatalogAware class with this
version it should work,
but it may break your applications and I'm not sure if this is the correct
way to fix the problem.

    def url(self, ftype=urllib.splittype, fhost=urllib.splithost):
        """Return a SCRIPT_NAME-based url for an object."""
        from urllib import unquote
        if hasattr(self, 'DestinationURL') and \
           callable(self.DestinationURL):
            url='%s/%s' % (self.DestinationURL(), self.id)
        else: url=self.absolute_url(relative=1)
        type, uri=ftype(url)
        host, uri=fhost(uri)
        script_name=self.REQUEST['SCRIPT_NAME']
        __traceback_info__=(`uri`, `script_name`)
        if script_name:
            uri=filter(None, string.split(uri, script_name))[0]
        if uri[0] != '/': uri = '/' + uri
        uri=uri or '/'
        return unquote(uri)

I call absolute_url with relative=1, add a slash to the beginning of the URL
and unqoute the result.  In my local version I also set script_name to ""
cause if I use self.REQUEST I get errors that REQUEST doesn't exist.

In the Portal Toolkit, instead of defining a url() function, index_object
and friends just use "'/' + self.absolute_url(1)", which is also wrong, it
should be urllib.unquote('/' + self.absolute_url(1)).  Or maybe have
absolute_url return unurl-quoted URLs.  And CatalogAware would probably work
fine this way as well.

So, fix CatalogAwareness, update your catalog and you're done.

-- 
                -=  This is NOT a pyramid scheme  =-
The SNAFU Principle: True communication is possible only between equals

                      Itamar S.T.  itamars@ibm.net