Skip to content

Commit

Permalink
Merged 'tseaver-no_globals_imports' branch:
Browse files Browse the repository at this point in the history
o Replaced  imports from the 'Globals' module throughout the tree with
  imports from the actual modules;  the 'Globals' module was always intended
  to be an area for shared data, rather than a "facade" for imports.

o Added 'zope.deferredimport.deprecation' entries to 'Globals/__init__.py'
  for all previously imported symbols / modules.

o Moved 'ApplicationdefaultPermissions' from 'App/class_init.py' to
  'AccessCoontrol/Permission.py', to avoid possible import cycle in
  third-party code.

o Moved canonical location of UNIQUE / REPLACEABLE / NOT_REPLACEABLE
  constants from 'Globals' to 'OFS.ObjectManager'.

o Removed 'stuffGlobals' hack in favor of the deferred / deprecation
  imports.
  • Loading branch information
tseaver committed Jan 2, 2009
1 parent de69e2d commit f8a257a
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 36 deletions.
45 changes: 28 additions & 17 deletions PythonScript.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,38 @@
This product provides support for Script objects containing restricted
Python code.
"""

__version__='$Revision: 1.56 $'[11:-2]

import sys, os, traceback, re, marshal, new
from logging import getLogger
from Globals import DTMLFile, MessageDialog, package_home
import AccessControl, OFS, RestrictedPython
import marshal
import new
import os
import re
import sys
import traceback
from urllib import quote

from AccessControl.requestmethod import requestmethod
from AccessControl.SecurityInfo import ClassSecurityInfo
from AccessControl.SecurityManagement import getSecurityManager
from AccessControl.ZopeGuards import get_safe_globals, guarded_getattr
from AccessControl.ZopeGuards import get_safe_globals, guarded_getattr
from Acquisition import aq_parent
from OFS.SimpleItem import SimpleItem
from App.class_init import InitializeClass
from App.Common import package_home
from App.Dialogs import MessageDialog
from App.special_dtml import DTMLFile
from DateTime.DateTime import DateTime
from urllib import quote
from webdav.Lockable import ResourceLockedError
from Shared.DC.Scripts.Script import Script, BindingsUI, defaultBindings
from AccessControl import getSecurityManager
from OFS.History import Historical, html_diff
from OFS.Cache import Cacheable
from AccessControl.ZopeGuards import get_safe_globals, guarded_getattr
from AccessControl.requestmethod import requestmethod

from OFS.History import Historical
from OFS.History import html_diff
from OFS.SimpleItem import SimpleItem
from RestrictedPython import compile_restricted_function
from Shared.DC.Scripts.Script import BindingsUI
from Shared.DC.Scripts.Script import defaultBindings
from Shared.DC.Scripts.Script import Script
from webdav.Lockable import ResourceLockedError
from zExceptions import Forbidden
import Globals

LOG = getLogger('PythonScripts')

Expand Down Expand Up @@ -111,7 +122,7 @@ def __init__(self, id):
self.ZBindings_edit(defaultBindings)
self._makeFunction()

security = AccessControl.ClassSecurityInfo()
security = ClassSecurityInfo()

security.declareObjectProtected('View')
security.declareProtected('View', '__call__')
Expand Down Expand Up @@ -225,7 +236,7 @@ def __setstate__(self, state):
self._newfun(marshal.loads(self._code))

def _compiler(self, *args, **kw):
return RestrictedPython.compile_restricted_function(*args, **kw)
return compile_restricted_function(*args, **kw)

def _compile(self):
bind_names = self.getBindingAssignments().getAssignedNamesInOrder()
Expand Down Expand Up @@ -509,7 +520,7 @@ def document_src(self, REQUEST=None, RESPONSE=None):
return self.read()


Globals.InitializeClass(PythonScript)
InitializeClass(PythonScript)

class PythonScriptTracebackSupplement:
"""Implementation of ITracebackSupplement"""
Expand Down
55 changes: 36 additions & 19 deletions standard.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,46 @@
Scripts. It can be accessed from Python with the statement
"import Products.PythonScripts.standard"
"""

__version__='$Revision: 1.14 $'[11:-2]

from AccessControl import ModuleSecurityInfo, getSecurityManager
security = ModuleSecurityInfo()

security.declarePublic('special_formats', 'whole_dollars',
'dollars_and_cents', 'structured_text',
'restructured_text',
'sql_quote', 'html_quote', 'url_quote',
'url_quote_plus', 'newline_to_br',
'thousands_commas', 'url_unquote',
'url_unquote_plus', 'urlencode')
from DocumentTemplate.DT_Var import special_formats, \
whole_dollars, dollars_and_cents, structured_text, sql_quote, \
html_quote, url_quote, url_quote_plus, newline_to_br, thousands_commas, \
url_unquote, url_unquote_plus, restructured_text
from urllib import urlencode

from Globals import HTML
from AccessControl.DTML import RestrictedDTML
from AccessControl.SecurityInfo import ModuleSecurityInfo
from AccessControl.SecurityManagement import getSecurityManager
from App.special_dtml import HTML
from DocumentTemplate.DT_Var import special_formats
from DocumentTemplate.DT_Var import whole_dollars
from DocumentTemplate.DT_Var import dollars_and_cents
from DocumentTemplate.DT_Var import structured_text
from DocumentTemplate.DT_Var import sql_quote
from DocumentTemplate.DT_Var import html_quote
from DocumentTemplate.DT_Var import url_quote
from DocumentTemplate.DT_Var import url_quote_plus
from DocumentTemplate.DT_Var import newline_to_br
from DocumentTemplate.DT_Var import thousands_commas
from DocumentTemplate.DT_Var import url_unquote
from DocumentTemplate.DT_Var import url_unquote_plus
from DocumentTemplate.DT_Var import restructured_text
from ZPublisher.HTTPRequest import record

security = ModuleSecurityInfo()

security.declarePublic('special_formats',
'whole_dollars',
'dollars_and_cents',
'structured_text',
'restructured_text',
'sql_quote',
'html_quote',
'url_quote',
'url_quote_plus',
'newline_to_br',
'thousands_commas',
'url_unquote',
'url_unquote_plus',
'urlencode',
)

security.declarePublic('DTML')
class DTML(RestrictedDTML, HTML):
Expand All @@ -54,9 +73,6 @@ def __call__(self, client=None, REQUEST={}, RESPONSE=None, **kw):

finally: security.removeContext(self)

from ZPublisher.HTTPRequest import record

security.declarePublic('Object')

# We don't expose classes directly to restricted code
class _Object(record):
Expand Down Expand Up @@ -85,6 +101,7 @@ def update(self, d):
def __hash__(self):
return id(self)

security.declarePublic('Object')
def Object(**kw):
return _Object(**kw)

Expand Down

0 comments on commit f8a257a

Please sign in to comment.