[Zope3-checkins] CVS: Zope3/src/zope/app/schemagen - modulegen.py:1.1.2.2

Tim Peters tim.one@comcast.net
Tue, 24 Dec 2002 21:00:45 -0500


Update of /cvs-repository/Zope3/src/zope/app/schemagen
In directory cvs.zope.org:/tmp/cvs-serv17037/src/zope/app/schemagen

Modified Files:
      Tag: NameGeddon-branch
	modulegen.py 
Log Message:
generateModuleSource():  Normalize the result to contain exactly one
trailing newline.  Else the exact-match tests of this are brittle.


=== Zope3/src/zope/app/schemagen/modulegen.py 1.1.2.1 => 1.1.2.2 ===
--- Zope3/src/zope/app/schemagen/modulegen.py:1.1.2.1	Mon Dec 23 14:32:13 2002
+++ Zope3/src/zope/app/schemagen/modulegen.py	Tue Dec 24 21:00:44 2002
@@ -2,14 +2,14 @@
 #
 # 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$
@@ -27,7 +27,7 @@
         extra_methods = '\n%s' % extra_methods
     if extra_imports:
         extra_imports = '%s\n' % extra_imports
-        
+
     import_list = []
     field_text_list = []
     property_text_list = []
@@ -40,11 +40,11 @@
             field_name, schema_name, field_name))
         for import_entry in r.importList:
             import_list.append("from %s import %s" % import_entry)
-    
+
     import_text = '\n'.join(import_list)
     field_text = '\n'.join(field_text_list)
     property_text = '\n'.join(property_text_list)
-         
+
     text = '''\
 from zope.interface import Interface
 from persistence import Persistent
@@ -56,17 +56,21 @@
 class %(schema_name)s(Interface):
     """Autogenerated schema."""
 %(field_text)s
-    
+
 class %(class_name)s(Persistent):
     """Autogenerated class for %(schema_name)s."""
     __implements__ = %(schema_name)s
 
     def __init__(self):
         self.__schema_version__ = %(schema_version)s
-        
+
 %(property_text)s
 %(extra_methods)s
 ''' % vars()
-    
-    return text
 
+    # Normalize to one trailing newline.  This helps exact-match tests pass.
+    # Since the loop is unlikely to go around more than once, don't bother
+    # with a fancy algorithm.
+    while text.endswith('\n\n'):
+        text = text[:-1]
+    return text