Commit 66d1eacc authored by Aurel's avatar Aurel Committed by Arnaud Fontaine

update local patches, imports and method parameters according to code of zope4

* "OFS.CopySupport exceptions have been removed: you should use strings instead."
* "WSGI is used in place of ZServer."
* "StringType must be imported from types"
* "'script' is forbidden as python script name"
parent 58070276
...@@ -22,7 +22,10 @@ from zLOG import LOG,ERROR,INFO,WARNING ...@@ -22,7 +22,10 @@ from zLOG import LOG,ERROR,INFO,WARNING
from OFS.Image import File, Image from OFS.Image import File, Image
import os, transaction import os, transaction
from AccessControl import getSecurityManager, ClassSecurityInfo from AccessControl import getSecurityManager, ClassSecurityInfo
from Globals import package_home try:
from App.Common import package_home
except ImportError: # BBB Zope2
from Globals import package_home
import PIL.Image as PIL_Image import PIL.Image as PIL_Image
import thread import thread
import random import random
......
...@@ -20,8 +20,12 @@ import ZConfig ...@@ -20,8 +20,12 @@ import ZConfig
import Zope2 import Zope2
from Zope2.Startup.run import make_wsgi_app from Zope2.Startup.run import make_wsgi_app
from Products.ERP5Type.patches.WSGIPublisher import publish_module try:
from ZPublisher.WSGIPublisher import _MODULES
from ZPublisher.WSGIPublisher import publish_module
except ImportError:
# BBB Zope2
from Products.ERP5Type.patches.WSGIPublisher import publish_module
# this class licensed under the MIT license (stolen from pyramid_translogger) # this class licensed under the MIT license (stolen from pyramid_translogger)
class TransLogger(object): class TransLogger(object):
...@@ -167,7 +171,10 @@ def runwsgi(): ...@@ -167,7 +171,10 @@ def runwsgi():
args = parser.parse_args() args = parser.parse_args()
startup = os.path.dirname(Zope2.Startup.__file__) startup = os.path.dirname(Zope2.Startup.__file__)
schema = ZConfig.loadSchema(os.path.join(startup, 'zopeschema.xml')) if os.path.isfile(os.path.join(startup, 'wsgischema.xml')):
schema = ZConfig.loadSchema(os.path.join(startup, 'wsgischema.xml'))
else: # BBB
schema = ZConfig.loadSchema(os.path.join(startup, 'zopeschema.xml'))
conf, _ = ZConfig.loadConfig(schema, args.zope_conf) conf, _ = ZConfig.loadConfig(schema, args.zope_conf)
make_wsgi_app({}, zope_conf=args.zope_conf) make_wsgi_app({}, zope_conf=args.zope_conf)
...@@ -190,11 +197,11 @@ def runwsgi(): ...@@ -190,11 +197,11 @@ def runwsgi():
port = int(port) port = int(port)
createServer( createServer(
app_wrapper( app_wrapper(
large_file_threshold=conf.large_file_threshold, large_file_threshold=getattr(conf, 'large_file_threshold', None),
webdav_ports=[port] if args.webdav else ()), webdav_ports=[port] if args.webdav else ()),
listen=args.address, listen=args.address,
logger=logging.getLogger("access"), logger=logging.getLogger("access"),
threads=conf.zserver_threads, threads=getattr(conf, 'zserver_threads', 4),
asyncore_use_poll=True, asyncore_use_poll=True,
# Prevent waitress from adding its own Via and Server response headers. # Prevent waitress from adding its own Via and Server response headers.
ident=None, ident=None,
......
...@@ -21,7 +21,7 @@ class ComputedAttributeGetItemCompatibleMixin(ZSQLBrain): ...@@ -21,7 +21,7 @@ class ComputedAttributeGetItemCompatibleMixin(ZSQLBrain):
"""A brain that supports accessing computed attributes using __getitem__ """A brain that supports accessing computed attributes using __getitem__
protocol. protocol.
""" """
def __init__(self): def __init__(self, *args, **kw):
# __getitem__ returns the computed attribute directly, but if we access # __getitem__ returns the computed attribute directly, but if we access
# brain['node_title'] we expect to have the attribute after computation, # brain['node_title'] we expect to have the attribute after computation,
# not the ComputedAttribute attribue instance. Defining a __getitem__ # not the ComputedAttribute attribue instance. Defining a __getitem__
......
...@@ -48,7 +48,10 @@ from Products.ZSQLCatalog.SQLCatalog import Query, ComplexQuery, SimpleQuery ...@@ -48,7 +48,10 @@ from Products.ZSQLCatalog.SQLCatalog import Query, ComplexQuery, SimpleQuery
from Shared.DC.ZRDB.Results import Results from Shared.DC.ZRDB.Results import Results
from Products.ERP5Type.Utils import mergeZRDBResults from Products.ERP5Type.Utils import mergeZRDBResults
from App.Extensions import getBrain try: # BBB Zope 2.12
from App.Extensions import getBrain
except ImportError:
from Shared.DC.ZRDB.DA import getBrain
from MySQLdb import ProgrammingError from MySQLdb import ProgrammingError
from MySQLdb.constants.ER import NO_SUCH_TABLE from MySQLdb.constants.ER import NO_SUCH_TABLE
......
...@@ -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,11 +17,10 @@ import re ...@@ -17,11 +17,10 @@ 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
from zLOG import LOG, INFO, ERROR from zLOG import LOG, INFO, ERROR
......
...@@ -89,16 +89,28 @@ DateTimeKlass.__getstate__ = DateTime__getstate__ ...@@ -89,16 +89,28 @@ DateTimeKlass.__getstate__ = DateTime__getstate__
def DateTime_parse(self, st, datefmt=getDefaultDateFormat()): def DateTime_parse(self, st, datefmt=getDefaultDateFormat()):
# Parse date-time components from a string # Parse date-time components from a string
month=year=tz=tm=None month=year=tz=tm=None
spaces =self.space_chars try: # BBB DateTime 2.12
intpat =self.int_pattern spaces =self.space_chars
fltpat =self.flt_pattern intpat =self.int_pattern
wordpat =self.name_pattern fltpat =self.flt_pattern
delimiters =self.delimiters wordpat =self.name_pattern
MonthNumbers =self._monthmap delimiters =self.delimiters
DayOfWeekNames=self._daymap MonthNumbers =self._monthmap
ValidZones =self._tzinfo._zidx DayOfWeekNames=self._daymap
ValidZones =self._tzinfo._zidx
_MONTH_LEN = self._month_len
except AttributeError:
from DateTime.DateTime import (SPACE_CHARS as spaces,
INT_PATTERN as intpat,
FLT_PATTERN as fltpat,
NAME_PATTERN as wordpat,
DELIMITERS as delimiters,
_MONTHMAP as MonthNumbers,
_DAYMAP as DayOfWeekNames,
_TZINFO,
_MONTH_LEN)
ValidZones = _TZINFO._zidx
TimeModifiers =['am','pm'] TimeModifiers =['am','pm']
# Find timezone first, since it should always be the last # Find timezone first, since it should always be the last
# element, and may contain a slash, confusing the parser. # element, and may contain a slash, confusing the parser.
st= st.strip() st= st.strip()
...@@ -236,10 +248,9 @@ def DateTime_parse(self, st, datefmt=getDefaultDateFormat()): ...@@ -236,10 +248,9 @@ def DateTime_parse(self, st, datefmt=getDefaultDateFormat()):
year = _correctYear(year) year = _correctYear(year)
#handle dates before year 1000 #handle dates before year 1000
#if year < 1000: raise SyntaxError, st #if year < 1000: raise SyntaxError, st
leap = year%4==0 and (year%100!=0 or year%400==0) leap = year%4==0 and (year%100!=0 or year%400==0)
try: try:
if not day or day > self._month_len[leap][month]: if not day or day > _MONTH_LEN[leap][month]:
raise DateError(st) raise DateError(st)
except IndexError: except IndexError:
raise DateError(st) raise DateError(st)
......
...@@ -13,7 +13,8 @@ ...@@ -13,7 +13,8 @@
# #
############################################################################## ##############################################################################
from OFS.PropertySheets import DAVProperties, isDavCollection from OFS.PropertySheets import DAVProperties
from webdav.common import isDavCollection
from Acquisition import aq_base from Acquisition import aq_base
# This is required to make an ERP5 Document (folderish) look like a file (non folderish) # This is required to make an ERP5 Document (folderish) look like a file (non folderish)
......
...@@ -11,41 +11,40 @@ ...@@ -11,41 +11,40 @@
# #
############################################################################## ##############################################################################
from Products.ERP5Type.Timeout import getPublisherDeadlineValue from Products.ERP5Type.Timeout import getPublisherDeadlineValue
from ZPublisher import Publish try:
from ZPublisher.Publish import ( from ZServer.ZPublisher import Publish
# Produced using: from ZServer.ZPublisher.Publish import (
# dis.dis( # Produced using:
# compile(open(<this_file>, 'r').read(), 'foo', 'exec').co_consts[ # dis.dis(
# <index of publish code object in co_consts> # compile(open(<this_file>, 'r').read(), 'foo', 'exec').co_consts[
# ] # <index of publish code object in co_consts>
# ) # ]
# and checking all uniques LOAD_GLOBAL names, excluding builtins and # )
# getPublisherDeadlineValue, and including publish parameter default # and checking all uniques LOAD_GLOBAL names, excluding builtins and
# values. # getPublisherDeadlineValue, and including publish parameter default
ISkinnable, # values.
PubAfterTraversal, ISkinnable,
PubBeforeAbort, IBrowserPage,
PubBeforeCommit, recordMetaData,
PubFailure, pubevents,
PubStart, Redirect,
PubSuccess, Retry,
Redirect, call_object,
Retry, dont_publish_class,
call_object, endInteraction,
dont_publish_class, get_module_info,
endInteraction, mapply,
get_module_info, missing_name,
mapply, newInteraction,
missing_name, notify,
newInteraction, publish,
notify, setDefaultSkin,
publish, sys,
setDefaultSkin, urlparse,
sys, noSecurityManager,
urlparse, )
)
def publish(request, module_name, after_list, debug=0,
def publish(request, module_name, after_list, debug=0,
# Optimize: # Optimize:
call_object=call_object, call_object=call_object,
missing_name=missing_name, missing_name=missing_name,
...@@ -53,154 +52,354 @@ def publish(request, module_name, after_list, debug=0, ...@@ -53,154 +52,354 @@ def publish(request, module_name, after_list, debug=0,
mapply=mapply, mapply=mapply,
): ):
(bobo_before, bobo_after, object, realm, debug_mode, err_hook, (bobo_before, bobo_after, object, realm, debug_mode, err_hook,
validated_hook, transactions_manager)= get_module_info(module_name) validated_hook, transactions_manager)= get_module_info(module_name)
parents=None parents=None
response=None response=None
try: try:
with getPublisherDeadlineValue(request): with getPublisherDeadlineValue(request):
notify(PubStart(request)) notify(pubevents.PubStart(request))
# TODO pass request here once BaseRequest implements IParticipation # TODO pass request here once BaseRequest implements IParticipation
newInteraction() newInteraction()
request.processInputs() request.processInputs()
request_get=request.get request_get = request.get
response=request.response response = request.response
# First check for "cancel" redirect: # First check for "cancel" redirect:
if request_get('SUBMIT', '').strip().lower() == 'cancel': if request_get('SUBMIT', '').strip().lower() == 'cancel':
cancel = request_get('CANCEL_ACTION', '') cancel = request_get('CANCEL_ACTION', '')
if cancel: if cancel:
# Relative URLs aren't part of the spec, but are accepted by # Relative URLs aren't part of the spec, but are accepted by
# some browsers. # some browsers.
for part, base in zip(urlparse(cancel)[:3], for part, base in zip(urlparse(cancel)[:3],
urlparse(request['BASE1'])[:3]): urlparse(request['BASE1'])[:3]):
if not part: if not part:
continue continue
if not part.startswith(base): if not part.startswith(base):
cancel = '' cancel = ''
break break
if cancel: if cancel:
raise Redirect(cancel) raise Redirect(cancel)
after_list[0]=bobo_after after_list[0] = bobo_after
if debug_mode: if debug_mode:
response.debug_mode=debug_mode response.debug_mode = debug_mode
if realm and not request.get('REMOTE_USER',None): if realm and not request.get('REMOTE_USER', None):
response.realm=realm response.realm = realm
if bobo_before is not None: noSecurityManager()
bobo_before() if bobo_before is not None:
bobo_before()
# Get the path list.
# According to RFC1738 a trailing space in the path is valid. # Get the path list.
path=request_get('PATH_INFO') # According to RFC1738 a trailing space in the path is valid.
path = request_get('PATH_INFO')
request['PARENTS']=parents=[object]
request['PARENTS'] = parents = [object]
if transactions_manager:
transactions_manager.begin() if transactions_manager:
transactions_manager.begin()
object=request.traverse(path, validated_hook=validated_hook)
object = request.traverse(path, validated_hook=validated_hook)
notify(PubAfterTraversal(request))
if IBrowserPage.providedBy(object):
if transactions_manager: request.postProcessInputs()
transactions_manager.recordMetaData(object, request)
notify(pubevents.PubAfterTraversal(request))
result=mapply(object, request.args, request,
call_object,1, if transactions_manager:
missing_name, recordMetaData(object, request)
dont_publish_class,
request, bind=1) result = mapply(object, request.args, request,
call_object, 1,
if result is not response: missing_name,
response.setBody(result) dont_publish_class,
request, bind=1)
notify(PubBeforeCommit(request)) if result is not response:
response.setBody(result)
if transactions_manager:
transactions_manager.commit() notify(pubevents.PubBeforeCommit(request))
endInteraction()
if transactions_manager:
notify(PubSuccess(request)) transactions_manager.commit()
return response notify(pubevents.PubSuccess(request))
except: endInteraction()
# save in order to give 'PubFailure' the original exception info
exc_info = sys.exc_info() return response
# DM: provide nicer error message for FTP except:
sm = None # save in order to give 'PubFailure' the original exception info
if response is not None: exc_info = sys.exc_info()
sm = getattr(response, "setMessage", None) # DM: provide nicer error message for FTP
sm = None
if sm is not None: if response is not None:
from asyncore import compact_traceback sm = getattr(response, "setMessage", None)
cl,val= sys.exc_info()[:2]
sm('%s: %s %s' % ( if sm is not None:
getattr(cl,'__name__',cl), val, from asyncore import compact_traceback
debug_mode and compact_traceback()[-1] or '')) cl, val = sys.exc_info()[:2]
sm('%s: %s %s' % (
# debug is just used by tests (has nothing to do with debug_mode!) getattr(cl, '__name__', cl), val,
if not debug and err_hook is not None: debug_mode and compact_traceback()[-1] or ''))
retry = False
if parents: # debug is just used by tests (has nothing to do with debug_mode!)
parents=parents[0] if not debug and err_hook is not None:
try: retry = False
if parents:
parents = parents[0]
try: try:
with getPublisherDeadlineValue(request): try:
return err_hook(parents, request,
sys.exc_info()[0],
sys.exc_info()[1],
sys.exc_info()[2],
)
except Retry:
if not request.supports_retry():
with getPublisherDeadlineValue(request): with getPublisherDeadlineValue(request):
return err_hook(parents, request, return err_hook(parents, request,
sys.exc_info()[0], sys.exc_info()[0],
sys.exc_info()[1], sys.exc_info()[1],
sys.exc_info()[2], sys.exc_info()[2],
) )
retry = True except Retry:
finally: if not request.supports_retry():
# Note: 'abort's can fail. Nevertheless, we want end request handling with getPublisherDeadlineValue(request):
return err_hook(parents, request,
sys.exc_info()[0],
sys.exc_info()[1],
sys.exc_info()[2],
)
retry = True
finally:
# Note: 'abort's can fail.
# Nevertheless, we want end request handling.
try:
try:
notify(pubevents.PubBeforeAbort(
request, exc_info, retry))
finally:
if transactions_manager:
transactions_manager.abort()
finally:
endInteraction()
notify(pubevents.PubFailure(request, exc_info, retry))
# Only reachable if Retry is raised and request supports retry.
newrequest = request.retry()
request.close() # Free resources held by the request.
# Set the default layer/skin on the newly generated request
if ISkinnable.providedBy(newrequest):
setDefaultSkin(newrequest)
try:
return publish(newrequest, module_name, after_list, debug)
finally:
newrequest.close()
else:
# Note: 'abort's can fail.
# Nevertheless, we want end request handling.
try: try:
try: try:
notify(PubBeforeAbort(request, exc_info, retry)) notify(pubevents.PubBeforeAbort(request, exc_info, False))
finally: finally:
if transactions_manager: if transactions_manager:
transactions_manager.abort() transactions_manager.abort()
finally: finally:
endInteraction() endInteraction()
notify(PubFailure(request, exc_info, retry)) notify(pubevents.PubFailure(request, exc_info, False))
raise
# Only reachable if Retry is raised and request supports retry.
newrequest=request.retry() Publish.publish = publish
request.close() # Free resources held by the request.
except ImportError: # BBB Zope2
# Set the default layer/skin on the newly generated request from ZPublisher import Publish, pubevents
if ISkinnable.providedBy(newrequest): from ZPublisher.Publish import (
setDefaultSkin(newrequest) # Produced using:
try: # dis.dis(
return publish(newrequest, module_name, after_list, debug) # compile(open(<this_file>, 'r').read(), 'foo', 'exec').co_consts[
finally: # <index of publish code object in co_consts>
newrequest.close() # ]
# )
else: # and checking all uniques LOAD_GLOBAL names, excluding builtins and
# Note: 'abort's can fail. Nevertheless, we want end request handling # getPublisherDeadlineValue, and including publish parameter default
try: # values.
ISkinnable,
PubAfterTraversal,
PubBeforeAbort,
PubBeforeCommit,
PubFailure,
PubStart,
PubSuccess,
Redirect,
Retry,
call_object,
dont_publish_class,
endInteraction,
get_module_info,
mapply,
missing_name,
newInteraction,
notify,
publish,
setDefaultSkin,
sys,
urlparse,
)
def publish(request, module_name, after_list, debug=0,
# Optimize:
call_object=call_object,
missing_name=missing_name,
dont_publish_class=dont_publish_class,
mapply=mapply,
):
(bobo_before, bobo_after, object, realm, debug_mode, err_hook,
validated_hook, transactions_manager)= get_module_info(module_name)
parents=None
response=None
try:
with getPublisherDeadlineValue(request):
notify(PubStart(request))
# TODO pass request here once BaseRequest implements IParticipation
newInteraction()
request.processInputs()
request_get=request.get
response=request.response
# First check for "cancel" redirect:
if request_get('SUBMIT', '').strip().lower() == 'cancel':
cancel = request_get('CANCEL_ACTION', '')
if cancel:
# Relative URLs aren't part of the spec, but are accepted by
# some browsers.
for part, base in zip(urlparse(cancel)[:3],
urlparse(request['BASE1'])[:3]):
if not part:
continue
if not part.startswith(base):
cancel = ''
break
if cancel:
raise Redirect(cancel)
after_list[0]=bobo_after
if debug_mode:
response.debug_mode=debug_mode
if realm and not request.get('REMOTE_USER',None):
response.realm=realm
if bobo_before is not None:
bobo_before()
# Get the path list.
# According to RFC1738 a trailing space in the path is valid.
path=request_get('PATH_INFO')
request['PARENTS']=parents=[object]
if transactions_manager:
transactions_manager.begin()
object=request.traverse(path, validated_hook=validated_hook)
notify(PubAfterTraversal(request))
if transactions_manager:
transactions_manager.recordMetaData(object, request)
result=mapply(object, request.args, request,
call_object,1,
missing_name,
dont_publish_class,
request, bind=1)
if result is not response:
response.setBody(result)
notify(PubBeforeCommit(request))
if transactions_manager:
transactions_manager.commit()
endInteraction()
notify(PubSuccess(request))
return response
except:
# save in order to give 'PubFailure' the original exception info
exc_info = sys.exc_info()
# DM: provide nicer error message for FTP
sm = None
if response is not None:
sm = getattr(response, "setMessage", None)
if sm is not None:
from asyncore import compact_traceback
cl,val= sys.exc_info()[:2]
sm('%s: %s %s' % (
getattr(cl,'__name__',cl), val,
debug_mode and compact_traceback()[-1] or ''))
# debug is just used by tests (has nothing to do with debug_mode!)
if not debug and err_hook is not None:
retry = False
if parents:
parents=parents[0]
try:
try:
with getPublisherDeadlineValue(request):
return err_hook(parents, request,
sys.exc_info()[0],
sys.exc_info()[1],
sys.exc_info()[2],
)
except Retry:
if not request.supports_retry():
with getPublisherDeadlineValue(request):
return err_hook(parents, request,
sys.exc_info()[0],
sys.exc_info()[1],
sys.exc_info()[2],
)
retry = True
finally:
# Note: 'abort's can fail. Nevertheless, we want end request handling
try:
try:
notify(PubBeforeAbort(request, exc_info, retry))
finally:
if transactions_manager:
transactions_manager.abort()
finally:
endInteraction()
notify(PubFailure(request, exc_info, retry))
# Only reachable if Retry is raised and request supports retry.
newrequest=request.retry()
request.close() # Free resources held by the request.
# Set the default layer/skin on the newly generated request
if ISkinnable.providedBy(newrequest):
setDefaultSkin(newrequest)
try: try:
notify(PubBeforeAbort(request, exc_info, False)) return publish(newrequest, module_name, after_list, debug)
finally: finally:
if transactions_manager: newrequest.close()
transactions_manager.abort()
finally: else:
endInteraction() # Note: 'abort's can fail. Nevertheless, we want end request handling
notify(PubFailure(request, exc_info, False)) try:
raise try:
notify(PubBeforeAbort(request, exc_info, False))
finally:
if transactions_manager:
transactions_manager.abort()
finally:
endInteraction()
notify(PubFailure(request, exc_info, False))
raise
Publish.publish = publish Publish.publish = publish
...@@ -16,26 +16,48 @@ import copy ...@@ -16,26 +16,48 @@ import copy
import sys import sys
import types import types
from RestrictedPython.RestrictionMutator import RestrictionMutator try:
from RestrictedPython.transformer import FORBIDDEN_FUNC_NAMES
except:
# BBB
FORBIDDEN_FUNC_NAMES = frozenset(['printed',])
_MARKER = [] _MARKER = []
def checkNameLax(self, node, name=_MARKER): def checkNameLax(self, node, name=_MARKER, 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 None:
return
if name is _MARKER: if name is _MARKER:
# we use same implementation for checkName and checkAttrName which access # we use same implementation for checkName and checkAttrName which access
# the name in different ways ( see RestrictionMutator 3.6.0 ) # the name in different ways ( see RestrictionMutator 3.6.0 )
name = node.attrname 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
try:
from RestrictedPython.transformer import RestrictingNodeTransformer
RestrictingNodeTransformer.check_name = checkNameLax
except ImportError:
# BBB Restriced 3.6.0
from RestrictedPython.RestrictionMutator import RestrictionMutator
RestrictionMutator.checkName = RestrictionMutator.checkAttrName = checkNameLax
from Acquisition import aq_acquire from Acquisition import aq_acquire
...@@ -49,18 +71,22 @@ from AccessControl.ZopeGuards import (safe_builtins, _marker, Unauthorized, ...@@ -49,18 +71,22 @@ 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)
if "set" not in safe_builtins: # BBB
add_builtins(set=set, frozenset=frozenset, slice=slice)
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)
def guarded_next(iterator, default=_marker): def guarded_next(iterator, default=_marker):
"""next(iterator[, default]) """next(iterator[, default])
...@@ -81,7 +107,10 @@ def guarded_next(iterator, default=_marker): ...@@ -81,7 +107,10 @@ 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) #if "next" not in safe_builtins: # BBB
# override the default next if exists
safe_builtins.update(next=guarded_next)
# add_builtins()
_safe_class_attribute_dict = {} _safe_class_attribute_dict = {}
import inspect import inspect
...@@ -237,7 +266,7 @@ from AccessControl.ZopeGuards import _dict_white_list ...@@ -237,7 +266,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__
......
...@@ -54,7 +54,12 @@ from ZPublisher.mapply import mapply ...@@ -54,7 +54,12 @@ from ZPublisher.mapply import mapply
from ZPublisher.WSGIPublisher import call_object from ZPublisher.WSGIPublisher import call_object
from ZPublisher.WSGIPublisher import missing_name, WSGIResponse from ZPublisher.WSGIPublisher import missing_name, WSGIResponse
try:
from ZServer.ZPublisher import Publish
isZope4 = True
except ImportError:
isZope4 = False
if sys.version_info >= (3, ): if sys.version_info >= (3, ):
_FILE_TYPES = (IOBase, ) _FILE_TYPES = (IOBase, )
else: else:
...@@ -96,7 +101,8 @@ if 1: # upstream moved WSGIResponse to HTTPResponse.py ...@@ -96,7 +101,8 @@ if 1: # upstream moved WSGIResponse to HTTPResponse.py
if lock: if lock:
self._locked_body = 1 self._locked_body = 1
WSGIResponse.setBody = setBody if not isZope4:
WSGIResponse.setBody = setBody
def write(self, data): def write(self, data):
if not self._streaming: if not self._streaming:
...@@ -411,10 +417,17 @@ def load_app(module_info): ...@@ -411,10 +417,17 @@ def load_app(module_info):
try: try:
yield (app, realm, debug_mode, validated_hook) yield (app, realm, debug_mode, validated_hook)
finally: finally:
if transaction.manager._txn is not None: if isZope4:
# Only abort a transaction, if one exists. Otherwise the if transaction.manager.manager._txn is not None:
# abort creates a new transaction just to abort it. # Only abort a transaction, if one exists. Otherwise the
transaction.abort() # abort creates a new transaction just to abort it.
transaction.abort()
else:
if getattr(transaction.manager, '_txn', None) is not None:
# Only abort a transaction, if one exists. Otherwise the
# abort creates a new transaction just to abort it.
transaction.abort()
app._p_jar.close() app._p_jar.close()
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
from Shared.DC.ZRDB.sqltest import * from Shared.DC.ZRDB.sqltest import *
from Shared.DC.ZRDB import sqltest from Shared.DC.ZRDB import sqltest
from DateTime import DateTime from DateTime import DateTime
from types import StringType
list_type_list = list, tuple, set, frozenset, dict list_type_list = list, tuple, set, frozenset, dict
...@@ -50,7 +51,7 @@ if 1: # For easy diff with original ...@@ -50,7 +51,7 @@ if 1: # For easy diff with original
if type(v) is StringType: if type(v) is StringType:
if v[-1:]=='L': if v[-1:]=='L':
v=v[:-1] v=v[:-1]
atoi(v) int(v)
else: v=str(int(v)) else: v=str(int(v))
except ValueError: except ValueError:
raise ValueError( raise ValueError(
...@@ -58,7 +59,7 @@ if 1: # For easy diff with original ...@@ -58,7 +59,7 @@ if 1: # For easy diff with original
elif t=='float': elif t=='float':
if not v and type(v) is StringType: continue if not v and type(v) is StringType: continue
try: try:
if type(v) is StringType: atof(v) if type(v) is StringType: float(v)
else: v=str(float(v)) else: v=str(float(v))
except ValueError: except ValueError:
raise ValueError( raise ValueError(
...@@ -92,7 +93,7 @@ if 1: # For easy diff with original ...@@ -92,7 +93,7 @@ if 1: # For easy diff with original
'No input was provided for <em>%s</em>' % name) 'No input was provided for <em>%s</em>' % name)
if len(vs) > 1: if len(vs) > 1:
vs=join(map(str,vs),', ') vs = ', '.join(map(str, vs))
if self.op == '<>': if self.op == '<>':
## Do the equivalent of 'not-equal' for a list, ## Do the equivalent of 'not-equal' for a list,
## "a not in (b,c)" ## "a not in (b,c)"
...@@ -103,4 +104,11 @@ if 1: # For easy diff with original ...@@ -103,4 +104,11 @@ if 1: # For easy diff with original
return "%s %s %s" % (self.column, self.op, vs[0]) return "%s %s %s" % (self.column, self.op, vs[0])
SQLTest.render = SQLTest.__call__ = render SQLTest.render = SQLTest.__call__ = render
sqltest.valid_type = (('int', 'float', 'string', 'nb', 'datetime') + tuple('datetime(%s)' % x for x in xrange(7))).__contains__ new_valid_types = (('int', 'float', 'string', 'nb', 'datetime') + tuple('datetime(%s)' % x for x in xrange(7)))
try:
# BBB
from Shared.DC.ZRDB.sqltest import valid_type
sqltest.valid_type = new_valid_types.__contains__
except ImportError:
sqltest.valid_types = new_valid_types
...@@ -83,11 +83,15 @@ def SQLVar_render(self, md): ...@@ -83,11 +83,15 @@ def SQLVar_render(self, md):
% (t, self.__name__, v)) % (t, self.__name__, v))
# Patched by yo. datetime is added. # Patched by yo. datetime is added.
new_valid_types = 'int', 'float', 'string', 'nb', 'datetime'
valid_type = 'int', 'float', 'string', 'nb', 'datetime' new_valid_types += tuple(map('datetime(%s)'.__mod__, xrange(7)))
valid_type += tuple(map('datetime(%s)'.__mod__, xrange(7))) try:
valid_type = valid_type.__contains__ # BBB
from Shared.DC.ZRDB.sqlvar import valid_type
sqlvar.valid_type = new_valid_types.__contains__
except ImportError:
sqlvar.valid_types = new_valid_types
SQLVar.render = SQLVar_render SQLVar.render = SQLVar_render
SQLVar.__call__ = SQLVar_render SQLVar.__call__ = SQLVar_render
sqlvar.valid_type = valid_type
...@@ -141,7 +141,7 @@ class DummyMessageCatalog: ...@@ -141,7 +141,7 @@ class DummyMessageCatalog:
else: else:
return default return default
def translate(self, msgid, mapping=None, context=None, def translate(self, msgid, mapping=None, context=None,
target_language=None, default=None): target_language=None, default=None, *args, **kw):
return default return default
class DummyLocalizer: class DummyLocalizer:
......
...@@ -28,7 +28,7 @@ from ComputedAttribute import ComputedAttribute ...@@ -28,7 +28,7 @@ from ComputedAttribute import ComputedAttribute
# FIXME: manage_renameObject hack needs these imports # FIXME: manage_renameObject hack needs these imports
from Acquisition import aq_base from Acquisition import aq_base
from App.Dialogs import MessageDialog from App.Dialogs import MessageDialog
from OFS.CopySupport import CopyError, eNotSupported from OFS.CopySupport import CopyError
import sys import sys
class Form: class Form:
...@@ -688,7 +688,7 @@ class ZMIForm(ObjectManager, PropertyManager, RoleManager, Item, Form): ...@@ -688,7 +688,7 @@ class ZMIForm(ObjectManager, PropertyManager, RoleManager, Item, Form):
action ='manage_main')) action ='manage_main'))
ob=self._getOb(id) ob=self._getOb(id)
if not ob.cb_isMoveable(): if not ob.cb_isMoveable():
raise CopyError(eNotSupported % id) raise CopyError('Not Supported')
self._verifyObjectPaste(ob) self._verifyObjectPaste(ob)
try: ob._notifyOfCopyTo(self, op=1) try: ob._notifyOfCopyTo(self, op=1)
except: raise CopyError(MessageDialog( except: raise CopyError(MessageDialog(
......
...@@ -244,7 +244,7 @@ class HBTreeFolder2Tests(ERP5TypeTestCase): ...@@ -244,7 +244,7 @@ class HBTreeFolder2Tests(ERP5TypeTestCase):
h = HBTreeFolder2() h = HBTreeFolder2()
# whatever value, as long as it has an __of__ # whatever value, as long as it has an __of__
h._setOb('foo', HBTreeFolder2()) h._setOb('foo', HBTreeFolder2())
script = PythonScript('script') script = PythonScript('test_script')
script.ZPythonScript_edit('h', dedent(""" script.ZPythonScript_edit('h', dedent("""
for dummy in h.objectIds(): for dummy in h.objectIds():
pass pass
......
...@@ -206,7 +206,9 @@ class MessageCatalog(LanguageManager, ObjectManager, SimpleItem): ...@@ -206,7 +206,9 @@ class MessageCatalog(LanguageManager, ObjectManager, SimpleItem):
def translate(self, msgid, mapping=None, context=None, def translate(self, msgid, mapping=None, context=None,
target_language=None, default=None): target_language=None, default=None,
# zope i18n 4.7
msgid_plural=None, default_plural=None, number=None):
""" """ """ """
msgstr = self.gettext(msgid, lang=target_language, default=default) msgstr = self.gettext(msgid, lang=target_language, default=default)
# BBB support str in mapping by converting to unicode for # BBB support str in mapping by converting to unicode for
......
...@@ -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 pname
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 pname(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