fixed 1843, commented functions should not appear as if they are exposed
This commit is contained in:
+6
-3
@@ -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,
|
||||
|
||||
@@ -21,6 +21,8 @@ regex_expose = re.compile(
|
||||
'^def\s+(?P<name>_?[a-zA-Z0-9]\w*)\( *\)\s*:',
|
||||
flags=re.M)
|
||||
|
||||
regex_longcomments = re.compile('(""".*?"""|'+"'''.*?''')",re.DOTALL)
|
||||
|
||||
regex_include = re.compile(
|
||||
'(?P<all>\{\{\s*include\s+[\'"](?P<name>[^\'"]*)[\'"]\s*\}\})')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user