def open_environment(env_path, mpr): env = Environment.Environment(env_path) version = env.get_version() if version < Environment.db_version: raise TracError('The Trac environment needs to be upgraded. ' 'Run "trac-admin %s upgrade"' % env_path) elif version > Environment.db_version: raise TracError('Unknown Trac Environment version (%d).' % version) env.href = Href.Href(mpr.cgi_location) env.abs_href = Href.Href(mpr.base_url) return env
def real_cgi_start(): env = open_environment() req = CGIRequest() req.init_request() env.href = Href.Href(req.cgi_location) env.abs_href = Href.Href(req.base_url) # Parse arguments path_info = os.getenv('PATH_INFO') args = parse_args(req.command, path_info, os.getenv('QUERY_STRING'), sys.stdin, os.environ) dispatch_request(path_info, args, req, env)
def send_pretty_error(e, env, req=None): import util import Href import os.path import traceback import StringIO tb = StringIO.StringIO() traceback.print_exc(file=tb) if not req: req = CGIRequest() req.authname = '' req.init_request() try: if not env: env = open_environment() env.href = Href.Href(req.cgi_location) cnx = env.get_db_cnx() populate_hdf(req.hdf, env, cnx, req) if isinstance(e, util.TracError): req.hdf.setValue('title', e.title or 'Error') req.hdf.setValue('error.title', e.title or 'Error') req.hdf.setValue('error.type', 'TracError') req.hdf.setValue('error.message', e.message) if e.show_traceback: req.hdf.setValue('error.traceback', util.escape(tb.getvalue())) elif isinstance(e, perm.PermissionError): req.hdf.setValue('title', 'Permission Denied') req.hdf.setValue('error.type', 'permission') req.hdf.setValue('error.action', e.action) req.hdf.setValue('error.message', str(e)) else: req.hdf.setValue('title', 'Oops') req.hdf.setValue('error.type', 'internal') req.hdf.setValue('error.message', util.escape(str(e))) req.hdf.setValue('error.traceback', util.escape(tb.getvalue())) req.display('error.cs', response=500) except Exception: req.send_response(500) req.send_header('Content-Type', 'text/plain') req.end_headers() req.write('Oops...\n\nTrac detected an internal error:\n\n') req.write(str(e)) req.write('\n') req.write(tb.getvalue()) if env and env.log != None: env.log.error(str(e)) env.log.error(tb.getvalue())
def __init__(self): self.href = Href.Href('/') self._wiki_pages = {}
def __init__(self): self.log = Logging.logger_factory('null') self.href = Href.Href('/') self._wiki_pages = {}