[Zope] Re: Two newbie questions + Zope patch

Martijn Pieters mj@antraciet.nl
Thu, 09 Sep 1999 10:28:33 +0200


At 00:58 09/09/99 , Evan Simpson wrote:

>As I think I've mentioned before on the list, it would probably save a lot of
>folks a lot of grief if _['a/b/c'] and _.getattr(obj, 'a/b/c') did this
>automatically.  Hang on a mo'...
>
>Here's a patch for Zope 2.0.0's DocumentTemplate/DT_Util.py which does the
>trick for getattr:
>
>122a123,127
> >         if '/' in name:
> >             for namepart in filter(None, split(name, '/')):
> >                 inst = careful_getattr(md, inst, namepart)
> >             return inst
> >

There is a method on REQUEST that does this already:

def resolve_url:
     # Attempt to resolve a url into an object in the Zope
     # namespace. The url must be a fully-qualified url. The
     # method will return the requested object if it is found
     # or raise the same HTTP error that would be raised in
     # the case of a real web request. If the passed in url
     # does not appear to describe an object in the system
     # namespace (e.g. the host, port or script name dont
     # match that of the current request), a ValueError will
     # be raised.


--
Martijn Pieters, Web Developer
| Antraciet http://www.antraciet.nl
| Tel: +31-35-7502100 Fax: +31-35-7502111
| mailto:mj@antraciet.nl http://www.antraciet.nl/~mj
| PGP: http://wwwkeys.nl.pgp.net:11371/pks/lookup?op=get&search=0xA8A32149
------------------------------------------