def parse_template(filename, path='views/', context=dict(), lexers={}, delimiters=('{{', '}}')): """ filename can be a view filename in the views folder or an input stream path is the path of a views folder context is a dictionary of symbols used to render the template """ # First, if we have a str try to open the file if isinstance(filename, str): try: fp = open(os.path.join(path, filename), 'rb') text = fp.read() fp.close() except IOError: raise RestrictedError(filename, '', 'Unable to find the file') else: text = filename.read() # Use the file contents to get a parsed template and return it. return str( TemplateParser(text, context=context, path=path, lexers=lexers, delimiters=delimiters))
if request.body: request.body.close() # ################################################## # on application error, rollback database # ################################################## try: if response._custom_rollback: response._custom_rollback() else: BaseAdapter.close_all_instances('rollback') except: pass e = RestrictedError('Framework', '', '', locals()) ticket = e.log(request) or 'unrecoverable' http_response = \ HTTP(500, rewrite.thread.routes.error_message_ticket \ % dict(ticket=ticket), web2py_error='ticket %s' % ticket) finally: if response and hasattr(response, 'session_file') \ and response.session_file: response.session_file.close() session._unlock(response) http_response, new_environ = rewrite.try_rewrite_on_error( http_response, request, environ, ticket) if not http_response:
if request.body: request.body.close() # ################################################## # on application error, rollback database # ################################################## try: if response._custom_rollback: response._custom_rollback() else: BaseAdapter.close_all_instances('rollback') except: pass e = RestrictedError('Framework', '', '', locals()) ticket = e.log(request) or 'unrecoverable' http_response = \ HTTP(500, rwthread.routes.error_message_ticket % dict(ticket=ticket), web2py_error='ticket %s' % ticket) finally: if response and hasattr(response, 'session_file') \ and response.session_file: response.session_file.close() session._unlock(response) http_response, new_environ = try_rewrite_on_error(http_response, request, environ, ticket) if not http_response:
def _raise_error(self, message='', text=None): """ Raise an error using itself as the filename and textual content. """ raise RestrictedError(self.name, text or self.text, message)
error_message_ticket % dict(ticket=ticket), web2py_error='ticket %s' % ticket).to(responder) except: # ################################################## # on application error, rollback database # ################################################## try: if response._custom_rollback: response._custom_rollback() else: SQLDB.close_all_instances(SQLDB.rollback) except: pass e = RestrictedError('Framework', '', '', locals()) try: ticket = e.log(request) except: ticket = 'unrecoverable' logging.error(e.traceback) session._unlock(response) http_error_status = check_error_route(500, items[0]) return HTTP(http_error_status, error_message_ticket % dict(ticket=ticket), web2py_error='ticket %s' % ticket).to(responder) (wsgibase, html.URL) = rewrite(wsgibase, html.URL)
% dict(ticket=ticket), web2py_error='ticket %s' % ticket).to(responder) except: # ################################################## # on application error, rollback database # ################################################## try: if response._custom_rollback: response._custom_rollback() else: SQLDB.close_all_instances(SQLDB.rollback) except: pass e = RestrictedError('Framework', '', '', locals()) try: ticket = e.log(request) except: ticket = 'unrecoverable' logging.error(e.traceback) session._unlock(response) http_error_status = check_error_route(500, items[0]) return HTTP(http_error_status, error_message_ticket % dict(ticket=ticket), web2py_error='ticket %s' % ticket).to(responder) (wsgibase, html.URL) = rewrite(wsgibase, html.URL)