[Zope-CVS] CVS: Products/Ape/lib/apelib/core - interfaces.py:1.15.2.1 schemas.py:1.6.2.1 serializers.py:1.6.2.1

Shane Hathaway shane at zope.com
Tue Jul 20 22:26:28 EDT 2004


Update of /cvs-repository/Products/Ape/lib/apelib/core
In directory cvs.zope.org:/tmp/cvs-serv32139/core

Modified Files:
      Tag: sql-types-branch
	interfaces.py schemas.py serializers.py 
Log Message:
Checkpoint.  Started using common schemas for table specifications.

Renamed FieldSchema to ColumnSchema and got rid of RowSchema.  The new
names are less abstract.  This should make them easier to understand.


=== Products/Ape/lib/apelib/core/interfaces.py 1.15 => 1.15.2.1 ===
--- Products/Ape/lib/apelib/core/interfaces.py:1.15	Fri Mar 26 11:07:59 2004
+++ Products/Ape/lib/apelib/core/interfaces.py	Tue Jul 20 22:25:58 2004
@@ -535,3 +535,16 @@
         mapping containing only the items of the input dictionary
         whose state has changed.
         """
+
+
+class IColumnSchema (Interface):
+    """A column in a table."""
+
+    name = Attribute(
+        "name", "The column name")
+
+    type = Attribute(
+        "type", "The type of data held in the column, as a string")
+
+    unique = Attribute(
+        "unique", "True if the column is part of the primary key")


=== Products/Ape/lib/apelib/core/schemas.py 1.6 => 1.6.2.1 ===
--- Products/Ape/lib/apelib/core/schemas.py:1.6	Sat Mar 20 01:34:22 2004
+++ Products/Ape/lib/apelib/core/schemas.py	Tue Jul 20 22:25:58 2004
@@ -18,20 +18,25 @@
 
 from types import StringType
 
-ok_types = ['unicode', 'string', 'int', 'float', 'bool', 'object',
-            'classification', 'string:list', 'blob']
+from interfaces import IColumnSchema
 
+ok_types = [
+    'unicode', 'string', 'int', 'float', 'bool', 'object',
+    'classification', 'string:list', 'blob',
+    ]
 
-def add_field_type(t):
-    """Adds an allowable field type."""
+
+def add_column_type(t):
+    """Adds an allowable column type."""
     assert isinstance(t, StringType)
     if t not in ok_types:
         ok_types.append(t)
 
 
-class FieldSchema:
-    """Defines the schema of one field."""
-#    __implements__ = IRelationalSchema
+class ColumnSchema:
+    """Defines the schema of one column."""
+
+    __implements__ = IColumnSchema
 
     def __init__(self, name, type='string', unique=0):
         assert type in ok_types, type
@@ -39,8 +44,8 @@
         self.type = type
         self.unique = not not unique
 
-    def get_column_defs(self):
-        return [(self.name, self.type, self.unique)]
+    def get_columns(self):
+        return [self]
 
     def __eq__(self, other):
         if isinstance(other, self.__class__):
@@ -53,63 +58,44 @@
         return not self.__eq__(other)
 
     def __repr__(self):
-        return 'FieldSchema(%s, %s, %s)' % (
+        return 'ColumnSchema(%s, %s, %s)' % (
             repr(self.name), repr(self.type), repr(self.unique))
 
+# b/w compat.
+FieldSchema = ColumnSchema
 
-class RowSchema:
-    """Defines an ordered set of fields for exactly one row.
-    """
-#    __implements__ = IRelationalSchema
 
-    def __init__(self, fields=()):
-        self.fields = []
-        self.field_names = {}
-        for c in fields:
+class RowSequenceSchema:
+    """Defines a schema for a sequence of rows, including row count limits.
+    """
+    def __init__(self, columns=(), min_rows=0, max_rows=0):
+        # max_rows == 0 means unlimited.
+        assert (max_rows == 0 or max_rows >= min_rows)
+        self.min_rows = min_rows
+        self.max_rows = max_rows
+        self.columns = []
+        self.column_names = {}
+        for c in columns:
             self._add(c)
 
-    def get_column_defs(self):
+    def get_columns(self):
         res = []
-        for f in self.fields:
-            res.extend(f.get_column_defs())
-        return tuple(res)
+        for f in self.columns:
+            res.extend(f.get_columns())
+        return res
 
     def _add(self, c):
-        if self.field_names.has_key(c.name):
-            raise KeyError, 'Duplicate field name: %s' % c.name
-        self.field_names[c.name] = 1
-        self.fields.append(c)
+        if self.column_names.has_key(c.name):
+            raise KeyError, 'Duplicate column name: %s' % c.name
+        self.column_names[c.name] = 1
+        self.columns.append(c)
 
     def add(self, name, type='string', unique=0):
-        self._add(FieldSchema(name, type, unique))
+        self._add(ColumnSchema(name, type, unique))
 
     def __eq__(self, other):
         if isinstance(other, self.__class__):
-            if (self.fields == other.fields):
-                return 1  # Same
-        return 0  # Different
-
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __repr__(self):
-        return 'RowSchema(%s)' % repr(self.fields)
-
-
-class RowSequenceSchema (RowSchema):
-    """Defines a schema for a sequence of rows, including row count limits.
-    """
-
-    def __init__(self, fields=(), min_rows=0, max_rows=0):
-        # max_rows == 0 means unlimited.
-        assert (max_rows == 0 or max_rows >= min_rows)
-        RowSchema.__init__(self, fields)
-        self.min_rows = min_rows
-        self.max_rows = max_rows
-
-    def __eq__(self, other):
-        if isinstance(other, self.__class__):
-            if (self.fields == other.fields) and (
+            if (self.columns == other.columns) and (
                 self.min_rows == other.min_rows) and (
                 self.max_rows == other.max_rows):
                 return 1  # Same
@@ -120,5 +106,4 @@
 
     def __repr__(self):
         return 'RowSequenceSchema(%s, min_rows=%s, max_rows=%s)' % (
-            repr(self.fields), repr(self.min_rows), repr(self.max_rows))
-
+            repr(self.columns), repr(self.min_rows), repr(self.max_rows))


=== Products/Ape/lib/apelib/core/serializers.py 1.6 => 1.6.2.1 ===
--- Products/Ape/lib/apelib/core/serializers.py:1.6	Sat Mar 20 01:34:22 2004
+++ Products/Ape/lib/apelib/core/serializers.py	Tue Jul 20 22:25:58 2004
@@ -20,7 +20,7 @@
 
 from interfaces import ISerializer, IFullObjectSerializer
 from interfaces import DeserializationError, SerializationError
-from schemas import FieldSchema
+from schemas import ColumnSchema
 
 
 class CompositeSerializer:
@@ -139,7 +139,7 @@
 
     __implements__ = ISerializer
 
-    schema = FieldSchema('data', 'object')
+    schema = ColumnSchema('data', 'object')
 
     def can_serialize(self, obj):
         return 1
@@ -208,7 +208,7 @@
 
     __implements__ = ISerializer
 
-    schema = FieldSchema('data', 'string')
+    schema = ColumnSchema('data', 'string')
 
     def __init__(self, attrname):
         self.attrname = attrname



More information about the Zope-CVS mailing list