[Zope3-dev] calling objects when evaluating path expressions
Marius Gedminas
mgedmin@codeworks.lt
Mon, 23 Jun 2003 20:41:06 +0300
--PEIAKu/WMn1b1Hv9
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
On Fri, Jun 20, 2003 at 06:29:19PM +0300, Steve Alexander wrote:
> >Here's another approach that doesn't add any syntax. Recently, we added=
=20
> >the ability to use prefixes in the middle of path expressions, so=20
> >perhaps we could define the "call:" prefix to mean "call the method=20
> >named X, passing no arguments".
> >
> ><span tal:replace=3D"foo/call:bar/baz" />
>=20
> That's very similar to the syntax I jokingly suggested when talking=20
> about this with Jim on irc earlier today:
>=20
> <span tal:replace=3D"foo/bar/zope:call/baz" />
>=20
> I like your version better though. So, 'call' would essentially be a=20
> proxy that makes no-args methods into gettable properties.
>=20
>=20
> >On a related note, a few other prefixes could disambiguate traversal.=20
> >Consider the problem of fetching an item called "keys" from a dictionary=
=20
> >using a path expression. Unless Zope 3 has changed the policy, basic=20
> >traversal tries attributes first and items second, so path expressions=
=20
> >can't easily access items with certain names.
>=20
> Actually, Zope 3 has changed the policy. For speed, and because we use a=
=20
> lot of dicts, dicts are always traversed using __getitem__.
>=20
> >An "item:" prefix could solve this.
>=20
> It would. This would be useful for containers.
I believe there are already namespaces that accomplish this:
foo/bar/++attr++xxx/ does getattr(bar, 'xxx')
foo/bar/++item++yyy/ does bar[yyy]
Adding a ++call++ ought to be trivial (4 lines in namespaces.py + some
zcml).
OTOH foo/call:something/ looks better than foo/++call++something/.
Marius Gedminas
--=20
Codeworks is available for Zope consulting -- http://www.codeworks.lt/
--PEIAKu/WMn1b1Hv9
Content-Type: application/pgp-signature
Content-Disposition: inline
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org
iD8DBQE+9zuykVdEXeem148RAhh1AJ9rborfHP6UmsYppLVO8NWRT+qTKgCfcmH6
7ff4ocacdqtyZFBUwWsG3DM=
=JQvn
-----END PGP SIGNATURE-----
--PEIAKu/WMn1b1Hv9--