Removed unnecessary version checks
Fixed 2 memory leaks in restricted.py
This commit is contained in:
+2
-3
@@ -79,15 +79,14 @@ alert_dependency = ['hashlib', 'uuid']
|
|||||||
# python version.
|
# python version.
|
||||||
#
|
#
|
||||||
# List of modules deprecated in Python 2.6 or 2.7 that are in the above set
|
# 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 = ['mhlib', 'multifile', 'mimify', 'sets', 'MimeWriter'] # And ['optparse'] but we need it for now
|
||||||
py27_deprecated = [] # ['optparse'] but we need it for now
|
|
||||||
|
|
||||||
if python_version >= '2.6':
|
if python_version >= '2.6':
|
||||||
base_modules += ['json', 'multiprocessing']
|
base_modules += ['json', 'multiprocessing']
|
||||||
base_modules = list(set(base_modules).difference(set(py26_deprecated)))
|
base_modules = list(set(base_modules).difference(set(py26_deprecated)))
|
||||||
|
|
||||||
if python_version >= '2.7':
|
if python_version >= '2.7':
|
||||||
base_modules += ['argparse']
|
base_modules += ['argparse', 'json', 'multiprocessing']
|
||||||
base_modules = list(set(base_modules).difference(set(py27_deprecated)))
|
base_modules = list(set(base_modules).difference(set(py27_deprecated)))
|
||||||
|
|
||||||
# Now iterate in the base_modules, trying to do the import
|
# Now iterate in the base_modules, trying to do the import
|
||||||
|
|||||||
+4
-4
@@ -236,6 +236,7 @@ def restricted(code, environment=None, layer='Unknown'):
|
|||||||
# XXX Show exception in Wing IDE if running in debugger
|
# XXX Show exception in Wing IDE if running in debugger
|
||||||
if __debug__ and 'WINGDB_ACTIVE' in os.environ:
|
if __debug__ and 'WINGDB_ACTIVE' in os.environ:
|
||||||
sys.excepthook(etype, evalue, tb)
|
sys.excepthook(etype, evalue, tb)
|
||||||
|
del tb
|
||||||
output = "%s %s" % (etype, evalue)
|
output = "%s %s" % (etype, evalue)
|
||||||
raise RestrictedError(layer, code, output, environment)
|
raise RestrictedError(layer, code, output, environment)
|
||||||
|
|
||||||
@@ -261,6 +262,7 @@ def snapshot(info=None, context=5, code=None, environment=None):
|
|||||||
|
|
||||||
# start to process frames
|
# start to process frames
|
||||||
records = inspect.getinnerframes(etb, context)
|
records = inspect.getinnerframes(etb, context)
|
||||||
|
del etb # Prevent circular references that would cause memory leaks
|
||||||
s['frames'] = []
|
s['frames'] = []
|
||||||
for frame, file, lnum, func, lines, index in records:
|
for frame, file, lnum, func, lines, index in records:
|
||||||
file = file and os.path.abspath(file) or '?'
|
file = file and os.path.abspath(file) or '?'
|
||||||
@@ -319,10 +321,8 @@ def snapshot(info=None, context=5, code=None, environment=None):
|
|||||||
s['exception'] = {}
|
s['exception'] = {}
|
||||||
if isinstance(evalue, BaseException):
|
if isinstance(evalue, BaseException):
|
||||||
for name in dir(evalue):
|
for name in dir(evalue):
|
||||||
# prevent py26 DeprecatedWarning:
|
value = pydoc.text.repr(getattr(evalue, name))
|
||||||
if name != 'message' or sys.version_info < (2.6):
|
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
|
# add all local values (of last frame) to the snapshot
|
||||||
s['locals'] = {}
|
s['locals'] = {}
|
||||||
|
|||||||
@@ -6,10 +6,7 @@
|
|||||||
"""
|
"""
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
if sys.version < "2.7":
|
import unittest
|
||||||
import unittest2 as unittest
|
|
||||||
else:
|
|
||||||
import unittest
|
|
||||||
|
|
||||||
from fix_path import fix_sys_path
|
from fix_path import fix_sys_path
|
||||||
|
|
||||||
|
|||||||
@@ -8,10 +8,7 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
import smtplib
|
import smtplib
|
||||||
import datetime
|
import datetime
|
||||||
if sys.version < "2.7":
|
import unittest
|
||||||
import unittest2 as unittest
|
|
||||||
else:
|
|
||||||
import unittest
|
|
||||||
|
|
||||||
from fix_path import fix_sys_path
|
from fix_path import fix_sys_path
|
||||||
|
|
||||||
|
|||||||
+2
-22
@@ -5,10 +5,7 @@
|
|||||||
"""
|
"""
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
if sys.version_info < (2, 7):
|
import unittest
|
||||||
import unittest2 as unittest
|
|
||||||
else:
|
|
||||||
import unittest
|
|
||||||
import subprocess
|
import subprocess
|
||||||
import time
|
import time
|
||||||
import signal
|
import signal
|
||||||
@@ -48,27 +45,10 @@ def startwebserver():
|
|||||||
print ''
|
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():
|
def stopwebserver():
|
||||||
global webserverprocess
|
global webserverprocess
|
||||||
print 'Killing webserver'
|
print 'Killing webserver'
|
||||||
if sys.version_info < (2, 6):
|
webserverprocess.terminate()
|
||||||
terminate_process(webserverprocess.pid)
|
|
||||||
else:
|
|
||||||
webserverprocess.terminate()
|
|
||||||
|
|
||||||
|
|
||||||
class LiveTest(unittest.TestCase):
|
class LiveTest(unittest.TestCase):
|
||||||
|
|||||||
+3
-6
@@ -41,8 +41,8 @@ ProgramInfo = '''%s
|
|||||||
%s
|
%s
|
||||||
%s''' % (ProgramName, ProgramAuthor, ProgramVersion)
|
%s''' % (ProgramName, ProgramAuthor, ProgramVersion)
|
||||||
|
|
||||||
if not sys.version[:3] in ['2.6', '2.7']:
|
if not sys.version[:3] in ['2.7']:
|
||||||
msg = 'Warning: web2py requires Python 2.6 or 2.7 but you are running:\n%s'
|
msg = 'Warning: web2py requires Python 2.7 but you are running:\n%s'
|
||||||
msg = msg % sys.version
|
msg = msg % sys.version
|
||||||
sys.stderr.write(msg)
|
sys.stderr.write(msg)
|
||||||
|
|
||||||
@@ -57,10 +57,7 @@ def run_system_tests(options):
|
|||||||
major_version = sys.version_info[0]
|
major_version = sys.version_info[0]
|
||||||
minor_version = sys.version_info[1]
|
minor_version = sys.version_info[1]
|
||||||
if major_version == 2:
|
if major_version == 2:
|
||||||
if minor_version in (6,):
|
if minor_version in (7,):
|
||||||
sys.stderr.write('Python 2.6\n')
|
|
||||||
ret = subprocess.call(['unit2', '-v', 'gluon.tests'])
|
|
||||||
elif minor_version in (7,):
|
|
||||||
call_args = [sys.executable, '-m', 'unittest', '-v', 'gluon.tests']
|
call_args = [sys.executable, '-m', 'unittest', '-v', 'gluon.tests']
|
||||||
if options.with_coverage:
|
if options.with_coverage:
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user