<s> import os <EOL> import mimetypes <EOL> from giotto import get_config <EOL> from giotto . programs import Program <EOL> from giotto . views import GiottoView , renders <EOL> from giotto . utils import super_accept_to_mimetype <EOL> from giotto . exceptions import DataNotFound <EOL> from giotto . primitives import RAW_INVOCATION_ARGS <EOL> class FileView ( GiottoView ) : <EOL> def render ( self , result , mimetype , errors ) : <EOL> return super ( FileView , self ) . render ( result , "<STR_LIT>" , errors ) <EOL> @ renders ( '<STR_LIT>' ) <EOL> def any ( self , result ) : <EOL> return { '<STR_LIT:body>' : result [ <NUM_LIT:0> ] , '<STR_LIT>' : result [ <NUM_LIT:1> ] } <EOL> @ renders ( '<STR_LIT>' ) <EOL> def cmd ( self , result ) : <EOL> return { '<STR_LIT:body>' : result . read ( ) , '<STR_LIT>' : '<STR_LIT>' } <EOL> def StaticServe ( base_path = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> def get_file ( path = RAW_INVOCATION_ARGS ) : <EOL> fullpath = get_config ( '<STR_LIT>' ) + os . path . join ( base_path , path ) <EOL> try : <EOL> mime , encoding = mimetypes . guess_type ( fullpath ) <EOL> return open ( fullpath , '<STR_LIT:rb>' ) , mime or '<STR_LIT>' <EOL> except IOError : <EOL> raise DataNotFound ( "<STR_LIT>" ) <EOL> class StaticServe ( Program ) : <EOL> controllers = [ '<STR_LIT>' ] <EOL> model = [ get_file ] <EOL> view = FileView ( ) <EOL> return StaticServe ( ) <EOL> def SingleStaticServe ( file_path ) : <EOL> """<STR_LIT>""" <EOL> def get_file ( ) : <EOL> mime , encoding = mimetypes . guess_type ( file_path ) <EOL> fullpath = os . path . join ( get_config ( '<STR_LIT>' ) , file_path ) <EOL> return open ( fullpath , '<STR_LIT:rb>' ) , mime or '<STR_LIT>' <EOL> class SingleStaticServe ( Program ) : <EOL> controllers = [ '<STR_LIT>' ] <EOL> model = [ get_file ] <EOL> view = FileView ( ) <EOL> return SingleStaticServe ( ) </s>
