[Zope3-checkins] CVS: Zope3/src/zope/app/utilities - schema.py:1.14
Sidnei da Silva
sidnei at x3ng.com.br
Wed Dec 17 16:28:03 EST 2003
Update of /cvs-repository/Zope3/src/zope/app/utilities
In directory cvs.zope.org:/tmp/cvs-serv14741/src/zope/app/utilities
Modified Files:
schema.py
Log Message:
Small refactoring to make it easier to reuse the SchemaUtility on different contexts (like, storing the fields on a RDBMS)
=== Zope3/src/zope/app/utilities/schema.py 1.13 => 1.14 ===
--- Zope3/src/zope/app/utilities/schema.py:1.13 Tue Dec 16 05:32:06 2003
+++ Zope3/src/zope/app/utilities/schema.py Wed Dec 17 16:27:32 2003
@@ -40,7 +40,7 @@
from zope.interface.interface import InterfaceClass
from zope.interface.exceptions import InvalidInterface
-class SchemaUtility(PersistentInterfaceClass, Contained):
+class BaseSchemaUtility(InterfaceClass):
implements(IMutableSchema, ISchemaUtility)
@@ -48,10 +48,13 @@
__doc__=None, __module__=None):
if not bases:
bases = (Interface,)
- super(SchemaUtility, self).__init__(name, bases,
+ super(BaseSchemaUtility, self).__init__(name, bases,
attrs, __doc__, __module__)
- self.schemaPermissions = PersistentDict()
- self._attrs = PersistentDict()
+ self._clear()
+
+ def _clear(self):
+ self.schemaPermissions = {}
+ self._attrs = {}
def setName(self, name):
"""See zope.app.interfaces.utilities.IMutableSchema"""
@@ -84,6 +87,7 @@
raise KeyError, "Field %s already exists." % target_name
field = self[orig_name]
del self[orig_name]
+ field.__name__ = None
self[target_name] = field
def insertField(self, name, field, position):
@@ -96,10 +100,10 @@
if not 0 <= position <= len(field_names):
raise IndexError, "Position %s out of range." % position
fields.insert(position, field)
- self[name] = field
for p, f in enumerate(fields):
if not f.order == p:
f.order = p
+ self[name] = field
def moveField(self, name, position):
"""See zope.app.interfaces.utilities.IMutableSchema"""
@@ -134,9 +138,6 @@
else:
raise InvalidInterface("Concrete attribute, %s" % name)
- if not isinstance(value, Persistent):
- value = Struct(value)
-
setitem(self, self._attrs.__setitem__, name, value)
# Methods copied from zope.interface.interface.InterfaceClass,
@@ -229,6 +230,27 @@
dict[k]=v
for b in self.getBases(): b.__d(dict)
+
+class StructPersistentDict(PersistentDict):
+
+ def __setitem__(self, name, value):
+ if not isinstance(value, Persistent):
+ value = Struct(value)
+ return super(StructPersistentDict, self).__setitem__(name, value)
+
+class SchemaUtility(BaseSchemaUtility, PersistentInterfaceClass, Contained):
+
+ def __init__(self, name='', bases=(), attrs=None,
+ __doc__=None, __module__=None):
+ if not bases:
+ bases = (Interface,)
+ PersistentInterfaceClass.__init__(self, name, bases,
+ attrs, __doc__, __module__)
+ self._clear()
+
+ def _clear(self):
+ self.schemaPermissions = PersistentDict()
+ self._attrs = StructPersistentDict()
class SchemaAdding(Adding):
More information about the Zope3-Checkins
mailing list