2012-04-24 14:22:59 +04:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
import os
|
2012-04-24 22:15:38 +04:00
|
|
|
import hashlib
|
|
|
|
import sys
|
2012-04-24 14:22:59 +04:00
|
|
|
|
2012-04-24 22:15:38 +04:00
|
|
|
from bottle import (Bottle, route, run, static_file, debug, view, request)
|
2012-04-24 14:22:59 +04:00
|
|
|
|
2012-04-24 22:15:38 +04:00
|
|
|
import settings
|
2012-04-24 14:22:59 +04:00
|
|
|
|
2012-04-24 22:15:38 +04:00
|
|
|
# ensure we got the project module on the python path to avoid import problems
|
|
|
|
sys.path.insert(0, os.path.dirname(settings.ROOT_DIR))
|
2012-04-24 14:22:59 +04:00
|
|
|
|
2012-04-24 22:15:38 +04:00
|
|
|
from src.paste import Paste
|
|
|
|
|
|
|
|
app = Bottle()
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/')
|
2012-04-24 14:22:59 +04:00
|
|
|
@view('home')
|
|
|
|
def index():
|
|
|
|
return {}
|
|
|
|
|
|
|
|
|
2012-04-24 22:15:38 +04:00
|
|
|
@app.route('/paste/create', method='POST')
|
|
|
|
def create_paste():
|
|
|
|
|
|
|
|
try:
|
|
|
|
content = unicode(request.forms.get('content', ''), 'utf8')
|
|
|
|
except UnicodeDecodeError:
|
|
|
|
content = u''
|
|
|
|
|
|
|
|
if content:
|
|
|
|
expire_in = request.forms.get('expire_in', u'burn_after_reading')
|
|
|
|
paste = Paste(expire_in=expire_in, content=content)
|
|
|
|
paste.save()
|
|
|
|
|
|
|
|
return paste.uuid
|
|
|
|
|
|
|
|
return ''
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/static/<filename:re:.*>')
|
2012-04-24 14:22:59 +04:00
|
|
|
def server_static(filename):
|
2012-04-24 22:15:38 +04:00
|
|
|
return static_file(filename, root=settings.STATIC_FILES_ROOT)
|
2012-04-24 14:22:59 +04:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2012-04-24 22:15:38 +04:00
|
|
|
if settings.DEBUG:
|
2012-04-24 14:22:59 +04:00
|
|
|
debug(True)
|
2012-04-24 22:15:38 +04:00
|
|
|
run(app, host='localhost', port=8080, reloader=True)
|
2012-04-24 14:22:59 +04:00
|
|
|
else:
|
2012-04-24 22:15:38 +04:00
|
|
|
run(app, host='localhost', port=8080)
|