class Pastebin(WebApplication): def __init__(self, global_config, database_url, **local_config): # Paster app_factory entry point. The configuration entries from # the application config file will be passed in via local_config, # keyword parameters, and global_config. self.paste_store = PasteStore(database_url) @get('/') @template('index.mako') def index(self, request): return dict( latest=self.paste_store.latest() ) @post('/') def new_paste(self, request): author = request.form['author'] body = request.form['body'] syntax = request.form['syntax'] paste = self.paste_store.new(author, body, syntax) return redirect( request.url_adapter.build( 'paste', values=dict(id=paste.id), method='GET' ), code=303 ) @get('/<id>') @template('paste.mako') def paste(self, request, id): try: return dict( latest=self.paste_store.latest(), paste=self.paste_store.get(id) ) except KeyError: raise NotFound @get('/styles/syntax/<name>') def syntax_styles(self, request, name): try: return Response( css_stylesheet(name), mimetype='text/css' ) except ClassNotFound: raise NotFound @get('/styles/<path>') def static_content(self, request, path): return shared_data
class Pastebin(WebApplication): def __init__(self, global_config, database_url, **local_config): # Paster app_factory entry point. The configuration entries from # the application config file will be passed in via local_config, # keyword parameters, and global_config. self.paste_store = PasteStore(database_url) @get('/') @template('index.mako') def index(self, request): return dict(latest=self.paste_store.latest()) @post('/') def new_paste(self, request): author = request.form['author'] body = request.form['body'] syntax = request.form['syntax'] paste = self.paste_store.new(author, body, syntax) return redirect(request.url_adapter.build('paste', values=dict(id=paste.id), method='GET'), code=303) @get('/<id>') @template('paste.mako') def paste(self, request, id): try: return dict(latest=self.paste_store.latest(), paste=self.paste_store.get(id)) except KeyError: raise NotFound @get('/styles/syntax/<name>') def syntax_styles(self, request, name): try: return Response(css_stylesheet(name), mimetype='text/css') except ClassNotFound: raise NotFound @get('/styles/<path>') def static_content(self, request, path): return shared_data
def __init__(self, global_config, database_url, **local_config): # Paster app_factory entry point. The configuration entries from # the application config file will be passed in via local_config, # keyword parameters, and global_config. self.paste_store = PasteStore(database_url)