Commit 8c4be9f6 authored by 's avatar

Added wrapper checking to property management code.

parent afb3a08c
...@@ -84,7 +84,7 @@ ...@@ -84,7 +84,7 @@
############################################################################## ##############################################################################
"""Property management""" """Property management"""
__version__='$Revision: 1.24 $'[11:-2] __version__='$Revision: 1.25 $'[11:-2]
import ExtensionClass, Globals import ExtensionClass, Globals
import ZDOM import ZDOM
...@@ -214,13 +214,24 @@ class PropertyManager(ExtensionClass.Base, ZDOM.ElementWithAttributes): ...@@ -214,13 +214,24 @@ class PropertyManager(ExtensionClass.Base, ZDOM.ElementWithAttributes):
return md.get('type', 'string') return md.get('type', 'string')
return None return None
def _setPropValue(self, id, value): setattr(self,id,value) def _wrapperCheck(self, object):
def _delPropValue(self, id): delattr(self,id) # Raise an error if an object is wrapped.
if hasattr(object, 'aq_base'):
raise ValueError, 'Invalid property value: wrapped object'
return
def _setPropValue(self, id, value):
self._wrapperCheck(value)
setattr(self,id,value)
def _delPropValue(self, id):
delattr(self,id)
def _setProperty(self, id, value, type='string'): def _setProperty(self, id, value, type='string'):
# for selection and multiple selection properties # for selection and multiple selection properties
# the value argument indicates the select variable # the value argument indicates the select variable
# of the property # of the property
self._wrapperCheck(value)
if not self.valid_property_id(id): if not self.valid_property_id(id):
raise 'Bad Request', 'Invalid or duplicate property id' raise 'Bad Request', 'Invalid or duplicate property id'
if type in ('selection', 'multiple selection'): if type in ('selection', 'multiple selection'):
...@@ -240,6 +251,7 @@ class PropertyManager(ExtensionClass.Base, ZDOM.ElementWithAttributes): ...@@ -240,6 +251,7 @@ class PropertyManager(ExtensionClass.Base, ZDOM.ElementWithAttributes):
# Update the value of an existing property. If value # Update the value of an existing property. If value
# is a string, an attempt will be made to convert # is a string, an attempt will be made to convert
# the value to the type of the existing property. # the value to the type of the existing property.
self._wrapperCheck(value)
if not self.hasProperty(id): if not self.hasProperty(id):
raise 'Bad Request', 'The property %s does not exist' % id raise 'Bad Request', 'The property %s does not exist' % id
if type(value)==type(''): if type(value)==type(''):
......
...@@ -84,7 +84,7 @@ ...@@ -84,7 +84,7 @@
############################################################################## ##############################################################################
"""Property sheets""" """Property sheets"""
__version__='$Revision: 1.46 $'[11:-2] __version__='$Revision: 1.47 $'[11:-2]
import time, string, App.Management, Globals import time, string, App.Management, Globals
from ZPublisher.Converters import type_converters from ZPublisher.Converters import type_converters
...@@ -197,10 +197,17 @@ class PropertySheet(Persistent, Implicit): ...@@ -197,10 +197,17 @@ class PropertySheet(Persistent, Implicit):
return getattr(self.v_self(), id) return getattr(self.v_self(), id)
return default return default
def _wrapperCheck(self, object):
# Raise an error if an object is wrapped.
if hasattr(object, 'aq_base'):
raise ValueError, 'Invalid property value: wrapped object'
return
def _setProperty(self, id, value, type='string', meta=None): def _setProperty(self, id, value, type='string', meta=None):
# Set a new property with the given id, value and optional type. # Set a new property with the given id, value and optional type.
# Note that different property sets may support different typing # Note that different property sets may support different typing
# systems. # systems.
self._wrapperCheck(value)
if not self.valid_property_id(id): if not self.valid_property_id(id):
raise 'Bad Request', 'Invalid property id, %s.' % id raise 'Bad Request', 'Invalid property id, %s.' % id
if not self.property_extensible_schema__(): if not self.property_extensible_schema__():
...@@ -230,6 +237,7 @@ class PropertySheet(Persistent, Implicit): ...@@ -230,6 +237,7 @@ class PropertySheet(Persistent, Implicit):
# an attempt will be made to convert the value to the type of the # an attempt will be made to convert the value to the type of the
# existing property. If a mapping containing meta-data is passed, # existing property. If a mapping containing meta-data is passed,
# it will used to _replace_ the properties meta data. # it will used to _replace_ the properties meta data.
self._wrapperCheck(value)
if not self.hasProperty(id): if not self.hasProperty(id):
raise 'Bad Request', 'The property %s does not exist.' % id raise 'Bad Request', 'The property %s does not exist.' % id
propinfo=self.propertyInfo(id) propinfo=self.propertyInfo(id)
......
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