<s> import os <EOL> import mimetypes <EOL> mimetypes . add_type ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> mimetypes . add_type ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> from zope . structuredtext import stx2html <EOL> from pyramid . response import Response <EOL> from pyramid . httpexceptions import HTTPFound <EOL> from pyramid . view import render_view_to_response <EOL> from pyramid . view import view_config <EOL> from virginia . models import File <EOL> from virginia . models import Directory <EOL> @ view_config ( context = File ) <EOL> def file_view ( context , request ) : <EOL> dirname , filename = os . path . split ( context . path ) <EOL> name , ext = os . path . splitext ( filename ) <EOL> result = render_view_to_response ( context , request , ext ) <EOL> return result <EOL> @ view_config ( context = Directory ) <EOL> def directory_view ( context , request ) : <EOL> path_info = request . environ [ '<STR_LIT>' ] <EOL> if not path_info . endswith ( '<STR_LIT:/>' ) : <EOL> response = HTTPFound ( location = path_info + '<STR_LIT:/>' ) <EOL> return response <EOL> defaults = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> for name in defaults : <EOL> try : <EOL> index = context [ name ] <EOL> except KeyError : <EOL> continue <EOL> return file_view ( index , request ) <EOL> response = Response ( '<STR_LIT>' % context . path ) <EOL> response . content_type = '<STR_LIT>' <EOL> return response <EOL> @ view_config ( context = File , name = '<STR_LIT>' ) <EOL> def structured_text_view ( context , request ) : <EOL> """<STR_LIT>""" <EOL> result = stx2html ( context . source ) <EOL> response = Response ( result ) <EOL> response . content_type = '<STR_LIT>' <EOL> return response <EOL> @ view_config ( context = File , name = '<STR_LIT>' ) <EOL> @ view_config ( context = File , name = '<STR_LIT>' ) <EOL> @ view_config ( context = File , name = '<STR_LIT>' ) <EOL> @ view_config ( context = File , name = '<STR_LIT>' ) <EOL> def raw_view ( context , request ) : <EOL> """<STR_LIT>""" <EOL> response = Response ( context . source ) <EOL> dirname , filename = os . path . split ( context . path ) <EOL> name , ext = os . path . splitext ( filename ) <EOL> mt , encoding = mimetypes . guess_type ( filename ) <EOL> response . content_type = mt or '<STR_LIT>' <EOL> return response </s>
