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

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

-=-
Modified: Zope/branches/2.9/doc/CHANGES.txt
===================================================================
--- Zope/branches/2.9/doc/CHANGES.txt   2006-05-01 07:46:45 UTC (rev 67781)
+++ Zope/branches/2.9/doc/CHANGES.txt   2006-05-01 09:45:26 UTC (rev 67782)
@@ -18,6 +18,9 @@
 
    Bugs fixed
 
+      - Collector #2061: Fix problems where windows line endings are passed
+        to restricted code compilers.
+
       - Collector #2072: Applied patch to fix problem with overly restrictive
         __bobo_traverse__ security and tests.
       

Modified: Zope/branches/2.9/lib/python/RestrictedPython/RCompile.py
===================================================================
--- Zope/branches/2.9/lib/python/RestrictedPython/RCompile.py   2006-05-01 
07:46:45 UTC (rev 67781)
+++ Zope/branches/2.9/lib/python/RestrictedPython/RCompile.py   2006-05-01 
09:45:26 UTC (rev 67782)
@@ -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/branches/2.9/lib/python/RestrictedPython/tests/testRestrictions.py
===================================================================
--- Zope/branches/2.9/lib/python/RestrictedPython/tests/testRestrictions.py     
2006-05-01 07:46:45 UTC (rev 67781)
+++ Zope/branches/2.9/lib/python/RestrictedPython/tests/testRestrictions.py     
2006-05-01 09:45:26 UTC (rev 67782)
@@ -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():

_______________________________________________
Zope-Checkins maillist  -  Zope-Checkins@zope.org
http://mail.zope.org/mailman/listinfo/zope-checkins

Reply via email to