[Zope-Checkins] SVN: Zope/trunk/ - Collector #2061: Fix problems where windows line endings are passed to restricted code compilers.

Chris Withers chris at simplistix.co.uk
Mon May 1 05:47:47 EDT 2006


Log message for revision 67783:
  - Collector #2061: Fix problems where windows line endings are passed to restricted code compilers.
  
  
  

Changed:
  U   Zope/trunk/doc/CHANGES.txt
  U   Zope/trunk/lib/python/RestrictedPython/RCompile.py
  U   Zope/trunk/lib/python/RestrictedPython/tests/testRestrictions.py

-=-
Modified: Zope/trunk/doc/CHANGES.txt
===================================================================
--- Zope/trunk/doc/CHANGES.txt	2006-05-01 09:45:26 UTC (rev 67782)
+++ Zope/trunk/doc/CHANGES.txt	2006-05-01 09:47:46 UTC (rev 67783)
@@ -219,6 +219,9 @@
 
     Bugs Fixed
 
+      - Collector #2061: Fix problems where windows line endings are passed
+        to restricted code compilers.
+
       - Collector #2051: Applied patch by Yoshinori Okuji to fix some
         XML export/import problems, including tests for that feature.
 

Modified: Zope/trunk/lib/python/RestrictedPython/RCompile.py
===================================================================
--- Zope/trunk/lib/python/RestrictedPython/RCompile.py	2006-05-01 09:45:26 UTC (rev 67782)
+++ Zope/trunk/lib/python/RestrictedPython/RCompile.py	2006-05-01 09:47:46 UTC (rev 67783)
@@ -42,6 +42,8 @@
     # See concrete subclasses below.
 
     def __init__(self, source, filename):
+        if source:
+            source = '\n'.join(source.splitlines())
         self.rm = RestrictionMutator()
         AbstractCompileMode.__init__(self, source, filename)
 
@@ -206,6 +208,8 @@
 
     def __init__(self, p, body, name, filename, globals):
         self.params = p
+        if body:
+            body = '\n'.join(body.splitlines())
         self.body = body
         self.name = name
         self.globals = globals or []

Modified: Zope/trunk/lib/python/RestrictedPython/tests/testRestrictions.py
===================================================================
--- Zope/trunk/lib/python/RestrictedPython/tests/testRestrictions.py	2006-05-01 09:45:26 UTC (rev 67782)
+++ Zope/trunk/lib/python/RestrictedPython/tests/testRestrictions.py	2006-05-01 09:47:46 UTC (rev 67783)
@@ -499,6 +499,35 @@
         self.assertRaises(SyntaxError,
                           compile_restricted, err, "<string>", "exec")
 
+    # these two tests check that source code with Windows line
+    # endings still works.
+
+    def checkLineEndingsRFunction(self):
+        from RestrictedPython.RCompile import RFunction
+        gen = RFunction(
+            p='',
+            body='# testing\r\nprint "testing"\r\nreturn printed\n',
+            name='test',
+            filename='<test>',
+            globals=(),
+            )
+        gen.mode = 'exec'
+        # if the source has any line ending other than \n by the time
+        # parse() is called, then you'll get a syntax error.
+        gen.parse()
+
+    def checkLineEndingsRestrictedCompileMode(self):
+        from RestrictedPython.RCompile import RestrictedCompileMode
+        gen = RestrictedCompileMode(
+            '# testing\r\nprint "testing"\r\nreturn printed\n',
+            '<testing>'
+            )
+        gen.mode='exec'
+        # if the source has any line ending other than \n by the time
+        # parse() is called, then you'll get a syntax error.
+        gen.parse()
+
+        
 create_rmodule()
 
 def test_suite():



More information about the Zope-Checkins mailing list