<s> import logging <EOL> import genshi <EOL> from shakespeare . lib . base import * <EOL> log = logging . getLogger ( __name__ ) <EOL> class OurResourceController ( BaseController ) : <EOL> def index ( self ) : <EOL> return '<STR_LIT>' <EOL> def view ( self , id ) : <EOL> res = model . Resource . query . get ( id ) <EOL> if not res : <EOL> abort ( <NUM_LIT> ) <EOL> if res . material : <EOL> c . title = res . material . title <EOL> else : <EOL> c . title = '<STR_LIT>' <EOL> c . work = res . material . work <EOL> c . texthtml = genshi . HTML ( render_resource ( res ) ) <EOL> return render ( '<STR_LIT>' ) <EOL> import os <EOL> import shakespeare . format <EOL> def render_resource ( res ) : <EOL> if res . format == '<STR_LIT>' : <EOL> tfileobj = res . get_stream ( ) <EOL> ttext = h . markdown ( tfileobj . read ( ) ) <EOL> elif res . format == '<STR_LIT>' : <EOL> tfileobj = res . get_stream ( ) <EOL> ttext = shakespeare . format . format_text ( tfileobj , format = '<STR_LIT>' ) <EOL> elif res . format == '<STR_LIT>' : <EOL> ttext = '<STR_LIT>' % h . url_for ( '<STR_LIT>' , <EOL> url = os . path . basename ( res . locator ) ) <EOL> elif res . format == '<STR_LIT:html>' : <EOL> tfileobj = res . get_stream ( ) <EOL> ttext = tfileobj . read ( ) <EOL> else : <EOL> raise Exception ( '<STR_LIT>' ) <EOL> return ttext </s>
