Skip to content

Commit

Permalink
- Collector #2061: Fix problems where windows line endings are passed…
Browse files Browse the repository at this point in the history
… to restricted code compilers.
  • Loading branch information
cjw296 committed May 1, 2006
1 parent b21e385 commit 4a92f3b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
4 changes: 4 additions & 0 deletions RCompile.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class RestrictedCompileMode(AbstractCompileMode):
# See concrete subclasses below.

def __init__(self, source, filename):
if source:
source = '\n'.join(source.splitlines())
self.rm = RestrictionMutator()
AbstractCompileMode.__init__(self, source, filename)

Expand Down Expand Up @@ -206,6 +208,8 @@ class RFunction(RModule):

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 []
Expand Down
29 changes: 29 additions & 0 deletions tests/testRestrictions.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,35 @@ def checkSyntaxError(self):
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():
Expand Down

0 comments on commit 4a92f3b

Please sign in to comment.