<s> import jinja2 <EOL> import flask <EOL> import httpauth <EOL> import dulwich . web <EOL> from klaus import views , utils <EOL> from klaus . repo import FancyRepo <EOL> KLAUS_VERSION = utils . guess_git_revision ( ) or '<STR_LIT>' <EOL> class Klaus ( flask . Flask ) : <EOL> jinja_options = { <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : jinja2 . StrictUndefined <EOL> } <EOL> def __init__ ( self , repo_paths , site_name , use_smarthttp , ctags_policy = '<STR_LIT:none>' ) : <EOL> """<STR_LIT>""" <EOL> repo_objs = [ FancyRepo ( path ) for path in repo_paths ] <EOL> self . repos = dict ( ( repo . name , repo ) for repo in repo_objs ) <EOL> self . site_name = site_name <EOL> self . use_smarthttp = use_smarthttp <EOL> self . ctags_policy = ctags_policy <EOL> flask . Flask . __init__ ( self , __name__ ) <EOL> self . setup_routes ( ) <EOL> def create_jinja_environment ( self ) : <EOL> """<STR_LIT>""" <EOL> env = super ( Klaus , self ) . create_jinja_environment ( ) <EOL> for func in [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] : <EOL> env . filters [ func ] = getattr ( utils , func ) <EOL> env . globals [ '<STR_LIT>' ] = KLAUS_VERSION <EOL> env . globals [ '<STR_LIT>' ] = self . use_smarthttp <EOL> env . globals [ '<STR_LIT>' ] = self . site_name <EOL> return env <EOL> def setup_routes ( self ) : <EOL> for endpoint , rule in [ <EOL> ( '<STR_LIT>' , '<STR_LIT:/>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ] : <EOL> self . add_url_rule ( rule , view_func = getattr ( views , endpoint ) ) <EOL> def should_use_ctags ( self , git_repo , git_commit ) : <EOL> if self . ctags_policy == '<STR_LIT:none>' : <EOL> return False <EOL> elif self . ctags_policy == '<STR_LIT>' : <EOL> return True <EOL> elif self . ctags_policy == '<STR_LIT>' : <EOL> return git_commit . id in git_repo . get_tag_and_branch_shas ( ) <EOL> else : <EOL> raise ValueError ( "<STR_LIT>" % self . ctags_policy ) <EOL> def make_app ( repo_paths , site_name , use_smarthttp = False , htdigest_file = None , <EOL> require_browser_auth = False , disable_push = False , unauthenticated_push = False , <EOL> ctags_policy = '<STR_LIT:none>' ) : <EOL> """<STR_LIT>""" <EOL> if unauthenticated_push : <EOL> if not use_smarthttp : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if disable_push : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if require_browser_auth : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if htdigest_file and not ( require_browser_auth or use_smarthttp ) : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> app = Klaus ( <EOL> repo_paths , <EOL> site_name , <EOL> use_smarthttp , <EOL> ctags_policy , <EOL> ) <EOL> app . wsgi_app = utils . ProxyFix ( app . wsgi_app ) <EOL> if use_smarthttp : <EOL> dulwich_backend = dulwich . server . DictBackend ( <EOL> dict ( ( '<STR_LIT:/>' + name , repo ) for name , repo in app . repos . items ( ) ) <EOL> ) <EOL> dulwich_wrapped_app = dulwich . web . make_wsgi_chain ( <EOL> backend = dulwich_backend , <EOL> fallback_app = app . wsgi_app , <EOL> ) <EOL> dulwich_wrapped_app = utils . ProxyFix ( dulwich_wrapped_app ) <EOL> PATTERN = r'<STR_LIT>' <EOL> if unauthenticated_push : <EOL> app . wsgi_app = dulwich_wrapped_app <EOL> elif htdigest_file and not disable_push : <EOL> if require_browser_auth : <EOL> app . wsgi_app = dulwich_wrapped_app <EOL> else : <EOL> app . wsgi_app = httpauth . DigestFileHttpAuthMiddleware ( <EOL> htdigest_file , <EOL> wsgi_app = dulwich_wrapped_app , <EOL> routes = [ PATTERN ] , <EOL> ) <EOL> else : <EOL> app . wsgi_app = httpauth . AlwaysFailingAuthMiddleware ( <EOL> wsgi_app = dulwich_wrapped_app , <EOL> routes = [ PATTERN ] , <EOL> ) <EOL> if require_browser_auth : <EOL> app . wsgi_app = httpauth . DigestFileHttpAuthMiddleware ( <EOL> htdigest_file , <EOL> wsgi_app = app . wsgi_app <EOL> ) <EOL> return app </s>
