[Python-Dev] Re: PEP 292, Simpler String Substitutions

Barry A. Warsaw barry@zope.com
Sat, 22 Jun 2002 20:56:57 -0400


>>>>> "CT" == Christian Tismer <tismer@tismer.com> writes:

    CT> By no means.  allvars() is something like locals() or
    CT> globals(), just an explicit way to produce a dictionary of
    CT> variables.

I'd be ok with something like allvars() and requiring a dictionary to
the .sub() method, /if/ allvars() were a method on a frame object.  I
really, really do want to write in my i18n programs:

    def whereBorn(name):
	country = countryOfOrigin(name)
	return _('$name was born in $country')

I'd be fine if the definition of _() could reach into the frame of
whereBorn() and give me a list of all variables, including ones in
nested scopes.  Actually, that'd be a lot better than what I do now
(although truth be told, losing access to nested scoped variables is
only a hypothetical limitation in the code I've written).

The feature would be useless to me if I had to pass some explicit
dictionary into the _() method.  It makes writing i18n code extremely
tedious.  Invariably, the unsafeness of an implicit dictionary happens
when strings come from untrusted sources, and your .py file can't be
considered untrusted.  In those cases, creating an explicit dictionary
for interpolation is fine, but they also tend not to overlap with i18n
much.

-Barry