Merge pull request #2166 from leonelcamara/revert-2145-expose
Revert "don't use a regex to find exposed functions"
This commit is contained in:
+3
-3
@@ -23,6 +23,7 @@ from gluon.storage import Storage, List
|
|||||||
from gluon.template import parse_template
|
from gluon.template import parse_template
|
||||||
from gluon.restricted import restricted, compile2
|
from gluon.restricted import restricted, compile2
|
||||||
from gluon.fileutils import mktree, listdir, read_file, write_file
|
from gluon.fileutils import mktree, listdir, read_file, write_file
|
||||||
|
from gluon.myregex import regex_expose, regex_longcomments
|
||||||
from gluon.languages import TranslatorFactory
|
from gluon.languages import TranslatorFactory
|
||||||
from gluon.dal import DAL, Field
|
from gluon.dal import DAL, Field
|
||||||
from gluon.validators import Validator
|
from gluon.validators import Validator
|
||||||
@@ -44,7 +45,6 @@ from functools import reduce
|
|||||||
from gluon import rewrite
|
from gluon import rewrite
|
||||||
from gluon.custom_import import custom_import_install
|
from gluon.custom_import import custom_import_install
|
||||||
import py_compile
|
import py_compile
|
||||||
import ast
|
|
||||||
|
|
||||||
logger = logging.getLogger("web2py")
|
logger = logging.getLogger("web2py")
|
||||||
|
|
||||||
@@ -517,8 +517,8 @@ def compile_models(folder):
|
|||||||
|
|
||||||
|
|
||||||
def find_exposed_functions(data):
|
def find_exposed_functions(data):
|
||||||
parsed = ast.parse(data)
|
data = regex_longcomments.sub('', data)
|
||||||
return [n.name for n in ast.walk(parsed) if type(n) == ast.FunctionDef and len(n.args.args) == 0 and n.args.kwarg is None]
|
return regex_expose.findall(data)
|
||||||
|
|
||||||
|
|
||||||
def compile_controllers(folder):
|
def compile_controllers(folder):
|
||||||
|
|||||||
+7
-1
@@ -18,7 +18,13 @@ regex_tables = re.compile(
|
|||||||
"""^[\w]+\.define_table\(\s*[\'\"](?P<name>\w+)[\'\"]""",
|
"""^[\w]+\.define_table\(\s*[\'\"](?P<name>\w+)[\'\"]""",
|
||||||
flags=re.M)
|
flags=re.M)
|
||||||
|
|
||||||
# patterns to find includes and extends in views
|
# pattern to find exposed functions in controller
|
||||||
|
|
||||||
|
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(
|
regex_include = re.compile(
|
||||||
'(?P<all>\{\{\s*include\s+[\'"](?P<name>[^\'"]*)[\'"]\s*\}\})')
|
'(?P<all>\{\{\s*include\s+[\'"](?P<name>[^\'"]*)[\'"]\s*\}\})')
|
||||||
|
|||||||
Reference in New Issue
Block a user