[Zope] XXXPythonScript

Pierre-Julien Grizel grizel@mouli.net
Thu, 13 Dec 2001 09:57:53 +0100


This is a multi-part message in MIME format.
--------------60CE25F676E57B414F9A39AB
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit


J'ai retrouvé ça en faisant du ménage...


"""XXX Python Scripts Product

This product provides unrestricted, unsafe Python-based Scripts.
"""




-- 
If the only tool you have is a hammer, 
    you tend to see every problem as a nail.
Si le seul outil dont vous disposez est un marteau, 
    vous avez tendance à voir chaque problème comme un clou. 
                                       --Abraham Maslow
--------------60CE25F676E57B414F9A39AB
Content-Type: text/plain; charset=us-ascii;
 name="XXXPythonScript.py"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="XXXPythonScript.py"

"""XXX Python Scripts Product

This product provides unrestricted, unsafe Python-based Scripts.
"""

import os
# They can't be created or edited without setting this envar, tho.
NAYB = os.environ.get('ALL_YOUR_BASE_ARE_BELONG_TO') != 'US'

from Globals import DTMLFile, MessageDialog
from string import join, strip, rstrip, split, replace, lower
from urllib import quote

manage_addXXXPythonScriptForm = DTMLFile('www/XXXpyScriptAdd', globals())

_marker = []  # Create a new marker object

def manage_addXXXPythonScript(self, id, REQUEST=None, submit=None):
    """Add a XXX Python Script to a folder."""
    id = str(id)
    id = self._setObject(id, XXXPythonScript(id))
    if REQUEST is not None:
        file = REQUEST.form.get('file', '')
        if type(file) is not type(''): file = file.read()
        if file:
            self._getOb(id).write(file)
        try: u = self.DestinationURL()
        except: u = REQUEST['URL1']
        if submit==" Add and Edit ": u="%s/%s" % (u,quote(id))
        REQUEST.RESPONSE.redirect(u+'/manage_main')
    return ''

from Products.PythonScripts.PythonScript import PythonScript, Python_magic

class XXXPythonScript(PythonScript):
    """Scripts written in Python.

    Removes all restrictions imposed by Python Scripts.
    """

    meta_type='Script (Python, unsafe)'

    def _makeFunction(self, allowSideEffect=0):
        if NAYB:
            raise RuntimeError, '<pre>XXX Scripts are Edit-locked</pre>'
        # Was the cached bytecode compiled with a compatible Python?
        if getattr(self, 'Python_magic', None) != Python_magic:
            allowSideEffect = 1
        if allowSideEffect:
            self._checkCBlock(PrintBlock)
            self.ZCacheable_invalidate()
        if getattr(self, '_v_errors', None):
            raise "Python Script Error", ('<pre>%s</pre>' %
                                          join(self._v_errors, '\n') )
        return self._newfun(allowSideEffect, {'__debug__': __debug__},
                            __builtins__=__builtins__)

from Products.PythonScripts.zbytecodehacks.VSExec import CodeBlock, Printing
class PrintBlock(CodeBlock):
    Mungers = [Printing]


--------------60CE25F676E57B414F9A39AB--