def run_models_in(environment): """ Runs all models (in the app specified by the current folder) It tries pre-compiled models first before compiling them. """ folder = environment['request'].folder c = environment['request'].controller f = environment['request'].function cpath = os.path.join(folder, 'compiled') if os.path.exists(cpath): for model in listdir(cpath, '^models_\w+\.pyc$', 0): restricted(read_pyc(model), environment, layer=model) path = os.path.join(cpath, 'models') models = listdir(path, '^\w+\.pyc$',0,sort=False) compiled=True else: path = os.path.join(folder, 'models') models = listdir(path, '^\w+\.py$',0,sort=False) compiled=False paths = (path, os.path.join(path,c), os.path.join(path,c,f)) for model in models: if not os.path.split(model)[0] in paths and c!='appadmin': continue elif compiled: code = read_pyc(model) elif is_gae: code = getcfs(model, model, lambda: compile2(read_file(model), model)) else: code = getcfs(model, model, None) restricted(code, environment, layer=model)
def run_models_in(environment): """ Runs all models (in the app specified by the current folder) It tries pre-compiled models first before compiling them. """ folder = environment['request'].folder c = environment['request'].controller f = environment['request'].function cpath = os.path.join(folder, 'compiled') if os.path.exists(cpath): for model in listdir(cpath, '^models_\w+\.pyc$', 0): restricted(read_pyc(model), environment, layer=model) path = os.path.join(cpath, 'models') models = listdir(path, '^\w+\.pyc$', 0, sort=False) compiled = True else: path = os.path.join(folder, 'models') models = listdir(path, '^\w+\.py$', 0, sort=False) compiled = False paths = (path, os.path.join(path, c), os.path.join(path, c, f)) for model in models: if not os.path.split(model)[0] in paths and c != 'appadmin': continue elif compiled: code = read_pyc(model) elif is_gae: code = getcfs(model, model, lambda: compile2(read_file(model), model)) else: code = getcfs(model, model, None) restricted(code, environment, layer=model)
def run_models_in(environment): """ Runs all models (in the app specified by the current folder) It tries pre-compiled models first before compiling them. """ folder = environment["request"].folder c = environment["request"].controller f = environment["request"].function cpath = pjoin(folder, "compiled") if os.path.exists(cpath): for model in listdir(cpath, "^models_\w+\.pyc$", 0): restricted(read_pyc(model), environment, layer=model) path = pjoin(cpath, "models") models = listdir(path, "^\w+\.pyc$", 0, sort=False) compiled = True else: path = pjoin(folder, "models") models = listdir(path, "^\w+\.py$", 0, sort=False) compiled = False n = len(path) + 1 for model in models: regex = environment["response"].models_to_run if isinstance(regex, list): regex = re_compile("|".join(regex)) file = model[n:].replace(os.path.sep, "/").replace(".pyc", ".py") if not regex.search(file) and c != "appadmin": continue elif compiled: code = read_pyc(model) elif is_gae: code = getcfs(model, model, lambda: compile2(read_file(model), model)) else: code = getcfs(model, model, None) restricted(code, environment, layer=model)
def run_view_in(environment): """ Executes the view for the requested action. The view is the one specified in `response.view` or determined by the url or `view/generic.extension` It tries the pre-compiled views_controller_function.pyc before compiling it. """ request = environment["request"] response = environment["response"] view = response.view folder = request.folder path = pjoin(folder, "compiled") badv = "invalid view (%s)" % view if response.generic_patterns: patterns = response.generic_patterns regex = re_compile("|".join(map(fnmatch.translate, patterns))) short_action = "%(controller)s/%(function)s.%(extension)s" % request allow_generic = regex.search(short_action) else: allow_generic = False if not isinstance(view, str): ccode = parse_template(view, pjoin(folder, "views"), context=environment) restricted(ccode, environment, "file stream") elif os.path.exists(path): x = view.replace("/", "_") files = ["views_%s.pyc" % x] if allow_generic: files.append("views_generic.%s.pyc" % request.extension) # for backward compatibility if request.extension == "html": files.append("views_%s.pyc" % x[:-5]) if allow_generic: files.append("views_generic.pyc") # end backward compatibility code for f in files: filename = pjoin(path, f) if os.path.exists(filename): code = read_pyc(filename) restricted(code, environment, layer=filename) return raise HTTP(404, rewrite.thread.routes.error_message % badv, web2py_error=badv) else: filename = pjoin(folder, "views", view) if not os.path.exists(filename) and allow_generic: view = "generic." + request.extension filename = pjoin(folder, "views", view) if not os.path.exists(filename): raise HTTP(404, rewrite.thread.routes.error_message % badv, web2py_error=badv) layer = filename if is_gae: ccode = getcfs( layer, filename, lambda: compile2(parse_template(view, pjoin(folder, "views"), context=environment), layer), ) else: ccode = parse_template(view, pjoin(folder, "views"), context=environment) restricted(ccode, environment, layer)
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
def run_view_in(environment): """ Executes the view for the requested action. The view is the one specified in `response.view` or determined by the url or `view/generic.extension` It tries the pre-compiled views_controller_function.pyc before compiling it. """ request = environment['request'] response = environment['response'] folder = request.folder path = os.path.join(folder, 'compiled') badv = 'invalid view (%s)' % response.view if not isinstance(response.view, str): ccode = parse_template(response.view, os.path.join(folder, 'views'), context=environment) restricted(ccode, environment, 'file stream') elif os.path.exists(path): x = response.view.replace('/', '_') if request.extension == 'html': # for backward compatibility files = [os.path.join(path, 'views_%s.pyc' % x), os.path.join(path, 'views_%s.pyc' % x[:-5]), os.path.join(path, 'views_generic.html.pyc'), os.path.join(path, 'views_generic.pyc')] else: files = [os.path.join(path, 'views_%s.pyc' % x), os.path.join(path, 'views_generic.%s.pyc' % request.extension)] for filename in files: if os.path.exists(filename): code = read_pyc(filename) restricted(code, environment, layer=filename) return raise HTTP(400, rewrite.thread.routes.error_message % badv, web2py_error=badv) else: filename = os.path.join(folder, 'views', response.view) if not os.path.exists(filename): response.view = 'generic.' + request.extension filename = os.path.join(folder, 'views', response.view) if not os.path.exists(filename): raise HTTP(400, rewrite.thread.routes.error_message % badv, web2py_error=badv) layer = filename if is_gae: ccode = getcfs(layer, filename, lambda: compile2(parse_template(response.view, os.path.join(folder, 'views'), context=environment),layer)) else: ccode = parse_template(response.view, os.path.join(folder, 'views'), context=environment) restricted(ccode, environment, layer)
def run_models_in(environment): """ Runs all models (in the app specified by the current folder) It tries pre-compiled models first before compiling them. """ folder = environment['request'].folder path = os.path.join(folder, 'compiled') if os.path.exists(path): for model in listdir(path, '^models_.+\.pyc$', 0): restricted(read_pyc(model), environment, layer=model) else: models = listdir(os.path.join(folder, 'models'), '^\w+\.py$', 0) for model in models: layer = model if is_gae: code = getcfs(model, model, lambda: compile2(open(model, 'r').read(), layer)) else: code = getcfs(model, model, None) restricted(code, environment, layer)
def run_models_in(environment): """ Runs all models (in the app specified by the current folder) It tries pre-compiled models first before compiling them. """ folder = environment['request'].folder path = os.path.join(folder, 'compiled') if os.path.exists(path): for model in listdir(path, '^models_.+\.pyc$', 0): restricted(read_pyc(model), environment, layer=model) else: models = listdir(os.path.join(folder, 'models'), '^\w+\.py$', 0) for model in models: layer = model if is_gae: code = getcfs(model, model, lambda: compile2(open(model, 'r').read(),layer)) else: code = getcfs(model, model, None) restricted(code, environment, layer)
def run_models_in(environment): """ Runs all models (in the app specified by the current folder) It tries pre-compiled models first before compiling them. """ folder = environment['request'].folder c = environment['request'].controller f = environment['request'].function cpath = pjoin(folder, 'compiled') if os.path.exists(cpath): for model in listdir(cpath, '^models_\w+\.pyc$', 0): restricted(read_pyc(model), environment, layer=model) path = pjoin(cpath, 'models') models = listdir(path, '^\w+\.pyc$', 0) compiled = True else: path = pjoin(folder, 'models') models = listdir(path, '^\w+\.py$', 0) compiled = False n = len(path) + 1 for model in models: regex = environment['response'].models_to_run if isinstance(regex, list): regex = re_compile('|'.join(regex)) file = model[n:].replace(os.path.sep, '/').replace('.pyc', '.py') if not regex.search(file) and c != 'appadmin': continue elif compiled: code = read_pyc(model) elif is_gae: code = getcfs(model, model, lambda: compile2(read_file(model), model)) else: code = getcfs(model, model, None) restricted(code, environment, layer=model)
def run_models_in(environment): """ Runs all models (in the app specified by the current folder) It tries pre-compiled models first before compiling them. """ folder = environment['request'].folder c = environment['request'].controller f = environment['request'].function cpath = pjoin(folder, 'compiled') if os.path.exists(cpath): for model in listdir(cpath, '^models_\w+\.pyc$', 0): restricted(read_pyc(model), environment, layer=model) path = pjoin(cpath, 'models') models = listdir(path, '^\w+\.pyc$',0,sort=False) compiled=True else: path = pjoin(folder, 'models') models = listdir(path, '^\w+\.py$',0,sort=False) compiled=False n = len(path) + 1 for model in models: regex = environment['response'].models_to_run if isinstance(regex, list): regex = re_compile('|'.join(regex)) file = model[n:].replace(os.path.sep, '/').replace('.pyc', '.py') if not regex.search(file) and c!= 'appadmin': continue elif compiled: code = read_pyc(model) elif is_gae: code = getcfs(model, model, lambda: compile2(read_file(model), model)) else: code = getcfs(model, model, None) restricted(code, environment, layer=model)
def read_plural_dict(filename): return getcfs('plurals:' + filename, filename, lambda: read_plural_dict_aux(filename))
def read_possible_languages(langpath): return getcfs('langs:' + langpath, langpath, lambda: read_possible_languages_aux(langpath))
def run_view_in(environment): """ Executes the view for the requested action. The view is the one specified in `response.view` or determined by the url or `view/generic.extension` It tries the pre-compiled views_controller_function.pyc before compiling it. """ request = environment['request'] response = environment['response'] folder = request.folder path = os.path.join(folder, 'compiled') badv = 'invalid view (%s)' % response.view patterns = response.generic_patterns or [] regex = re.compile('|'.join(fnmatch.translate(r) for r in patterns)) short_action = '%(controller)s/%(function)s.%(extension)s' % request allow_generic = patterns and regex.search(short_action) if not isinstance(response.view, str): ccode = parse_template(response.view, os.path.join(folder, 'views'), context=environment) restricted(ccode, environment, 'file stream') elif os.path.exists(path): x = response.view.replace('/', '_') files = ['views_%s.pyc' % x] if allow_generic: files.append('views_generic.%s.pyc' % request.extension) # for backward compatibility if request.extension == 'html': files.append('views_%s.pyc' % x[:-5]) if allow_generic: files.append('views_generic.pyc') # end backward compatibility code for f in files: filename = os.path.join(path,f) if os.path.exists(filename): code = read_pyc(filename) restricted(code, environment, layer=filename) return raise HTTP(404, rewrite.thread.routes.error_message % badv, web2py_error=badv) else: filename = os.path.join(folder, 'views', response.view) if not os.path.exists(filename) and allow_generic: response.view = 'generic.' + request.extension filename = os.path.join(folder, 'views', response.view) if not os.path.exists(filename): # Troubleshoot suggested by http://groups.google.com/group/web2py/browse_thread/thread/1c9ed82b640d04a9/82c734b68b79a16a?lnk=gst&q=invalid+view#82c734b68b79a16a badv = filename raise HTTP(404, rewrite.thread.routes.error_message % badv, web2py_error=badv) layer = filename if is_gae: ccode = getcfs(layer, filename, lambda: compile2(parse_template(response.view, os.path.join(folder, 'views'), context=environment),layer)) else: ccode = parse_template(response.view, os.path.join(folder, 'views'), context=environment) restricted(ccode, environment, layer)
def read_plural_rules(lang): filename = abspath('gluon','contrib','rules', 'plural_rules-%s.py' % lang) return getcfs('plural_rules-'+lang, filename, lambda: read_plural_rules_aux(filename))
def read_possible_languages(appdir): langdir = pjoin(appdir,'languages') return getcfs('langs:'+langdir, langdir, lambda: read_possible_languages_aux(langdir))
def read_possible_languages(path): lang_path = ospath.join(path, 'languages') return getcfs('langs:'+lang_path, lang_path, lambda: read_possible_languages_aux(lang_path))
def read_possible_languages(appdir): langdir = pjoin(appdir, "languages") return getcfs("langs:" + langdir, langdir, lambda: read_possible_languages_aux(langdir))
def read_dict(filename): return getcfs('language:%s' % filename, filename, lambda filename=filename: read_dict_aux(filename))
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
def read_plural_rules(lang): filename = abspath('gluon', 'contrib', 'rules', 'plural_rules-%s.py' % lang) return getcfs('plural_rules-' + lang, filename, lambda: read_plural_rules_aux(filename))
def read_dict(filename): """ return dictionary with translation messages """ return getcfs('lang:'+filename, filename, lambda: read_dict_aux(filename))
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
def read_possible_languages(appdir): langdir = pjoin(appdir, 'languages') return getcfs('langs:' + langdir, langdir, lambda: read_possible_languages_aux(langdir))
def read_dict(filename): """ return dictionary with translation messages """ return getcfs('lang:' + filename, filename, lambda: read_dict_aux(filename))
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') badc = 'invalid controller (%s/%s)' % (controller, function) badf = 'invalid function (%s/%s)' % (controller, function) 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.thread.routes.error_message % badf, web2py_error=badf) 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.thread.routes.error_message % badc, web2py_error=badc) 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.thread.routes.error_message % badc, web2py_error=badc) fp = open(filename, 'r') code = fp.read() fp.close() exposed = regex_expose.findall(code) if not function in exposed: raise HTTP(400, 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') if hasattr(vars,'xml'): vars = vars.xml() return vars
def run_view_in(environment): """ Executes the view for the requested action. The view is the one specified in `response.view` or determined by the url or `view/generic.extension` It tries the pre-compiled views_controller_function.pyc before compiling it. """ request = environment['request'] response = environment['response'] view = response.view folder = request.folder path = pjoin(folder, 'compiled') badv = 'invalid view (%s)' % view if response.generic_patterns: patterns = response.generic_patterns regex = re_compile('|'.join(map(fnmatch.translate, patterns))) short_action = '%(controller)s/%(function)s.%(extension)s' % request allow_generic = regex.search(short_action) else: allow_generic = False if not isinstance(view, str): ccode = parse_template(view, pjoin(folder, 'views'), context=environment) restricted(ccode, environment, 'file stream') elif os.path.exists(path): x = view.replace('/', '_') files = ['views_%s.pyc' % x] if allow_generic: files.append('views_generic.%s.pyc' % request.extension) # for backward compatibility if request.extension == 'html': files.append('views_%s.pyc' % x[:-5]) if allow_generic: files.append('views_generic.pyc') # end backward compatibility code for f in files: filename = pjoin(path,f) if os.path.exists(filename): code = read_pyc(filename) restricted(code, environment, layer=filename) return raise HTTP(404, rewrite.THREAD_LOCAL.routes.error_message % badv, web2py_error=badv) else: filename = pjoin(folder, 'views', view) if not os.path.exists(filename) and allow_generic: view = 'generic.' + request.extension filename = pjoin(folder, 'views', view) if not os.path.exists(filename): raise HTTP(404, rewrite.THREAD_LOCAL.routes.error_message % badv, web2py_error=badv) layer = filename if is_gae: ccode = getcfs(layer, filename, lambda: compile2(parse_template(view, pjoin(folder, 'views'), context=environment),layer)) else: ccode = parse_template(view, pjoin(folder, 'views'), context=environment) restricted(ccode, environment, layer)
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') badc = 'invalid controller (%s/%s)' % (controller, function) badf = 'invalid function (%s/%s)' % (controller, function) if os.path.exists(path): filename = os.path.join( 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': filename = os.path.join(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() 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(404, rewrite.thread.routes.error_message % badc, web2py_error=badc) fp = open(filename, 'r') code = fp.read() fp.close() 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') if hasattr(vars, 'xml'): vars = vars.xml() return vars
def read_plural_dict(filename): return getcfs('plurals:'+filename, filename, lambda: read_plural_dict_aux(filename))
def read_dict(filename): return getcfs('language:%s'%filename,filename, lambda filename=filename:read_dict_aux(filename))
def run_view_in(environment): """ Executes the view for the requested action. The view is the one specified in `response.view` or determined by the url or `view/generic.extension` It tries the pre-compiled views_controller_function.pyc before compiling it. """ request = environment['request'] response = environment['response'] view = response.view folder = request.folder path = pjoin(folder, 'compiled') badv = 'invalid view (%s)' % view if response.generic_patterns: patterns = response.generic_patterns regex = re_compile('|'.join(map(fnmatch.translate, patterns))) short_action = '%(controller)s/%(function)s.%(extension)s' % request allow_generic = regex.search(short_action) else: allow_generic = False if not isinstance(view, str): ccode = parse_template(view, pjoin(folder, 'views'), context=environment) restricted(ccode, environment, 'file stream') elif os.path.exists(path): x = view.replace('/', '_') files = ['views_%s.pyc' % x] if allow_generic: files.append('views_generic.%s.pyc' % request.extension) # for backward compatibility if request.extension == 'html': files.append('views_%s.pyc' % x[:-5]) if allow_generic: files.append('views_generic.pyc') # end backward compatibility code for f in files: filename = pjoin(path, f) if os.path.exists(filename): code = read_pyc(filename) restricted(code, environment, layer=filename) return raise HTTP(404, rewrite.THREAD_LOCAL.routes.error_message % badv, web2py_error=badv) else: filename = pjoin(folder, 'views', view) if not os.path.exists(filename) and allow_generic: view = 'generic.' + request.extension filename = pjoin(folder, 'views', view) if not os.path.exists(filename): raise HTTP(404, rewrite.THREAD_LOCAL.routes.error_message % badv, web2py_error=badv) layer = filename if is_gae: ccode = getcfs(layer, filename, lambda: compile2(parse_template(view, pjoin(folder, 'views'), context=environment), layer)) else: ccode = parse_template(view, pjoin(folder, 'views'), context=environment) restricted(ccode, environment, layer)
def read_possible_languages(path): lang_path = ospath.join(path, 'languages') return getcfs('langs:' + lang_path, lang_path, lambda: read_possible_languages_aux(lang_path))