Skip to content

Commit

Permalink
Revert "Python3 update"
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Howitz committed Oct 25, 2016
1 parent dac38ad commit 01598c5
Show file tree
Hide file tree
Showing 13 changed files with 9 additions and 1,502 deletions.
1 change: 1 addition & 0 deletions pytest.ini
Expand Up @@ -2,5 +2,6 @@
addopts =
testpaths = tests src/RestrictedPython/tests
norecursedirs = fixures

isort_ignore =
bootstrap.py
16 changes: 2 additions & 14 deletions src/RestrictedPython/test_helper.py
Expand Up @@ -22,7 +22,6 @@
"""

import dis
import sys
import types

from dis import findlinestarts
Expand Down Expand Up @@ -136,34 +135,23 @@ def __init__(self, opcode, pos):


def _disassemble(co, lasti=-1):
# in py2 code is str
code = co.co_code
#in py3 code is bytes
#if sys.version_info.major > 2:
# code = code.decode()
labels = dis.findlabels(code)
linestarts = dict(findlinestarts(co))
n = len(code)
i = 0
extended_arg = 0
free = co.co_cellvars + co.co_freevars
while i < n:
if sys.version_info.major < 3:
op = ord(code[i])
else:
op = code[i]
op = ord(code[i])
o = Op(op, i)
i += 1
if i in linestarts and i > 0:
o.line = linestarts[i]
if i in labels:
o.target = True
if op > dis.HAVE_ARGUMENT:
if sys.version_info.major < 3:
arg = ord(code[i]) + ord(code[i + 1]) * 256 + extended_arg
else:
arg = code[i] + code[i + 1] * 256 + extended_arg

arg = ord(code[i]) + ord(code[i + 1]) * 256 + extended_arg
extended_arg = 0
i += 2
if op == dis.EXTENDED_ARG:
Expand Down
37 changes: 0 additions & 37 deletions src/RestrictedPython/tests/security_in_syntax.py
Expand Up @@ -87,40 +87,3 @@ def no_augmeneted_assignment_to_slice():

def no_augmeneted_assignment_to_slice2():
a[x:y:z] += c

# These are all supposed to raise a SyntaxError when using
# compile_restricted() but not when using compile().
# Each function in this module is compiled using compile_restricted().


def with_as_bad_name():
with x as _leading_underscore:
pass


def relative_import_as_bad_name():
from .x import y as _leading_underscore


def except_as_bad_name():
try:
1 / 0
except Exception as _leading_underscore:
pass

# These are all supposed to raise a SyntaxError when using
# compile_restricted() but not when using compile().
# Each function in this module is compiled using compile_restricted().


def dict_comp_bad_name():
{y: y for _restricted_name in x}


def set_comp_bad_name():
{y for _restricted_name in x}


def compound_with_bad_name():
with a as b, c as _restricted_name:
pass
10 changes: 4 additions & 6 deletions src/RestrictedPython/transformer.py
Expand Up @@ -123,7 +123,7 @@
#ast.Nonlocal,
ast.ClassDef,
ast.Module,
ast.Param,
ast.Param
]


Expand Down Expand Up @@ -158,9 +158,7 @@
ast.Bytes,
ast.Starred,
ast.arg,
ast.Try, # Try should not be supported
ast.TryExcept, # TryExcept should not be supported
ast.NameConstant
#ast.Try, # Try should not be supported
])

if version >= (3, 4):
Expand Down Expand Up @@ -324,8 +322,8 @@ def check_name(self, node, name):
self.error(node, '"%s" is an invalid variable name because '
'it ends with "__roles__".' % name)

# elif name == "printed":
# self.error(node, '"printed" is a reserved name.')
elif name == "printed":
self.error(node, '"printed" is a reserved name.')

def transform_tuple_unpack(self, root, src, to_wrap=None):
"""Protects tuple unpacking with _getiter_
Expand Down
13 changes: 0 additions & 13 deletions tests/fixtures/class.py

This file was deleted.

5 changes: 0 additions & 5 deletions tests/fixtures/lambda.py

This file was deleted.

210 changes: 0 additions & 210 deletions tests/fixtures/restricted_module.py

This file was deleted.

0 comments on commit 01598c5

Please sign in to comment.