[Zope-Checkins] CVS: Zope27/lib/python/TAL - TALInterpreter.py:1.68.26.2

Casey Duncan casey@zope.com
Mon, 9 Sep 2002 10:21:28 -0400


I guess I am curious why this would be necessary, couldn't you already ju=
st=20
do:

import TAL.TALInterpreter
import MyStringIO
TAL.TALInterpreter.StringIO =3D MyStringIO.StringIO

Its still a messy monkey patch but at least you wouldn't need to change t=
he=20
framework.

It seems ridiculous to change the framework so that you can monkey patch =
it.=20
The whole point of monkey patches is to change the framework at run time=20
without changing the framework code itself.

If the above is inadequate, then I think some other mechanism should be=20
devised. Such as a module function like Guido suggested. Defining things =
as=20
monkey patch hooks is setting a bad precedent IMO.

-Casey

On Sunday 08 September 2002 10:04 pm, Florent Guillaume wrote:
> Update of /cvs-repository/Zope27/lib/python/TAL
> In directory cvs.zope.org:/tmp/cvs-serv14808/lib/python/TAL
>=20
> Modified Files:
>       Tag: Zope-2_7-development-branch
> =09TALInterpreter.py=20
> Log Message:
> Provide an opportunity for third-party products to use a full
> Unicode-aware StringIO by monkey-patching two appropriate methods
> until one is completely integrated into Zope.
>=20
>=20
> =3D=3D=3D Zope27/lib/python/TAL/TALInterpreter.py 1.68.26.1 =3D> 1.68.2=
6.2 =3D=3D=3D
> --- Zope27/lib/python/TAL/TALInterpreter.py:1.68.26.1=09Tue Jul 30 16:1=
2:52=20
2002
> +++ Zope27/lib/python/TAL/TALInterpreter.py=09Sun Sep  8 22:04:52 2002
> @@ -116,6 +116,11 @@
>          self.i18nInterpolate =3D i18nInterpolate
>          self.i18nContext =3D TranslationContext()
> =20
> +    def StringIO(self):
> +        # Third-party products wishing to provide a full Unicode-aware
> +        # StringIO can do so by monkey-patching this method.
> +        return StringIO()
> +
>      def saveState(self):
>          return (self.position, self.col, self.stream,
>                  self.scopeLevel, self.level, self.i18nContext)
> @@ -347,7 +352,7 @@
> =20
>      def no_tag(self, start, program):
>          state =3D self.saveState()
> -        self.stream =3D stream =3D StringIO()
> +        self.stream =3D stream =3D self.StringIO()
>          self._stream_write =3D stream.write
>          self.interpret(start)
>          self.restoreOutputState(state)
> @@ -474,7 +479,7 @@
>              # evaluate the mini-program to get the value of the variab=
le.
>              state =3D self.saveState()
>              try:
> -                tmpstream =3D StringIO()
> +                tmpstream =3D self.StringIO()
>                  self.interpret(program, tmpstream)
>                  value =3D normalize(tmpstream.getvalue())
>              finally:
> @@ -509,7 +514,7 @@
>          #
>          # Use a temporary stream to capture the interpretation of the
>          # subnodes, which should /not/ go to the output stream.
> -        tmpstream =3D StringIO()
> +        tmpstream =3D self.StringIO()
>          self.interpret(stuff[1], tmpstream)
>          # We only care about the evaluated contents if we need an impl=
icit
>          # message id.  All other useful information will be in the i18=
ndict=20
on
> @@ -687,7 +692,7 @@
> =20
>      def do_onError_tal(self, (block, handler)):
>          state =3D self.saveState()
> -        self.stream =3D stream =3D StringIO()
> +        self.stream =3D stream =3D self.StringIO()
>          self._stream_write =3D stream.write
>          try:
>              self.interpret(block)
>=20
>=20
> _______________________________________________
> Zope-Checkins maillist  -  Zope-Checkins@zope.org
> http://lists.zope.org/mailman/listinfo/zope-checkins
>=20