<s> from __future__ import print_function <EOL> import cgi <EOL> import dircache <EOL> import fnmatch <EOL> from functools import partial <EOL> import gc <EOL> import io <EOL> import locale <EOL> import os <EOL> import pkg_resources <EOL> from pprint import pformat , pprint <EOL> import re <EOL> import sys <EOL> import traceback <EOL> from urlparse import urlparse <EOL> from genshi . builder import tag <EOL> from genshi . output import DocType <EOL> from genshi . template import TemplateLoader <EOL> from trac import __version__ as TRAC_VERSION <EOL> from trac . config import BoolOption , ChoiceOption , ConfigurationError , ExtensionOption , Option , OrderedExtensionsOption <EOL> from trac . core import * <EOL> from trac . env import open_environment <EOL> from trac . loader import get_plugin_info , match_plugins_to_frames <EOL> from trac . perm import PermissionCache , PermissionError <EOL> from trac . resource import ResourceNotFound <EOL> from trac . util import arity , get_frame_info , get_last_traceback , hex_entropy , lazy , read_file , safe_repr , translation , warn_setuptools_issue <EOL> from trac . util . concurrency import threading <EOL> from trac . util . datefmt import format_datetime , localtz , timezone , user_time <EOL> from trac . util . text import exception_to_unicode , shorten_line , to_unicode , to_utf8 , unicode_quote <EOL> from trac . util . translation import _ , get_negotiated_locale , has_babel , safefmt , tag_ <EOL> from trac . web . api import HTTPBadRequest , HTTPException , HTTPForbidden , HTTPInternalError , HTTPNotFound , IAuthenticator , IRequestFilter , IRequestHandler , Request , RequestDone , TracNotImplementedError , is_valid_default_handler <EOL> from trac . web . chrome import Chrome , ITemplateProvider , add_notice , add_warning <EOL> from trac . web . href import Href <EOL> from trac . web . session import Session <EOL> default_tracker = '<STR_LIT>' <EOL> class FakeSession ( dict ) : <EOL> sid = None <EOL> authenticated = False <EOL> last_visit = <NUM_LIT:0> <EOL> def save ( self ) : <EOL> pass <EOL> class FakePerm ( object ) : <EOL> username = '<STR_LIT>' <EOL> def __call__ ( self , realm_or_resource , id = False , version = False ) : <EOL> return self <EOL> def has_permission ( self , action , realm_or_resource = None , id = False , <EOL> version = False ) : <EOL> return False <EOL> __contains__ = has_permission <EOL> def require ( self , action , realm_or_resource = None , id = False , version = False , <EOL> message = None ) : <EOL> if message is None : <EOL> raise PermissionError ( action ) <EOL> else : <EOL> raise PermissionError ( msg = message ) <EOL> assert_permission = require <EOL> class RequestWithSession ( Request ) : <EOL> """<STR_LIT>""" <EOL> def send_response ( self , code = <NUM_LIT:200> ) : <EOL> if code < <NUM_LIT> : <EOL> self . session . save ( ) <EOL> super ( RequestWithSession , self ) . send_response ( code ) <EOL> class RequestDispatcher ( Component ) : <EOL> """<STR_LIT>""" <EOL> required = True <EOL> implements ( ITemplateProvider ) <EOL> authenticators = ExtensionPoint ( IAuthenticator ) <EOL> handlers = ExtensionPoint ( IRequestHandler ) <EOL> filters = OrderedExtensionsOption ( '<STR_LIT>' , '<STR_LIT>' , <EOL> IRequestFilter , <EOL> doc = """<STR_LIT>""" ) <EOL> default_handler = ExtensionOption ( '<STR_LIT>' , '<STR_LIT>' , <EOL> IRequestHandler , '<STR_LIT>' , <EOL> """<STR_LIT>""" ) <EOL> default_timezone = Option ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> """<STR_LIT>""" ) <EOL> default_language = Option ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> """<STR_LIT>""" ) <EOL> default_date_format = ChoiceOption ( '<STR_LIT>' , '<STR_LIT>' , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> """<STR_LIT>""" ) <EOL> use_xsendfile = BoolOption ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:false>' , <EOL> """<STR_LIT>""" ) <EOL> xsendfile_header = Option ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> """<STR_LIT>""" ) <EOL> def authenticate ( self , req ) : <EOL> for authenticator in self . authenticators : <EOL> try : <EOL> authname = authenticator . authenticate ( req ) <EOL> except TracError as e : <EOL> self . log . error ( "<STR_LIT>" , <EOL> authenticator . __class__ . __name__ , <EOL> exception_to_unicode ( e , traceback = True ) ) <EOL> add_warning ( req , _ ( "<STR_LIT>" <EOL> "<STR_LIT>" ) ) <EOL> break <EOL> if authname : <EOL> return authname <EOL> return '<STR_LIT>' <EOL> def dispatch ( self , req ) : <EOL> """<STR_LIT>""" <EOL> self . log . debug ( '<STR_LIT>' , req ) <EOL> chrome = Chrome ( self . env ) <EOL> req . callbacks . update ( { <EOL> '<STR_LIT>' : self . authenticate , <EOL> '<STR_LIT>' : chrome . prepare_request , <EOL> '<STR_LIT>' : self . _get_form_token , <EOL> '<STR_LIT>' : self . _get_lc_time , <EOL> '<STR_LIT>' : self . _get_locale , <EOL> '<STR_LIT>' : self . _get_perm , <EOL> '<STR_LIT>' : self . _get_session , <EOL> '<STR_LIT>' : self . _get_timezone , <EOL> '<STR_LIT>' : self . _get_use_xsendfile , <EOL> '<STR_LIT>' : self . _get_xsendfile_header , <EOL> } ) <EOL> try : <EOL> chosen_handler = None <EOL> for handler in self . _request_handlers . values ( ) : <EOL> if handler . match_request ( req ) : <EOL> chosen_handler = handler <EOL> break <EOL> if not chosen_handler and req . path_info in ( '<STR_LIT>' , '<STR_LIT:/>' ) : <EOL> chosen_handler = self . _get_valid_default_handler ( req ) <EOL> self . log . debug ( "<STR_LIT>" , chosen_handler ) <EOL> chosen_handler = self . _pre_process_request ( req , chosen_handler ) <EOL> if not chosen_handler : <EOL> if req . path_info . endswith ( '<STR_LIT:/>' ) : <EOL> target = unicode_quote ( req . path_info . rstrip ( '<STR_LIT:/>' ) ) <EOL> if req . query_string : <EOL> target += '<STR_LIT:?>' + req . query_string <EOL> req . redirect ( req . href + target , permanent = True ) <EOL> raise HTTPNotFound ( '<STR_LIT>' , <EOL> req . path_info ) <EOL> req . callbacks [ '<STR_LIT>' ] = partial ( chrome . prepare_request , <EOL> handler = chosen_handler ) <EOL> if req . method == '<STR_LIT:POST>' : <EOL> ctype = req . get_header ( '<STR_LIT:Content-Type>' ) <EOL> if ctype : <EOL> ctype , options = cgi . parse_header ( ctype ) <EOL> if ctype in ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) and req . args . get ( '<STR_LIT>' ) != req . form_token : <EOL> if self . env . secure_cookies and req . scheme == '<STR_LIT:http>' : <EOL> msg = _ ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> else : <EOL> msg = _ ( '<STR_LIT>' ) <EOL> raise HTTPBadRequest ( _ ( '<STR_LIT>' <EOL> '<STR_LIT>' , msg = msg ) ) <EOL> resp = chosen_handler . process_request ( req ) <EOL> if resp : <EOL> if len ( resp ) == <NUM_LIT:2> : <EOL> self . log . error ( "<STR_LIT>" <EOL> "<STR_LIT>" , resp [ <NUM_LIT:0> ] ) <EOL> raise TracError ( <EOL> _ ( "<STR_LIT>" <EOL> "<STR_LIT>" ) ) <EOL> template , data , content_type , method = self . _post_process_request ( req , * resp ) <EOL> if '<STR_LIT>' in req . args : <EOL> req . perm . require ( '<STR_LIT>' ) <EOL> out = io . BytesIO ( ) <EOL> pprint ( data , out ) <EOL> req . send ( out . getvalue ( ) , '<STR_LIT>' ) <EOL> self . log . debug ( "<STR_LIT>" ) <EOL> output = chrome . render_template ( <EOL> req , template , data , content_type , method = method , <EOL> iterable = chrome . use_chunked_encoding ) <EOL> req . send ( output , content_type or '<STR_LIT>' ) <EOL> else : <EOL> self . log . debug ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> self . _post_process_request ( req ) <EOL> except RequestDone : <EOL> raise <EOL> except Exception as e : <EOL> err = sys . exc_info ( ) <EOL> try : <EOL> self . _post_process_request ( req ) <EOL> except RequestDone : <EOL> pass <EOL> except Exception as e2 : <EOL> self . log . error ( "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> exception_to_unicode ( e2 , traceback = True ) ) <EOL> if isinstance ( e , PermissionError ) : <EOL> raise HTTPForbidden ( e ) <EOL> if isinstance ( e , ResourceNotFound ) : <EOL> raise HTTPNotFound ( e ) <EOL> if isinstance ( e , NotImplementedError ) : <EOL> tb = traceback . extract_tb ( err [ <NUM_LIT:2> ] ) [ - <NUM_LIT:1> ] <EOL> self . log . warning ( "<STR_LIT>" , <EOL> e . __class__ . __name__ , tb [ <NUM_LIT:0> ] , tb [ <NUM_LIT:1> ] , tb [ <NUM_LIT:2> ] , <EOL> to_unicode ( e ) or "<STR_LIT>" ) <EOL> raise HTTPInternalError ( TracNotImplementedError ( e ) ) <EOL> if isinstance ( e , TracError ) : <EOL> raise HTTPInternalError ( e ) <EOL> raise err [ <NUM_LIT:0> ] , err [ <NUM_LIT:1> ] , err [ <NUM_LIT:2> ] <EOL> def get_htdocs_dirs ( self ) : <EOL> return [ ] <EOL> def get_templates_dirs ( self ) : <EOL> return [ pkg_resources . resource_filename ( '<STR_LIT>' , '<STR_LIT>' ) ] <EOL> @ lazy <EOL> def _request_handlers ( self ) : <EOL> return dict ( ( handler . __class__ . __name__ , handler ) <EOL> for handler in self . handlers ) <EOL> def _get_valid_default_handler ( self , req ) : <EOL> name = req . session . get ( '<STR_LIT>' ) <EOL> handler = self . _request_handlers . get ( name ) <EOL> if handler and not is_valid_default_handler ( handler ) : <EOL> handler = None <EOL> if not handler : <EOL> handler = self . default_handler <EOL> if not is_valid_default_handler ( handler ) : <EOL> raise ConfigurationError ( <EOL> tag_ ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> handler = tag . code ( handler . __class__ . __name__ ) , <EOL> option = tag . code ( "<STR_LIT>" ) , <EOL> page = tag . a ( _ ( "<STR_LIT>" ) , <EOL> href = req . href . admin ( '<STR_LIT>' ) ) ) ) <EOL> return handler <EOL> def _get_perm ( self , req ) : <EOL> if isinstance ( req . session , FakeSession ) : <EOL> return FakePerm ( ) <EOL> else : <EOL> return PermissionCache ( self . env , req . authname ) <EOL> def _get_session ( self , req ) : <EOL> try : <EOL> return Session ( self . env , req ) <EOL> except TracError as e : <EOL> self . log . error ( "<STR_LIT>" , <EOL> exception_to_unicode ( e ) ) <EOL> return FakeSession ( ) <EOL> def _get_locale ( self , req ) : <EOL> if has_babel : <EOL> preferred = req . session . get ( '<STR_LIT>' ) <EOL> default = self . env . config . get ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> negotiated = get_negotiated_locale ( [ preferred , default ] + <EOL> req . languages ) <EOL> self . log . debug ( "<STR_LIT>" , preferred , <EOL> negotiated ) <EOL> return negotiated <EOL> def _get_lc_time ( self , req ) : <EOL> lc_time = req . session . get ( '<STR_LIT>' ) <EOL> if not lc_time or lc_time == '<STR_LIT>' and not has_babel : <EOL> lc_time = self . default_date_format <EOL> if lc_time == '<STR_LIT>' : <EOL> return '<STR_LIT>' <EOL> return req . locale <EOL> def _get_timezone ( self , req ) : <EOL> try : <EOL> return timezone ( req . session . get ( '<STR_LIT>' , self . default_timezone <EOL> or '<STR_LIT>' ) ) <EOL> except Exception : <EOL> return localtz <EOL> def _get_form_token ( self , req ) : <EOL> """<STR_LIT>""" <EOL> if '<STR_LIT>' in req . incookie : <EOL> return req . incookie [ '<STR_LIT>' ] . value <EOL> else : <EOL> req . outcookie [ '<STR_LIT>' ] = hex_entropy ( <NUM_LIT> ) <EOL> req . outcookie [ '<STR_LIT>' ] [ '<STR_LIT:path>' ] = req . base_path or '<STR_LIT:/>' <EOL> if self . env . secure_cookies : <EOL> req . outcookie [ '<STR_LIT>' ] [ '<STR_LIT>' ] = True <EOL> req . outcookie [ '<STR_LIT>' ] [ '<STR_LIT>' ] = True <EOL> return req . outcookie [ '<STR_LIT>' ] . value <EOL> def _get_use_xsendfile ( self , req ) : <EOL> return self . use_xsendfile <EOL> _xsendfile_header_re = re . compile ( r"<STR_LIT>" ) <EOL> _warn_xsendfile_header = False <EOL> def _get_xsendfile_header ( self , req ) : <EOL> header = self . xsendfile_header . strip ( ) <EOL> if self . _xsendfile_header_re . match ( header ) : <EOL> return to_utf8 ( header ) <EOL> else : <EOL> if not self . _warn_xsendfile_header : <EOL> self . _warn_xsendfile_header = True <EOL> self . log . warn ( "<STR_LIT>" , <EOL> header ) <EOL> return None <EOL> def _pre_process_request ( self , req , chosen_handler ) : <EOL> for filter_ in self . filters : <EOL> chosen_handler = filter_ . pre_process_request ( req , chosen_handler ) <EOL> return chosen_handler <EOL> def _post_process_request ( self , req , * args ) : <EOL> resp = args <EOL> if len ( resp ) == <NUM_LIT:3> : <EOL> resp += ( None , ) <EOL> nbargs = len ( resp ) <EOL> for f in reversed ( self . filters ) : <EOL> extra_arg_count = arity ( f . post_process_request ) - <NUM_LIT:1> <EOL> if extra_arg_count == nbargs : <EOL> resp = f . post_process_request ( req , * resp ) <EOL> elif extra_arg_count == nbargs - <NUM_LIT:1> : <EOL> method = resp [ - <NUM_LIT:1> ] <EOL> resp = f . post_process_request ( req , * resp [ : - <NUM_LIT:1> ] ) <EOL> resp += ( method , ) <EOL> elif nbargs == <NUM_LIT:0> : <EOL> f . post_process_request ( req , * ( None , ) * extra_arg_count ) <EOL> return resp <EOL> _warn_setuptools = False <EOL> _slashes_re = re . compile ( r'<STR_LIT>' ) <EOL> def dispatch_request ( environ , start_response ) : <EOL> """<STR_LIT>""" <EOL> global _warn_setuptools <EOL> if _warn_setuptools is False : <EOL> _warn_setuptools = True <EOL> warn_setuptools_issue ( out = environ . get ( '<STR_LIT>' ) ) <EOL> if sys . flags . optimize != <NUM_LIT:0> : <EOL> raise EnvironmentError ( "<STR_LIT>" ) <EOL> script_url = environ . get ( '<STR_LIT>' ) <EOL> if script_url is not None : <EOL> path_info = environ . get ( '<STR_LIT>' ) <EOL> if not path_info : <EOL> environ [ '<STR_LIT>' ] = script_url <EOL> else : <EOL> script_url = _slashes_re . sub ( '<STR_LIT:/>' , script_url ) <EOL> path_info = _slashes_re . sub ( '<STR_LIT:/>' , path_info ) <EOL> if script_url . endswith ( path_info ) : <EOL> environ [ '<STR_LIT>' ] = script_url [ : - len ( path_info ) ] <EOL> environ . setdefault ( '<STR_LIT>' , os . getenv ( '<STR_LIT>' ) ) <EOL> environ . setdefault ( '<STR_LIT>' , <EOL> os . getenv ( '<STR_LIT>' ) ) <EOL> environ . setdefault ( '<STR_LIT>' , <EOL> os . getenv ( '<STR_LIT>' ) ) <EOL> environ . setdefault ( '<STR_LIT>' , <EOL> os . getenv ( '<STR_LIT>' ) ) <EOL> environ . setdefault ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> environ . setdefault ( '<STR_LIT>' , <EOL> os . getenv ( '<STR_LIT>' ) ) <EOL> locale . setlocale ( locale . LC_ALL , environ [ '<STR_LIT>' ] ) <EOL> env_path = environ . get ( '<STR_LIT>' ) <EOL> if not env_path : <EOL> env_parent_dir = environ . get ( '<STR_LIT>' ) <EOL> env_paths = environ . get ( '<STR_LIT>' ) <EOL> if env_parent_dir or env_paths : <EOL> path_info = environ . get ( '<STR_LIT>' , '<STR_LIT>' ) . lstrip ( '<STR_LIT:/>' ) . split ( '<STR_LIT:/>' ) <EOL> env_name = path_info . pop ( <NUM_LIT:0> ) <EOL> if not env_name : <EOL> send_project_index ( environ , start_response , env_parent_dir , <EOL> env_paths ) <EOL> return [ ] <EOL> errmsg = None <EOL> script_name = environ . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> try : <EOL> script_name = unicode ( script_name , '<STR_LIT:utf-8>' ) <EOL> environ [ '<STR_LIT>' ] = Href ( script_name ) ( env_name ) <EOL> environ [ '<STR_LIT>' ] = '<STR_LIT:/>' + '<STR_LIT:/>' . join ( path_info ) <EOL> if env_parent_dir : <EOL> env_path = os . path . join ( env_parent_dir , env_name ) <EOL> else : <EOL> env_path = get_environments ( environ ) . get ( env_name ) <EOL> if not env_path or not os . path . isdir ( env_path ) : <EOL> errmsg = '<STR_LIT>' <EOL> except UnicodeDecodeError : <EOL> errmsg = '<STR_LIT>' % script_name <EOL> if errmsg : <EOL> start_response ( '<STR_LIT>' , <EOL> [ ( '<STR_LIT:Content-Type>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , str ( len ( errmsg ) ) ) ] ) <EOL> return [ errmsg ] <EOL> if not env_path : <EOL> raise EnvironmentError ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> run_once = environ [ '<STR_LIT>' ] <EOL> env = env_error = None <EOL> try : <EOL> env = open_environment ( env_path , use_cache = not run_once ) <EOL> if env . base_url_for_redirect : <EOL> environ [ '<STR_LIT>' ] = env . base_url <EOL> if not hasattr ( env , '<STR_LIT>' ) : <EOL> mod_wsgi_version = environ . get ( '<STR_LIT>' ) <EOL> if mod_wsgi_version : <EOL> mod_wsgi_version = ( <EOL> "<STR_LIT>" % <EOL> ( '<STR_LIT:.>' . join ( [ str ( x ) for x in mod_wsgi_version ] ) , <EOL> environ . get ( '<STR_LIT>' ) , <EOL> environ . get ( '<STR_LIT>' ) or <EOL> '<STR_LIT>' ) ) <EOL> environ . update ( { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : mod_wsgi_version } ) <EOL> env . webfrontend = environ . get ( '<STR_LIT>' ) <EOL> if env . webfrontend : <EOL> env . webfrontend_version = environ [ '<STR_LIT>' ] <EOL> except Exception as e : <EOL> env_error = e <EOL> req = RequestWithSession ( environ , start_response ) <EOL> translation . make_activable ( lambda : req . locale , env . path if env else None ) <EOL> try : <EOL> return _dispatch_request ( req , env , env_error ) <EOL> finally : <EOL> translation . deactivate ( ) <EOL> if env and not run_once : <EOL> env . shutdown ( threading . _get_ident ( ) ) <EOL> unreachable = gc . collect ( ) <EOL> def _dispatch_request ( req , env , env_error ) : <EOL> resp = [ ] <EOL> if env and not env . abs_href . base : <EOL> env . abs_href = req . abs_href <EOL> try : <EOL> if not env and env_error : <EOL> raise HTTPInternalError ( env_error ) <EOL> try : <EOL> dispatcher = RequestDispatcher ( env ) <EOL> dispatcher . dispatch ( req ) <EOL> except RequestDone as req_done : <EOL> resp = req_done . iterable <EOL> resp = resp or req . _response or [ ] <EOL> except HTTPException as e : <EOL> _send_user_error ( req , env , e ) <EOL> except Exception : <EOL> send_internal_error ( env , req , sys . exc_info ( ) ) <EOL> return resp <EOL> def _send_user_error ( req , env , e ) : <EOL> if env : <EOL> env . log . warn ( '<STR_LIT>' , req . remote_addr , exception_to_unicode ( e ) ) <EOL> data = { '<STR_LIT:title>' : e . title , '<STR_LIT:type>' : '<STR_LIT>' , '<STR_LIT:message>' : e . message , <EOL> '<STR_LIT>' : [ ] , '<STR_LIT>' : None } <EOL> if e . code == <NUM_LIT> and req . authname == '<STR_LIT>' : <EOL> do_so = tag . a ( _ ( "<STR_LIT>" ) , href = req . href . login ( ) ) <EOL> add_notice ( req , tag_ ( "<STR_LIT>" <EOL> "<STR_LIT>" , do_so = do_so ) ) <EOL> try : <EOL> req . send_error ( sys . exc_info ( ) , status = e . code , env = env , data = data ) <EOL> except RequestDone : <EOL> pass <EOL> def send_internal_error ( env , req , exc_info ) : <EOL> if env : <EOL> env . log . error ( "<STR_LIT>" , <EOL> req , req . environ . get ( '<STR_LIT>' ) , <EOL> exception_to_unicode ( exc_info [ <NUM_LIT:1> ] , traceback = True ) ) <EOL> message = exception_to_unicode ( exc_info [ <NUM_LIT:1> ] ) <EOL> traceback = get_last_traceback ( ) <EOL> frames , plugins , faulty_plugins , interface_custom = [ ] , [ ] , [ ] , [ ] <EOL> th = '<STR_LIT>' <EOL> has_admin = False <EOL> try : <EOL> has_admin = '<STR_LIT>' in req . perm <EOL> except Exception : <EOL> pass <EOL> tracker = default_tracker <EOL> tracker_args = { } <EOL> if has_admin and not isinstance ( exc_info [ <NUM_LIT:1> ] , MemoryError ) : <EOL> frames = get_frame_info ( exc_info [ <NUM_LIT:2> ] ) <EOL> if env : <EOL> plugins = [ p for p in get_plugin_info ( env ) <EOL> if any ( c [ '<STR_LIT>' ] <EOL> for m in p [ '<STR_LIT>' ] . itervalues ( ) <EOL> for c in m [ '<STR_LIT>' ] . itervalues ( ) ) ] <EOL> match_plugins_to_frames ( plugins , frames ) <EOL> faulty_plugins = [ p for p in plugins if '<STR_LIT>' in p ] <EOL> faulty_plugins . sort ( key = lambda p : p [ '<STR_LIT>' ] ) <EOL> if faulty_plugins : <EOL> info = faulty_plugins [ <NUM_LIT:0> ] [ '<STR_LIT:info>' ] <EOL> home_page = info . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if '<STR_LIT>' in info : <EOL> tracker = info [ '<STR_LIT>' ] <EOL> elif urlparse ( home_page ) . netloc == urlparse ( th ) . netloc : <EOL> tracker = th <EOL> plugin_name = info . get ( '<STR_LIT>' , '<STR_LIT>' ) . rstrip ( '<STR_LIT:/>' ) . split ( '<STR_LIT:/>' ) [ - <NUM_LIT:1> ] <EOL> tracker_args = { '<STR_LIT>' : plugin_name } <EOL> interface_custom = Chrome ( env ) . get_interface_customization_files ( ) <EOL> def get_description ( _ ) : <EOL> if env and has_admin : <EOL> sys_info = "<STR_LIT>" . join ( "<STR_LIT>" <EOL> % ( k , v . replace ( '<STR_LIT:\n>' , '<STR_LIT>' ) ) <EOL> for k , v in env . get_systeminfo ( ) ) <EOL> sys_info += "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" <EOL> enabled_plugins = "<STR_LIT>" . join ( "<STR_LIT>" <EOL> % ( p [ '<STR_LIT:name>' ] , p [ '<STR_LIT:version>' ] or _ ( '<STR_LIT>' ) ) <EOL> for p in plugins ) <EOL> files = Chrome ( env ) . get_interface_customization_files ( ) . items ( ) <EOL> interface_files = "<STR_LIT>" . join ( "<STR_LIT>" <EOL> % ( k , "<STR_LIT:U+002CU+0020>" . join ( "<STR_LIT>" % f for f in v ) ) <EOL> for k , v in sorted ( files ) ) <EOL> else : <EOL> sys_info = _ ( "<STR_LIT>" ) <EOL> enabled_plugins = _ ( "<STR_LIT>" ) <EOL> interface_files = _ ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> return _ ( """<STR_LIT>""" , <EOL> method = req . method , path_info = req . path_info , <EOL> req_args = pformat ( req . args ) , sys_info = sys_info , <EOL> enabled_plugins = enabled_plugins , <EOL> interface_customization = interface_files , <EOL> traceback = to_unicode ( traceback ) ) <EOL> description_en = get_description ( lambda s , ** kw : safefmt ( s , kw ) ) <EOL> try : <EOL> description = get_description ( _ ) <EOL> except Exception : <EOL> description = description_en <EOL> data = { '<STR_LIT:title>' : '<STR_LIT>' , <EOL> '<STR_LIT:type>' : '<STR_LIT>' , '<STR_LIT:message>' : message , <EOL> '<STR_LIT>' : traceback , '<STR_LIT>' : frames , <EOL> '<STR_LIT>' : shorten_line , '<STR_LIT>' : safe_repr , <EOL> '<STR_LIT>' : plugins , '<STR_LIT>' : faulty_plugins , <EOL> '<STR_LIT>' : interface_custom , <EOL> '<STR_LIT>' : tracker , '<STR_LIT>' : tracker_args , <EOL> '<STR_LIT:description>' : description , '<STR_LIT>' : description_en } <EOL> Chrome ( env ) . add_jquery_ui ( req ) <EOL> try : <EOL> req . send_error ( exc_info , status = <NUM_LIT> , env = env , data = data ) <EOL> except RequestDone : <EOL> pass <EOL> def send_project_index ( environ , start_response , parent_dir = None , <EOL> env_paths = None ) : <EOL> req = Request ( environ , start_response ) <EOL> loadpaths = [ pkg_resources . resource_filename ( '<STR_LIT>' , '<STR_LIT>' ) ] <EOL> if req . environ . get ( '<STR_LIT>' ) : <EOL> env_index_template = req . environ [ '<STR_LIT>' ] <EOL> tmpl_path , template = os . path . split ( env_index_template ) <EOL> loadpaths . insert ( <NUM_LIT:0> , tmpl_path ) <EOL> else : <EOL> template = '<STR_LIT>' <EOL> data = { '<STR_LIT>' : { '<STR_LIT:version>' : TRAC_VERSION , <EOL> '<STR_LIT:time>' : user_time ( req , format_datetime ) } , <EOL> '<STR_LIT>' : req } <EOL> if req . environ . get ( '<STR_LIT>' ) : <EOL> for pair in req . environ [ '<STR_LIT>' ] . split ( '<STR_LIT:U+002C>' ) : <EOL> key , val = pair . split ( '<STR_LIT:=>' ) <EOL> data [ key ] = val <EOL> try : <EOL> href = Href ( req . base_path ) <EOL> projects = [ ] <EOL> for env_name , env_path in get_environments ( environ ) . items ( ) : <EOL> try : <EOL> env = open_environment ( env_path , <EOL> use_cache = not environ [ '<STR_LIT>' ] ) <EOL> proj = { <EOL> '<STR_LIT>' : env , <EOL> '<STR_LIT:name>' : env . project_name , <EOL> '<STR_LIT:description>' : env . project_description , <EOL> '<STR_LIT>' : href ( env_name ) <EOL> } <EOL> except Exception as e : <EOL> proj = { '<STR_LIT:name>' : env_name , '<STR_LIT:description>' : to_unicode ( e ) } <EOL> projects . append ( proj ) <EOL> projects . sort ( lambda x , y : cmp ( x [ '<STR_LIT:name>' ] . lower ( ) , y [ '<STR_LIT:name>' ] . lower ( ) ) ) <EOL> data [ '<STR_LIT>' ] = projects <EOL> loader = TemplateLoader ( loadpaths , variable_lookup = '<STR_LIT>' , <EOL> default_encoding = '<STR_LIT:utf-8>' ) <EOL> tmpl = loader . load ( template ) <EOL> stream = tmpl . generate ( ** data ) <EOL> if template . endswith ( '<STR_LIT>' ) : <EOL> output = stream . render ( '<STR_LIT>' ) <EOL> req . send ( output , '<STR_LIT>' ) <EOL> else : <EOL> output = stream . render ( '<STR_LIT>' , doctype = DocType . XHTML_STRICT , <EOL> encoding = '<STR_LIT:utf-8>' ) <EOL> req . send ( output , '<STR_LIT>' ) <EOL> except RequestDone : <EOL> pass <EOL> def get_tracignore_patterns ( env_parent_dir ) : <EOL> """<STR_LIT>""" <EOL> path = os . path . join ( env_parent_dir , '<STR_LIT>' ) <EOL> try : <EOL> lines = [ line . strip ( ) for line in read_file ( path ) . splitlines ( ) ] <EOL> except IOError : <EOL> return [ '<STR_LIT>' ] <EOL> return [ line for line in lines if line and not line . startswith ( '<STR_LIT:#>' ) ] <EOL> def get_environments ( environ , warn = False ) : <EOL> """<STR_LIT>""" <EOL> env_paths = environ . get ( '<STR_LIT>' , [ ] ) <EOL> env_parent_dir = environ . get ( '<STR_LIT>' ) <EOL> if env_parent_dir : <EOL> env_parent_dir = os . path . normpath ( env_parent_dir ) <EOL> paths = dircache . listdir ( env_parent_dir ) [ : ] <EOL> dircache . annotate ( env_parent_dir , paths ) <EOL> ignore_patterns = get_tracignore_patterns ( env_parent_dir ) <EOL> paths = [ path [ : - <NUM_LIT:1> ] for path in paths if path [ - <NUM_LIT:1> ] == '<STR_LIT:/>' <EOL> and not any ( fnmatch . fnmatch ( path [ : - <NUM_LIT:1> ] , pattern ) <EOL> for pattern in ignore_patterns ) ] <EOL> env_paths . extend ( os . path . join ( env_parent_dir , project ) <EOL> for project in paths ) <EOL> envs = { } <EOL> for env_path in env_paths : <EOL> env_path = os . path . normpath ( env_path ) <EOL> if not os . path . isdir ( env_path ) : <EOL> continue <EOL> env_name = os . path . split ( env_path ) [ <NUM_LIT:1> ] <EOL> if env_name in envs : <EOL> if warn : <EOL> print ( '<STR_LIT>' <EOL> '<STR_LIT>' % ( env_path , envs [ env_name ] ) , <EOL> file = sys . stderr ) <EOL> else : <EOL> envs [ env_name ] = env_path <EOL> return envs </s>
