From 6bbafc5920a5d140d714a38726b3f9be1a3236ba Mon Sep 17 00:00:00 2001 From: mdipierro Date: Wed, 8 Jan 2014 11:32:07 -0600 Subject: [PATCH] fixed 1843, commented functions should not appear as if they are exposed --- VERSION | 2 +- applications/admin/controllers/default.py | 7 ++++--- gluon/compileapp.py | 9 ++++++--- gluon/myregex.py | 2 ++ 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/VERSION b/VERSION index 1c362945..fd524df8 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -Version 2.8.2-stable+timestamp.2014.01.08.11.15.41 +Version 2.8.2-stable+timestamp.2014.01.08.11.31.12 diff --git a/applications/admin/controllers/default.py b/applications/admin/controllers/default.py index 1cebd27a..ef7bca33 100644 --- a/applications/admin/controllers/default.py +++ b/applications/admin/controllers/default.py @@ -13,6 +13,7 @@ from gluon.admin import * from gluon.fileutils import abspath, read_file, write_file from gluon.utils import web2py_uuid from gluon.tools import Config +from gluon.compileapp import find_exposed_functions from glob import glob import shutil import platform @@ -752,7 +753,7 @@ def edit(): if len(request.args) > 2 and request.args[1] == 'controllers': controller = (request.args[2])[:-3] - functions = regex_expose.findall(data) + functions = find_exposed_functions(data) else: (controller, functions) = (None, None) @@ -1065,7 +1066,7 @@ def design(): functions = {} for c in controllers: data = safe_read(apath('%s/controllers/%s' % (app, c), r=request)) - items = regex_expose.findall(data) + items = find_exposed_functions(data) functions[c] = items # Get all views @@ -1203,7 +1204,7 @@ def plugin(): functions = {} for c in controllers: data = safe_read(apath('%s/controllers/%s' % (app, c), r=request)) - items = regex_expose.findall(data) + items = find_exposed_functions(data) functions[c] = items # Get all views diff --git a/gluon/compileapp.py b/gluon/compileapp.py index cec75ea2..101e45ab 100644 --- a/gluon/compileapp.py +++ b/gluon/compileapp.py @@ -22,7 +22,7 @@ from gluon.storage import Storage, List from gluon.template import parse_template from gluon.restricted import restricted, compile2 from gluon.fileutils import mktree, listdir, read_file, write_file -from gluon.myregex import regex_expose +from gluon.myregex import regex_expose, regex_longcomments from gluon.languages import translator from gluon.dal import BaseAdapter, SQLDB, SQLField, DAL, Field from gluon.sqlhtml import SQLFORM, SQLTABLE @@ -481,6 +481,9 @@ def compile_models(folder): save_pyc(filename) os.unlink(filename) +def find_exposed_functions(data): + data = regex_longcomments.sub('',data) + return regex_expose.findall(data) def compile_controllers(folder): """ @@ -491,7 +494,7 @@ def compile_controllers(folder): for fname in listdir(path, '.+\.py$'): ### why is this here? save_pyc(pjoin(path, file)) data = read_file(pjoin(path, fname)) - exposed = regex_expose.findall(data) + exposed = find_exposed_functions(data) for function in exposed: command = data + "\nresponse._vars=response._caller(%s)\n" % \ function @@ -602,7 +605,7 @@ def run_controller_in(controller, function, environment): rewrite.THREAD_LOCAL.routes.error_message % badc, web2py_error=badc) code = read_file(filename) - exposed = regex_expose.findall(code) + exposed = find_exposed_functions(code) if not function in exposed: raise HTTP(404, rewrite.THREAD_LOCAL.routes.error_message % badf, diff --git a/gluon/myregex.py b/gluon/myregex.py index 15e7ff6b..ac1b2009 100644 --- a/gluon/myregex.py +++ b/gluon/myregex.py @@ -21,6 +21,8 @@ regex_expose = re.compile( '^def\s+(?P_?[a-zA-Z0-9]\w*)\( *\)\s*:', flags=re.M) +regex_longcomments = re.compile('(""".*?"""|'+"'''.*?''')",re.DOTALL) + regex_include = re.compile( '(?P\{\{\s*include\s+[\'"](?P[^\'"]*)[\'"]\s*\}\})')