Commit 26f0da6d authored by Aurel's avatar Aurel Committed by Arnaud Fontaine

wip : update patches & import for zope4

parent 35969925
...@@ -21,8 +21,6 @@ from AccessControl.Permission import Permission ...@@ -21,8 +21,6 @@ from AccessControl.Permission import Permission
from OFS.ObjectManager import ObjectManager from OFS.ObjectManager import ObjectManager
from OFS.CopySupport import CopyContainer as OriginalCopyContainer from OFS.CopySupport import CopyContainer as OriginalCopyContainer
from OFS.CopySupport import CopyError from OFS.CopySupport import CopyError
from OFS.CopySupport import eNotSupported, eNoItemsSpecified, eNoData
from OFS.CopySupport import eNotFound, eInvalid
from OFS.CopySupport import _cb_encode, _cb_decode, cookie_path from OFS.CopySupport import _cb_encode, _cb_decode, cookie_path
from OFS.CopySupport import sanity_check from OFS.CopySupport import sanity_check
from Products.ERP5Type import Permissions from Products.ERP5Type import Permissions
...@@ -70,7 +68,7 @@ class CopyContainer: ...@@ -70,7 +68,7 @@ class CopyContainer:
return OriginalCopyContainer.manage_copyObjects(self, ids, REQUEST, return OriginalCopyContainer.manage_copyObjects(self, ids, REQUEST,
RESPONSE) RESPONSE)
if uids is None and REQUEST is not None: if uids is None and REQUEST is not None:
return eNoItemsSpecified raise BadRequest('No items specified')
elif uids is None: elif uids is None:
raise ValueError('uids must be specified') raise ValueError('uids must be specified')
...@@ -80,7 +78,7 @@ class CopyContainer: ...@@ -80,7 +78,7 @@ class CopyContainer:
for uid in uids: for uid in uids:
ob=self.getPortalObject().portal_catalog.getObject(uid) ob=self.getPortalObject().portal_catalog.getObject(uid)
if not ob.cb_isCopyable(): if not ob.cb_isCopyable():
raise CopyError(eNotSupported % uid) raise CopyError('Not Supported')
m=Moniker.Moniker(ob) m=Moniker.Moniker(ob)
oblist.append(m.dump()) oblist.append(m.dump())
cp=(0, oblist) cp=(0, oblist)
...@@ -185,7 +183,7 @@ class CopyContainer: ...@@ -185,7 +183,7 @@ class CopyContainer:
# Use default methode # Use default methode
return OriginalCopyContainer.manage_cutObjects(self, ids, REQUEST) return OriginalCopyContainer.manage_cutObjects(self, ids, REQUEST)
if uids is None and REQUEST is not None: if uids is None and REQUEST is not None:
return eNoItemsSpecified raise BadRequest('No items specified')
elif uids is None: elif uids is None:
raise ValueError('uids must be specified') raise ValueError('uids must be specified')
...@@ -195,7 +193,7 @@ class CopyContainer: ...@@ -195,7 +193,7 @@ class CopyContainer:
for uid in uids: for uid in uids:
ob=self.getPortalObject().portal_catalog.getObject(uid) ob=self.getPortalObject().portal_catalog.getObject(uid)
if not ob.cb_isMoveable(): if not ob.cb_isMoveable():
raise CopyError(eNotSupported % id) raise CopyError('Not Supported')
m=Moniker.Moniker(ob) m=Moniker.Moniker(ob)
oblist.append(m.dump()) oblist.append(m.dump())
cp=(1, oblist) # 0->1 This is the difference with manage_copyObject cp=(1, oblist) # 0->1 This is the difference with manage_copyObject
...@@ -439,7 +437,7 @@ class CopyContainer: ...@@ -439,7 +437,7 @@ class CopyContainer:
try: try:
cp = _cb_decode(cp) cp = _cb_decode(cp)
except: except:
raise CopyError(eInvalid) raise CopyError("Clipboard Error")
oblist = [] oblist = []
op = cp[0] op = cp[0]
app = self.getPhysicalRoot() app = self.getPhysicalRoot()
...@@ -448,7 +446,7 @@ class CopyContainer: ...@@ -448,7 +446,7 @@ class CopyContainer:
try: try:
ob = m.bind(app) ob = m.bind(app)
except: except:
raise CopyError(eNotFound) raise CopyError('Item Not Found')
self._verifyObjectPaste(ob, validate_src=op + 1) self._verifyObjectPaste(ob, validate_src=op + 1)
oblist.append(ob) oblist.append(ob)
result = [] result = []
...@@ -475,7 +473,7 @@ class CopyContainer: ...@@ -475,7 +473,7 @@ class CopyContainer:
)[op] )[op]
for ob in oblist: for ob in oblist:
if not getattr(ob, is_doable_id)(): if not getattr(ob, is_doable_id)():
raise CopyError(eNotSupported % escape(ob.getId())) raise CopyError('Not Supported')
try: try:
ob._notifyOfCopyTo(self, op=op) ob._notifyOfCopyTo(self, op=op)
except: except:
...@@ -595,7 +593,7 @@ class CopyContainer: ...@@ -595,7 +593,7 @@ class CopyContainer:
elif REQUEST is not None and '__cp' in REQUEST: elif REQUEST is not None and '__cp' in REQUEST:
cp = REQUEST['__cp'] cp = REQUEST['__cp']
if cp is None: if cp is None:
raise CopyError(eNoData) raise CopyError("No Data")
op, result = self.__duplicate( op, result = self.__duplicate(
cp, cp,
duplicate=False, duplicate=False,
......
...@@ -17,10 +17,9 @@ import re ...@@ -17,10 +17,9 @@ import re
try: from IOBTree import Bucket try: from IOBTree import Bucket
except: Bucket=lambda:{} except: Bucket=lambda:{}
from Shared.DC.ZRDB.Aqueduct import decodestring, parse from Shared.DC.ZRDB.Aqueduct import decodestring, parse
from Shared.DC.ZRDB.DA import DA, DatabaseError, SQLMethodTracebackSupplement from Shared.DC.ZRDB.DA import DA, DatabaseError, SQLMethodTracebackSupplement, getBrain
from Shared.DC.ZRDB import RDB from Shared.DC.ZRDB import RDB
from Shared.DC.ZRDB.Results import Results from Shared.DC.ZRDB.Results import Results
from App.Extensions import getBrain
from AccessControl import ClassSecurityInfo, getSecurityManager from AccessControl import ClassSecurityInfo, getSecurityManager
from Products.ERP5Type.Globals import InitializeClass from Products.ERP5Type.Globals import InitializeClass
from Acquisition import aq_base, aq_parent from Acquisition import aq_base, aq_parent
......
...@@ -16,26 +16,32 @@ import copy ...@@ -16,26 +16,32 @@ import copy
import sys import sys
import types import types
from RestrictedPython.RestrictionMutator import RestrictionMutator from RestrictedPython.transformer import RestrictingNodeTransformer
_MARKER = [] _MARKER = []
def checkNameLax(self, node, name=_MARKER): def checkNameLax(self, node, name, allow_magic_methods=False):
"""Verifies that a name being assigned is safe. """Check names if they are allowed.
In ERP5 we are much more lax that than in Zope's original restricted In ERP5 we are much more lax that than in Zope's original restricted
python and allow to using names starting with _, because we rely on python and allow to using names starting with _, because we rely on
runtime checks to prevent access to forbidden attributes from objects. runtime checks to prevent access to forbidden attributes from objects.
We don't allow defining attributes ending with __roles__ though. We don't allow defining attributes ending with __roles__ though.
If ``allow_magic_methods is True`` names in `ALLOWED_FUNC_NAMES`
are additionally allowed although their names start with `_`.
""" """
if name is _MARKER: if name is None:
# we use same implementation for checkName and checkAttrName which access return
# the name in different ways ( see RestrictionMutator 3.6.0 )
name = node.attrname
if name.endswith('__roles__'): if name.endswith('__roles__'):
self.error(node, '"%s" is an invalid variable name because ' self.error(node, '"%s" is an invalid variable name because '
'it ends with "__roles__".' % name) 'it ends with "__roles__".' % name)
elif name in FORBIDDEN_FUNC_NAMES:
self.error(node, '"{name}" is a reserved name.'.format(name=name))
RestrictionMutator.checkName = RestrictionMutator.checkAttrName = checkNameLax RestrictingNodeTransformer.check_name = checkNameLax
# XXX we might want to pach visit_Attribute too
from Acquisition import aq_acquire from Acquisition import aq_acquire
...@@ -49,17 +55,17 @@ from AccessControl.ZopeGuards import (safe_builtins, _marker, Unauthorized, ...@@ -49,17 +55,17 @@ from AccessControl.ZopeGuards import (safe_builtins, _marker, Unauthorized,
# TODO: add buffer/bytearray # TODO: add buffer/bytearray
def add_builtins(**kw): def add_builtins(**kw):
assert not set(safe_builtins).intersection(kw) assert not set(safe_builtins).intersection(kw), "%r intersect %r\n%r" %(safe_builtins, kw, set(safe_builtins).intersection(kw))
safe_builtins.update(kw) safe_builtins.update(kw)
del safe_builtins['dict'] del safe_builtins['dict']
del safe_builtins['list'] del safe_builtins['list']
add_builtins(Ellipsis=Ellipsis, NotImplemented=NotImplemented, add_builtins(Ellipsis=Ellipsis, NotImplemented=NotImplemented,
dict=dict, list=list, set=set, frozenset=frozenset) dict=dict, list=list) #, set=set, frozenset=frozenset)
add_builtins(bin=bin, classmethod=classmethod, format=format, object=object, add_builtins(bin=bin, classmethod=classmethod, format=format, object=object,
property=property, slice=slice, staticmethod=staticmethod, property=property, staticmethod=staticmethod,
super=super, type=type) super=super, type=type) # slice=slice,
def guarded_next(iterator, default=_marker): def guarded_next(iterator, default=_marker):
"""next(iterator[, default]) """next(iterator[, default])
...@@ -81,7 +87,7 @@ def guarded_next(iterator, default=_marker): ...@@ -81,7 +87,7 @@ def guarded_next(iterator, default=_marker):
if default is _marker: if default is _marker:
raise raise
return default return default
add_builtins(next=guarded_next) #add_builtins(next=guarded_next)
_safe_class_attribute_dict = {} _safe_class_attribute_dict = {}
import inspect import inspect
...@@ -237,7 +243,7 @@ from AccessControl.ZopeGuards import _dict_white_list ...@@ -237,7 +243,7 @@ from AccessControl.ZopeGuards import _dict_white_list
# (closure) directly to ignore defaultdict like dict/list # (closure) directly to ignore defaultdict like dict/list
from RestrictedPython.Guards import full_write_guard from RestrictedPython.Guards import full_write_guard
ContainerAssertions[defaultdict] = _check_access_wrapper(defaultdict, _dict_white_list) ContainerAssertions[defaultdict] = _check_access_wrapper(defaultdict, _dict_white_list)
full_write_guard.func_closure[1].cell_contents.__self__[defaultdict] = True #XXXfull_write_guard.func_closure[1].cell_contents.__self__[defaultdict] = True
ContainerAssertions[OrderedDict] = _check_access_wrapper(OrderedDict, _dict_white_list) ContainerAssertions[OrderedDict] = _check_access_wrapper(OrderedDict, _dict_white_list)
OrderedDict.__guarded_setitem__ = OrderedDict.__setitem__.__func__ OrderedDict.__guarded_setitem__ = OrderedDict.__setitem__.__func__
......
...@@ -27,7 +27,7 @@ from Acquisition import Implicit, aq_base ...@@ -27,7 +27,7 @@ from Acquisition import Implicit, aq_base
from Persistence import Persistent from Persistence import Persistent
from DocumentTemplate.DT_Util import InstanceDict, TemplateDict from DocumentTemplate.DT_Util import InstanceDict, TemplateDict
from DocumentTemplate.DT_Util import Eval from DocumentTemplate.DT_Util import Eval
from AccessControl.Permission import name_trans from AccessControl.Permission import getPermissionIdentifier
from AccessControl.Permissions import import_export_objects, \ from AccessControl.Permissions import import_export_objects, \
manage_zcatalog_entries manage_zcatalog_entries
from .SQLCatalog import CatalogError from .SQLCatalog import CatalogError
...@@ -1364,7 +1364,7 @@ InitializeClass(ZCatalog) ...@@ -1364,7 +1364,7 @@ InitializeClass(ZCatalog)
def p_name(name): def p_name(name):
return '_' + string.translate(name, name_trans) + '_Permission' return getPermissionIdentifier(name)
def absattr(attr): def absattr(attr):
if callable(attr): return attr() if callable(attr): return attr()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment