diff options
-rw-r--r-- | config.py | 3 | ||||
-rwxr-xr-x | pasteme.py | 26 | ||||
-rw-r--r-- | views/bad_format.tpl | 10 | ||||
-rw-r--r-- | views/not_fount.tpl | 16 | ||||
-rw-r--r-- | views/paste.tpl | 8 | ||||
-rw-r--r-- | views/root.tpl (renamed from views/welcome_page.tpl) | 0 |
6 files changed, 60 insertions, 3 deletions
diff --git a/config.py b/config.py new file mode 100644 index 0000000..4454890 --- /dev/null +++ b/config.py @@ -0,0 +1,3 @@ +# configuration file of pastme service + +pastedir = '/tmp/pastes' @@ -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') diff --git a/views/bad_format.tpl b/views/bad_format.tpl new file mode 100644 index 0000000..6efdab8 --- /dev/null +++ b/views/bad_format.tpl @@ -0,0 +1,10 @@ +<html> +<head> +<title>Bad paste format requested</title> +</head> +<body> +<h2>Hello</h2> +<p>I do not understand the format you are trying to get for the past +requested. Please try again with either <i>colored</i> or <i>raw</i></p> +</body> +</html> diff --git a/views/not_fount.tpl b/views/not_fount.tpl new file mode 100644 index 0000000..50a41db --- /dev/null +++ b/views/not_fount.tpl @@ -0,0 +1,16 @@ +<html> +<head> +<title>Paste not available</title> +</head> +<body> +<h2>Hello</h2> +<p>I wanted to display you a paste, but I did not find it. There can be two +reason for this:</p> +<ul> + <li>Either the paste expired</li> + <li>Or the paste never existed (the <b>URL</b> might be wrong)<li> +</ul> + +<p>I'm sorry for you, but <i>nonetheless</i> I whish you a very good day.</p> +</body> +</html> diff --git a/views/paste.tpl b/views/paste.tpl new file mode 100644 index 0000000..99fad8c --- /dev/null +++ b/views/paste.tpl @@ -0,0 +1,8 @@ +<html> +<head> +<title>Paste snippets</title> +</head> +<body> +{{content}} +</body> +</html> diff --git a/views/welcome_page.tpl b/views/root.tpl index 53c6393..53c6393 100644 --- a/views/welcome_page.tpl +++ b/views/root.tpl |