Commit c1fba44c authored by Aurel's avatar Aurel Committed by Arnaud Fontaine

wip : update patches & import for zope4

parent 3db45131
......@@ -21,8 +21,6 @@ from AccessControl.Permission import Permission
from OFS.ObjectManager import ObjectManager
from OFS.CopySupport import CopyContainer as OriginalCopyContainer
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 sanity_check
from Products.ERP5Type import Permissions
......@@ -70,7 +68,7 @@ class CopyContainer:
return OriginalCopyContainer.manage_copyObjects(self, ids, REQUEST,
RESPONSE)
if uids is None and REQUEST is not None:
return eNoItemsSpecified
raise BadRequest('No items specified')
elif uids is None:
raise ValueError('uids must be specified')
......@@ -80,7 +78,7 @@ class CopyContainer:
for uid in uids:
ob=self.getPortalObject().portal_catalog.getObject(uid)
if not ob.cb_isCopyable():
raise CopyError(eNotSupported % uid)
raise CopyError('Not Supported')
m=Moniker.Moniker(ob)
oblist.append(m.dump())
cp=(0, oblist)
......@@ -185,7 +183,7 @@ class CopyContainer:
# Use default methode
return OriginalCopyContainer.manage_cutObjects(self, ids, REQUEST)
if uids is None and REQUEST is not None:
return eNoItemsSpecified
raise BadRequest('No items specified')
elif uids is None:
raise ValueError('uids must be specified')
......@@ -195,7 +193,7 @@ class CopyContainer:
for uid in uids:
ob=self.getPortalObject().portal_catalog.getObject(uid)
if not ob.cb_isMoveable():
raise CopyError(eNotSupported % id)
raise CopyError('Not Supported')
m=Moniker.Moniker(ob)
oblist.append(m.dump())
cp=(1, oblist) # 0->1 This is the difference with manage_copyObject
......@@ -439,7 +437,7 @@ class CopyContainer:
try:
cp = _cb_decode(cp)
except:
raise CopyError(eInvalid)
raise CopyError("Clipboard Error")
oblist = []
op = cp[0]
app = self.getPhysicalRoot()
......@@ -448,7 +446,7 @@ class CopyContainer:
try:
ob = m.bind(app)
except:
raise CopyError(eNotFound)
raise CopyError('Item Not Found')
self._verifyObjectPaste(ob, validate_src=op + 1)
oblist.append(ob)
result = []
......@@ -475,7 +473,7 @@ class CopyContainer:
)[op]
for ob in oblist:
if not getattr(ob, is_doable_id)():
raise CopyError(eNotSupported % escape(ob.getId()))
raise CopyError('Not Supported')
try:
ob._notifyOfCopyTo(self, op=op)
except:
......@@ -595,7 +593,7 @@ class CopyContainer:
elif REQUEST is not None and '__cp' in REQUEST:
cp = REQUEST['__cp']
if cp is None:
raise CopyError(eNoData)
raise CopyError("No Data")
op, result = self.__duplicate(
cp,
duplicate=False,
......
......@@ -17,11 +17,10 @@ import re
try: from IOBTree import Bucket
except: Bucket=lambda:{}
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.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 Acquisition import aq_base, aq_parent
from zLOG import LOG, INFO, ERROR
......
......@@ -16,26 +16,32 @@ import copy
import sys
import types
from RestrictedPython.RestrictionMutator import RestrictionMutator
from RestrictedPython.transformer import RestrictingNodeTransformer
_MARKER = []
def checkNameLax(self, node, name=_MARKER):
"""Verifies that a name being assigned is safe.
def checkNameLax(self, node, name, allow_magic_methods=False):
"""Check names if they are allowed.
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
runtime checks to prevent access to forbidden attributes from objects.
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:
# we use same implementation for checkName and checkAttrName which access
# the name in different ways ( see RestrictionMutator 3.6.0 )
name = node.attrname
if name is None:
return
if name.endswith('__roles__'):
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
......@@ -49,17 +55,17 @@ from AccessControl.ZopeGuards import (safe_builtins, _marker, Unauthorized,
# TODO: add buffer/bytearray
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)
del safe_builtins['dict']
del safe_builtins['list']
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,
property=property, slice=slice, staticmethod=staticmethod,
super=super, type=type)
property=property, staticmethod=staticmethod,
super=super, type=type) # slice=slice,
def guarded_next(iterator, default=_marker):
"""next(iterator[, default])
......@@ -81,7 +87,7 @@ def guarded_next(iterator, default=_marker):
if default is _marker:
raise
return default
add_builtins(next=guarded_next)
#add_builtins(next=guarded_next)
_safe_class_attribute_dict = {}
import inspect
......@@ -237,7 +243,7 @@ from AccessControl.ZopeGuards import _dict_white_list
# (closure) directly to ignore defaultdict like dict/list
from RestrictedPython.Guards import full_write_guard
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)
OrderedDict.__guarded_setitem__ = OrderedDict.__setitem__.__func__
......
......@@ -27,7 +27,7 @@ from Acquisition import Implicit, aq_base
from Persistence import Persistent
from DocumentTemplate.DT_Util import InstanceDict, TemplateDict
from DocumentTemplate.DT_Util import Eval
from AccessControl.Permission import name_trans
from AccessControl.Permission import getPermissionIdentifier
from AccessControl.Permissions import import_export_objects, \
manage_zcatalog_entries
from .SQLCatalog import CatalogError
......@@ -1364,7 +1364,7 @@ InitializeClass(ZCatalog)
def p_name(name):
return '_' + string.translate(name, name_trans) + '_Permission'
return getPermissionIdentifier(name)
def absattr(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