Removed unnecessary version checks

Fixed 2 memory leaks in restricted.py
This commit is contained in:
Leonel Câmara
2016-05-19 19:03:54 +01:00
parent 56b29553c5
commit 180ebcd7f1
6 changed files with 13 additions and 43 deletions
+2 -3
View File
@@ -79,15 +79,14 @@ alert_dependency = ['hashlib', 'uuid']
# python version.
#
# List of modules deprecated in Python 2.6 or 2.7 that are in the above set
py26_deprecated = ['mhlib', 'multifile', 'mimify', 'sets', 'MimeWriter']
py27_deprecated = [] # ['optparse'] but we need it for now
py27_deprecated = ['mhlib', 'multifile', 'mimify', 'sets', 'MimeWriter'] # And ['optparse'] but we need it for now
if python_version >= '2.6':
base_modules += ['json', 'multiprocessing']
base_modules = list(set(base_modules).difference(set(py26_deprecated)))
if python_version >= '2.7':
base_modules += ['argparse']
base_modules += ['argparse', 'json', 'multiprocessing']
base_modules = list(set(base_modules).difference(set(py27_deprecated)))
# Now iterate in the base_modules, trying to do the import
+4 -4
View File
@@ -236,6 +236,7 @@ def restricted(code, environment=None, layer='Unknown'):
# XXX Show exception in Wing IDE if running in debugger
if __debug__ and 'WINGDB_ACTIVE' in os.environ:
sys.excepthook(etype, evalue, tb)
del tb
output = "%s %s" % (etype, evalue)
raise RestrictedError(layer, code, output, environment)
@@ -261,6 +262,7 @@ def snapshot(info=None, context=5, code=None, environment=None):
# start to process frames
records = inspect.getinnerframes(etb, context)
del etb # Prevent circular references that would cause memory leaks
s['frames'] = []
for frame, file, lnum, func, lines, index in records:
file = file and os.path.abspath(file) or '?'
@@ -319,10 +321,8 @@ def snapshot(info=None, context=5, code=None, environment=None):
s['exception'] = {}
if isinstance(evalue, BaseException):
for name in dir(evalue):
# prevent py26 DeprecatedWarning:
if name != 'message' or sys.version_info < (2.6):
value = pydoc.text.repr(getattr(evalue, name))
s['exception'][name] = value
value = pydoc.text.repr(getattr(evalue, name))
s['exception'][name] = value
# add all local values (of last frame) to the snapshot
s['locals'] = {}
+1 -4
View File
@@ -6,10 +6,7 @@
"""
import os
import sys
if sys.version < "2.7":
import unittest2 as unittest
else:
import unittest
import unittest
from fix_path import fix_sys_path
+1 -4
View File
@@ -8,10 +8,7 @@ import os
import sys
import smtplib
import datetime
if sys.version < "2.7":
import unittest2 as unittest
else:
import unittest
import unittest
from fix_path import fix_sys_path
+2 -22
View File
@@ -5,10 +5,7 @@
"""
import sys
import os
if sys.version_info < (2, 7):
import unittest2 as unittest
else:
import unittest
import unittest
import subprocess
import time
import signal
@@ -48,27 +45,10 @@ def startwebserver():
print ''
def terminate_process(pid):
# Taken from http://stackoverflow.com/questions/1064335/in-python-2-5-how-do-i-kill-a-subprocess
# all this **blah** is because we are stuck with Python 2.5 and \
# we cannot use Popen.terminate()
if sys.platform.startswith('win'):
import ctypes
PROCESS_TERMINATE = 1
handle = ctypes.windll.kernel32.OpenProcess(PROCESS_TERMINATE, False, pid)
ctypes.windll.kernel32.TerminateProcess(handle, -1)
ctypes.windll.kernel32.CloseHandle(handle)
else:
os.kill(pid, signal.SIGKILL)
def stopwebserver():
global webserverprocess
print 'Killing webserver'
if sys.version_info < (2, 6):
terminate_process(webserverprocess.pid)
else:
webserverprocess.terminate()
webserverprocess.terminate()
class LiveTest(unittest.TestCase):
+3 -6
View File
@@ -41,8 +41,8 @@ ProgramInfo = '''%s
%s
%s''' % (ProgramName, ProgramAuthor, ProgramVersion)
if not sys.version[:3] in ['2.6', '2.7']:
msg = 'Warning: web2py requires Python 2.6 or 2.7 but you are running:\n%s'
if not sys.version[:3] in ['2.7']:
msg = 'Warning: web2py requires Python 2.7 but you are running:\n%s'
msg = msg % sys.version
sys.stderr.write(msg)
@@ -57,10 +57,7 @@ def run_system_tests(options):
major_version = sys.version_info[0]
minor_version = sys.version_info[1]
if major_version == 2:
if minor_version in (6,):
sys.stderr.write('Python 2.6\n')
ret = subprocess.call(['unit2', '-v', 'gluon.tests'])
elif minor_version in (7,):
if minor_version in (7,):
call_args = [sys.executable, '-m', 'unittest', '-v', 'gluon.tests']
if options.with_coverage:
try: