[Zope-Checkins] CVS: Releases/Zope/lib/python/Products/PythonScripts - PythonScript.py:1.43.6.2

Casey Duncan casey@ZOPE.COM
Tue, 10 Jun 2003 17:53:58 -0400


FYI: This breaks the CMF FSPythonScript implementation. Not sure what you=
=20
might want to do about that... ;^)

I believe this is caught by the CMFCore tests at least...

-Casey

On Tuesday 10 June 2003 05:14 pm, Evan Simpson wrote:
> Update of /cvs-repository/Releases/Zope/lib/python/Products/PythonScrip=
ts
> In directory=20
cvs.zope.org:/tmp/cvs-serv15134/lib/python/Products/PythonScripts
>=20
> Modified Files:
>       Tag: Zope-2_6-branch
> =09PythonScript.py=20
> Log Message:
> Fix Collector #902: Script recursion broken due to shared globals.
>=20
>=20
> =3D=3D=3D Releases/Zope/lib/python/Products/PythonScripts/PythonScript.=
py 1.43.6.1=20
=3D> 1.43.6.2 =3D=3D=3D
> --- Releases/Zope/lib/python/Products/PythonScripts/PythonScript.py:1.4=
3.6.1=09
Tue Oct  8 18:25:30 2002
> +++ Releases/Zope/lib/python/Products/PythonScripts/PythonScript.py=09T=
ue Jun=20
10 17:14:36 2003
> @@ -19,7 +19,7 @@
> =20
>  __version__=3D'$Revision$'[11:-2]
> =20
> -import sys, os, traceback, re, marshal
> +import sys, os, traceback, re, marshal, new
>  from Globals import DTMLFile, MessageDialog, package_home
>  import AccessControl, OFS, RestrictedPython
>  from OFS.SimpleItem import SimpleItem
> @@ -210,7 +210,7 @@
>              self._compile()
>              self._v_change =3D 1
>          elif self._code is None:
> -            self._v_f =3D None
> +            self._v_ft =3D None
>          else:
>              self._newfun(marshal.loads(self._code))
> =20
> @@ -224,7 +224,7 @@
>          self.warnings =3D tuple(r[2])
>          if errors:
>              self._code =3D None
> -            self._v_f =3D None
> +            self._v_ft =3D None
>              self._setFuncSignature((), (), 0)
>              # Fix up syntax errors.
>              filestring =3D '  File "<string>",'
> @@ -255,7 +255,8 @@
>               }
>          l =3D {}
>          exec code in g, l
> -        self._v_f =3D f =3D l.values()[0]
> +        f =3D l.values()[0]
> +        self._v_ft =3D (f.func_code, g, f.func_defaults or ())
>          return f
> =20
>      def _makeFunction(self, dummy=3D0): # CMFCore.FSPythonScript uses =
dummy=20
arg.
> @@ -263,7 +264,7 @@
>          self._compile()
> =20
>      def _editedBindings(self):
> -        if getattr(self, '_v_f', None) is not None:
> +        if getattr(self, '_v_ft', None) is not None:
>              self._makeFunction()
> =20
>      def _exec(self, bound_names, args, kw):
> @@ -292,21 +293,19 @@
> =20
>          #__traceback_info__ =3D bound_names, args, kw, self.func_defau=
lts
> =20
> -        f =3D self._v_f
> -        if f is None:
> +        ft =3D self._v_ft
> +        if ft is None:
>              __traceback_supplement__ =3D (
>                  PythonScriptTracebackSupplement, self)
>              raise RuntimeError, '%s %s has errors.' % (self.meta_type,=
=20
self.id)
> =20
> +        fcode, g, fadefs =3D ft
> +        g =3D g.copy()
>          if bound_names is not None:
> -            # XXX This causes the whole acquisition chain
> -            # to be held by self._v_f.  I think we really should
> -            # use new.function() instead, similar to
> -            # CMFCore.FSPythonScript.  new.function() takes
> -            # about 8 microseconds on a 1 GHz Athlon. - Shane
> -            f.func_globals.update(bound_names)
> -        f.func_globals['__traceback_supplement__'] =3D (
> +            g.update(bound_names)
> +        g['__traceback_supplement__'] =3D (
>              PythonScriptTracebackSupplement, self, -1)
> +        f =3D new.function(fcode, g, None, fadefs)
> =20
>          # Execute the function in a new security context.
>          security=3DgetSecurityManager()
>=20
>=20
> _______________________________________________
> Zope-Checkins maillist  -  Zope-Checkins@zope.org
> http://mail.zope.org/mailman/listinfo/zope-checkins
>=20