diff options
author | VG <vg@devys.org> | 2014-11-28 16:45:09 +0100 |
---|---|---|
committer | VG <vg@devys.org> | 2014-11-28 16:45:09 +0100 |
commit | 3622c92f6c03ef21ea0fbb9a9e75598d2b2581cf (patch) | |
tree | e2bb3fd3545d226f29b1f9b851dff910803db580 /pasteme.py | |
parent | 753f1d95913915f62d3f18c1075ff1ff08db20eb (diff) | |
download | pasteme-3622c92f6c03ef21ea0fbb9a9e75598d2b2581cf.tar.gz pasteme-3622c92f6c03ef21ea0fbb9a9e75598d2b2581cf.tar.bz2 pasteme-3622c92f6c03ef21ea0fbb9a9e75598d2b2581cf.zip |
Add paste save and restore
Diffstat (limited to 'pasteme.py')
-rwxr-xr-x | pasteme.py | 26 |
1 files changed, 23 insertions, 3 deletions
@@ -2,20 +2,40 @@ import bottle import identigen +import config +from pathlib import Path + +pathbase = Path(config.pastedir) + +if not pathbase.exists(): + pathbase.mkdir(mode=0o700, parents=True) @bottle.route('/') def route_root(): - return bottle.template('welcome_page') + return bottle.template('root') @bottle.route('/', method='POST') def route_paste_post(): content = bottle.request.forms.get('content') - return content + ' ' + identigen.generate(content) + pid = identigen.generate(content) + path = pathbase / pid + with path.open(mode='wb') as fd: + fd.write(content.encode('utf8')) + bottle.redirect('/' + pid) @bottle.route('/<pid>') @bottle.route('/<pid>/<pformat>') def route_paste_get(pid, pformat='colored'): - return 'paste: {}, {}'.format(pid, pformat) + if pformat != 'colored' and pformat != 'raw': + return bottle.template('bad_format') + path = pathbase / pid + try: + with path.open() as fd: + content = fd.read() + except IOError: + # use this template for all file based exception + return bottle.template('not_found') + return bottle.template('paste', content=content) if __name__ == '__main__': print('I: Starting application with development server') |