本文整理汇总了Python中myregex.regex_expose.findall函数的典型用法代码示例。如果您正苦于以下问题:Python findall函数的具体用法?Python findall怎么用?Python findall使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了findall函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run_controller_in
def run_controller_in(controller, function, environment):
"""
Runs the controller.function() (for the app specified by
the current folder).
It tries pre-compiled controller_function.pyc first before compiling it.
"""
# if compiled should run compiled!
folder = environment["request"].folder
path = pjoin(folder, "compiled")
badc = "invalid controller (%s/%s)" % (controller, function)
badf = "invalid function (%s/%s)" % (controller, function)
if os.path.exists(path):
filename = pjoin(path, "controllers_%s_%s.pyc" % (controller, function))
if not os.path.exists(filename):
raise HTTP(404, rewrite.thread.routes.error_message % badf, web2py_error=badf)
restricted(read_pyc(filename), environment, layer=filename)
elif function == "_TEST":
# TESTING: adjust the path to include site packages
from settings import global_settings
from admin import abspath, add_path_first
paths = (global_settings.gluon_parent, abspath("site-packages", gluon=True), abspath("gluon", gluon=True), "")
[add_path_first(path) for path in paths]
# TESTING END
filename = pjoin(folder, "controllers/%s.py" % controller)
if not os.path.exists(filename):
raise HTTP(404, rewrite.thread.routes.error_message % badc, web2py_error=badc)
environment["__symbols__"] = environment.keys()
code = read_file(filename)
code += TEST_CODE
restricted(code, environment, layer=filename)
else:
filename = pjoin(folder, "controllers/%s.py" % controller)
if not os.path.exists(filename):
raise HTTP(404, rewrite.thread.routes.error_message % badc, web2py_error=badc)
code = read_file(filename)
exposed = regex_expose.findall(code)
if not function in exposed:
raise HTTP(404, rewrite.thread.routes.error_message % badf, web2py_error=badf)
code = "%s\nresponse._vars=response._caller(%s)\n" % (code, function)
if is_gae:
layer = filename + ":" + function
code = getcfs(layer, filename, lambda: compile2(code, layer))
restricted(code, environment, filename)
response = environment["response"]
vars = response._vars
if response.postprocessing:
for p in response.postprocessing:
vars = p(vars)
if isinstance(vars, unicode):
vars = vars.encode("utf8")
elif hasattr(vars, "xml") and callable(vars.xml):
vars = vars.xml()
return vars
示例2: compile_controllers
def compile_controllers(folder):
"""
Compiles all the controllers in the application specified by `folder`
"""
path = pjoin(folder, "controllers")
for file in listdir(path, ".+\.py$"):
### why is this here? save_pyc(pjoin(path, file))
data = read_file(pjoin(path, file))
exposed = regex_expose.findall(data)
for function in exposed:
command = data + "\nresponse._vars=response._caller(%s)\n" % function
filename = pjoin(
folder, "compiled", ("controllers/" + file[:-3]).replace("/", "_") + "_" + function + ".py"
)
write_file(filename, command)
save_pyc(filename)
os.unlink(filename)
示例3: compile_controllers
def compile_controllers(folder):
"""
Compiles all the controllers in the application specified by `folder`
"""
path = pjoin(folder, 'controllers')
for file in listdir(path, '.+\.py$'):
### why is this here? save_pyc(pjoin(path, file))
data = read_file(pjoin(path, file))
exposed = regex_expose.findall(data)
for function in exposed:
command = data + "\nresponse._vars=response._caller(%s)\n" % \
function
filename = pjoin(folder, 'compiled', ('controllers/'
+ file[:-3]).replace('/', '_')
+ '_' + function + '.py')
write_file(filename, command)
save_pyc(filename)
os.unlink(filename)
示例4: compile_controllers
def compile_controllers(folder):
"""
Compiles all the controllers in the application specified by `folder`
"""
path = os.path.join(folder, 'controllers/')
for file in listdir(path, '.+\.py$'):
save_pyc(os.path.join(path, file))
fp = open(path + file, 'r')
data = fp.read()
fp.close()
exposed = regex_expose.findall(data)
for function in exposed:
command = data + "\nresponse._vars=response._caller(%s)\n" % \
function
filename = os.path.join(folder, 'compiled/', ('controllers/'
+ file[:-3]).replace('/', '_')
+ '_' + function + '.py')
fp = open(filename, 'w')
fp.write(command)
fp.close()
save_pyc(filename)
os.unlink(filename)
示例5: run_controller_in
def run_controller_in(controller, function, environment):
"""
Runs the controller.function() (for the app specified by
the current folder).
It tries pre-compiled controller_function.pyc first before compiling it.
"""
# if compiled should run compiled!
folder = environment['request'].folder
path = pjoin(folder, 'compiled')
badc = 'invalid controller (%s/%s)' % (controller, function)
badf = 'invalid function (%s/%s)' % (controller, function)
if os.path.exists(path):
filename = pjoin(path, 'controllers_%s_%s.pyc'
% (controller, function))
if not os.path.exists(filename):
raise HTTP(404,
rewrite.THREAD_LOCAL.routes.error_message % badf,
web2py_error=badf)
restricted(read_pyc(filename), environment, layer=filename)
elif function == '_TEST':
# TESTING: adjust the path to include site packages
from settings import global_settings
from admin import abspath, add_path_first
paths = (global_settings.gluon_parent, abspath(
'site-packages', gluon=True), abspath('gluon', gluon=True), '')
[add_path_first(path) for path in paths]
# TESTING END
filename = pjoin(folder, 'controllers/%s.py'
% controller)
if not os.path.exists(filename):
raise HTTP(404,
rewrite.THREAD_LOCAL.routes.error_message % badc,
web2py_error=badc)
environment['__symbols__'] = environment.keys()
code = read_file(filename)
code += TEST_CODE
restricted(code, environment, layer=filename)
else:
filename = pjoin(folder, 'controllers/%s.py'
% controller)
if not os.path.exists(filename):
raise HTTP(404,
rewrite.THREAD_LOCAL.routes.error_message % badc,
web2py_error=badc)
code = read_file(filename)
exposed = regex_expose.findall(code)
if not function in exposed:
raise HTTP(404,
rewrite.THREAD_LOCAL.routes.error_message % badf,
web2py_error=badf)
code = "%s\nresponse._vars=response._caller(%s)\n" % (code, function)
if is_gae:
layer = filename + ':' + function
code = getcfs(layer, filename, lambda: compile2(code, layer))
restricted(code, environment, filename)
response = environment['response']
vars = response._vars
if response.postprocessing:
vars = reduce(lambda vars, p: p(vars), response.postprocessing, vars)
if isinstance(vars, unicode):
vars = vars.encode('utf8')
elif hasattr(vars, 'xml') and callable(vars.xml):
vars = vars.xml()
return vars
示例6: run_controller_in
def run_controller_in(controller, function, environment):
"""
Runs the controller.function() (for the app specified by
the current folder).
It tries pre-compiled controller_function.pyc first before compiling it.
"""
# if compiled should run compiled!
folder = environment['request'].folder
path = os.path.join(folder, 'compiled/')
if os.path.exists(path):
filename = os.path.join(path, 'controllers_%s_%s.pyc'
% (controller, function))
if not os.path.exists(filename):
raise HTTP(400,
rewrite.params.error_message_custom % 'invalid function',
web2py_error='invalid function')
restricted(read_pyc(filename), environment, layer=filename)
elif function == '_TEST':
filename = os.path.join(folder, 'controllers/%s.py'
% controller)
if not os.path.exists(filename):
raise HTTP(400,
rewrite.params.error_message_custom % 'invalid controller',
web2py_error='invalid controller')
environment['__symbols__'] = environment.keys()
fp = open(filename, 'r')
code = fp.read()
fp.close()
code += TEST_CODE
restricted(code, environment, layer=filename)
else:
filename = os.path.join(folder, 'controllers/%s.py'
% controller)
if not os.path.exists(filename):
raise HTTP(400,
rewrite.params.error_message_custom % 'invalid controller',
web2py_error='invalid controller')
fp = open(filename, 'r')
code = fp.read()
fp.close()
exposed = regex_expose.findall(code)
if not function in exposed:
raise HTTP(400,
rewrite.params.error_message_custom % 'invalid function',
web2py_error='invalid function')
code = "%s\nresponse._vars=response._caller(%s)\n" % (code, function)
if is_gae:
layer = filename + ':' + function
code = getcfs(layer, filename, lambda: \
compile(code.replace('\r\n', '\n'), layer,
'exec'))
restricted(code, environment, filename)
response = environment['response']
vars=response._vars
if response.postprocessing:
for p in response.postprocessing:
vars = p(vars)
if isinstance(vars,unicode):
vars = vars.encode('utf8')
if hasattr(vars,'xml'):
vars = vars.xml()
return vars