[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/schemagen - modulegen.py:1.3

Martijn Faassen m.faassen@vet.uu.nl
Thu, 12 Dec 2002 12:40:26 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/App/schemagen
In directory cvs.zope.org:/tmp/cvs-serv11012

Modified Files:
	modulegen.py 
Log Message:
Added ability to supply extra imports for the generated module. Also
add ability to supply extra methods for the generated class.


=== Zope3/lib/python/Zope/App/schemagen/modulegen.py 1.2 => 1.3 ===
--- Zope3/lib/python/Zope/App/schemagen/modulegen.py:1.2	Thu Dec 12 07:14:52 2002
+++ Zope3/lib/python/Zope/App/schemagen/modulegen.py	Thu Dec 12 12:40:25 2002
@@ -1,13 +1,33 @@
+##############################################################################
+#
+# Copyright (c) 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+# 
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+# 
+##############################################################################
+"""
+$Id$
+"""
+
 from typereg import fieldRegistry
 
 def generateModuleSource(schema_name, fields, class_name,
-                         schema_history=None):
-    if schema_history is None:
-        schema_version = 0
-    else:
-        # XXX get it from schema history
-        pass
+                         schema_version=0, extra_imports='', extra_methods=''):
+    """Generate module source from schema information.
 
+    extra_methods if supplied needs to be a string with a four space indent.
+    """
+    if extra_methods:
+        extra_methods = '\n%s' % extra_methods
+    if extra_imports:
+        extra_imports = '%s\n' % extra_imports
+        
     import_list = []
     field_text_list = []
     property_text_list = []
@@ -32,7 +52,7 @@
 
 # field imports
 %(import_text)s
-
+%(extra_imports)s
 class %(schema_name)s(Interface):
     """Autogenerated schema."""
 %(field_text)s
@@ -43,8 +63,9 @@
 
     def __init__(self):
         self.__schema_version__ = %(schema_version)s
-
+        
 %(property_text)s
+%(extra_methods)s
 ''' % vars()
     
     return text