Commit 9829b291 authored by Aurel's avatar Aurel

wip : update patches & import for zope4

parent b808a05f
......@@ -20,8 +20,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
......@@ -438,7 +436,7 @@ class CopyContainer:
try:
cp = _cb_decode(cp)
except:
raise CopyError(eInvalid)
raise CopyError("Clipboard Error")
oblist = []
op = cp[0]
app = self.getPhysicalRoot()
......@@ -447,7 +445,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 = []
......@@ -474,7 +472,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:
......@@ -594,7 +592,7 @@ class CopyContainer:
elif REQUEST is not None and REQUEST.has_key('__cp'):
cp = REQUEST['__cp']
if cp is None:
raise CopyError(eNoData)
raise CopyError("No Data")
op, result = self.__duplicate(
cp,
duplicate=False,
......
......@@ -49,7 +49,7 @@ from Products.ERP5Type.patches import ActionInformation
from Products.ERP5Type.patches import ActionProviderBase
from Products.ERP5Type.patches import ActionsTool
from Products.ERP5Type.patches import CookieCrumbler
from Products.ERP5Type.patches import PropertySheets
#from Products.ERP5Type.patches import PropertySheets
from Products.ERP5Type.patches import CMFCoreSkinnable
from Products.ERP5Type.patches import CMFCoreSkinsTool
from Products.ERP5Type.patches import OFSFile
......
......@@ -17,10 +17,9 @@ 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 Products.ERP5Type.Globals import InitializeClass
from Acquisition import aq_base, aq_parent
......
......@@ -13,8 +13,13 @@
##############################################################################
# Import: add rename feature and make _importObjectFromFile return the object
from OFS.ObjectManager import ObjectManager, customImporters
from App.version_txt import getZopeVersion
from OFS.ObjectManager import ObjectManager
from OFS.XMLExportImport import importXML
from OFS.XMLExportImport import magic
customImporters={magic: importXML,
}
def ObjectManager_importObjectFromFile(self, filepath, verify=1, set_owner=1, id=None, suppress_events=False):
#LOG('_importObjectFromFile, filepath',0,filepath)
......
......@@ -15,26 +15,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
......@@ -48,17 +54,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])
......@@ -80,7 +86,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
......@@ -223,7 +229,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
# In contrary to builtins such as dict/defaultdict, it is possible to set
# attributes on OrderedDict instances, so only allow setitem/delitem
......@@ -469,13 +475,14 @@ ContainerAssertions[pd.DataFrame] = _check_access_wrapper(
# of RestrictedPython (closure) directly to allow
# write access to ndarray and pandas DataFrame.
from RestrictedPython.Guards import full_write_guard
full_write_guard.func_closure[1].cell_contents.__self__[np.ndarray] = True
full_write_guard.func_closure[1].cell_contents.__self__[np.core.records.recarray] = True
full_write_guard.func_closure[1].cell_contents.__self__[np.core.records.record] = True
full_write_guard.func_closure[1].cell_contents.__self__[pd.DataFrame] = True
full_write_guard.func_closure[1].cell_contents.__self__[pd.Series] = True
full_write_guard.func_closure[1].cell_contents.__self__[pd.tseries.index.DatetimeIndex] = True
full_write_guard.func_closure[1].cell_contents.__self__[pd.core.indexing._iLocIndexer] = True
full_write_guard.func_closure[1].cell_contents.__self__[pd.core.indexing._LocIndexer] = True
full_write_guard.func_closure[1].cell_contents.__self__[pd.MultiIndex] = True
full_write_guard.func_closure[1].cell_contents.__self__[pd.Index] = True
if False:
full_write_guard.func_closure[1].cell_contents.__self__[np.ndarray] = True
full_write_guard.func_closure[1].cell_contents.__self__[np.core.records.recarray] = True
full_write_guard.func_closure[1].cell_contents.__self__[np.core.records.record] = True
full_write_guard.func_closure[1].cell_contents.__self__[pd.DataFrame] = True
full_write_guard.func_closure[1].cell_contents.__self__[pd.Series] = True
full_write_guard.func_closure[1].cell_contents.__self__[pd.tseries.index.DatetimeIndex] = True
full_write_guard.func_closure[1].cell_contents.__self__[pd.core.indexing._iLocIndexer] = True
full_write_guard.func_closure[1].cell_contents.__self__[pd.core.indexing._LocIndexer] = True
full_write_guard.func_closure[1].cell_contents.__self__[pd.MultiIndex] = True
full_write_guard.func_closure[1].cell_contents.__self__[pd.Index] = True
......@@ -32,7 +32,12 @@ from SearchKey import SearchKey
from Products.ZSQLCatalog.Query.SimpleQuery import SimpleQuery
from Products.ZSQLCatalog.Query.ComplexQuery import ComplexQuery
from zLOG import LOG
from DateTime.DateTime import DateTime, DateTimeError, _cache
from DateTime.DateTime import DateTime, DateTimeError
try:
from DateTime.DateTime import _TZINFO as _cache
except ImportError:
# BBB version < zope4
from DateTime.DateTime import _cache
from Products.ZSQLCatalog.interfaces.search_key import ISearchKey
from zope.interface.verify import verifyClass
from Products.ZSQLCatalog.SearchText import parse
......
......@@ -23,7 +23,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
......@@ -1362,7 +1362,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