diff options
-rw-r--r-- | .gitignore | 2 | ||||
l--------- | bottle.py | 1 | ||||
-rw-r--r-- | identigen.py | 34 | ||||
-rwxr-xr-x | pasteme.py | 25 | ||||
-rw-r--r-- | readme.rst | 17 | ||||
-rw-r--r-- | views/welcome_page.tpl | 19 |
6 files changed, 97 insertions, 1 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a295864 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.pyc +__pycache__ diff --git a/bottle.py b/bottle.py new file mode 120000 index 0000000..ccf120b --- /dev/null +++ b/bottle.py @@ -0,0 +1 @@ +bottle/bottle.py
\ No newline at end of file diff --git a/identigen.py b/identigen.py new file mode 100644 index 0000000..496d8e0 --- /dev/null +++ b/identigen.py @@ -0,0 +1,34 @@ +import string +import hashlib + +SYLLABUS = ( [ x for x in string.ascii_lowercase if x not in 'aeiouy' ], + [ 'a', 'e', 'i', 'o', 'u', 'y', + 'ai', 'au', 'eu', 'ay', 'ao', 'ay', + 'ey', 'ei', 'eo', 'ou', 'ia', 'io', + 'ua', 'ui' ]) + +def translate(hsh, syllabus=SYLLABUS): + """ + Return a human lisible hash + """ + result = "" + + if len(hsh) % 2 == 1: + hsh = '0' + hsh + + while hsh: + val = int(hsh[0:2], 16) + hsh = hsh[2:] + + result += syllabus[0][val // 20] + result += syllabus[1][val % 20] + + return result + +def generate(content, minsize=8): + return translate( + hashlib.md5(content.encode('utf8')).hexdigest()[0:minsize]) + +if __name__ == '__main__': + import sys + print(generate(sys.argv[1])) diff --git a/pasteme.py b/pasteme.py new file mode 100755 index 0000000..37f4522 --- /dev/null +++ b/pasteme.py @@ -0,0 +1,25 @@ +#!/usr/bin/python3 + +import bottle +import identigen + +@bottle.route('/') +def route_root(): + return bottle.template('welcome_page') + +@bottle.route('/', method='POST') +def route_paste_post(): + content = bottle.request.forms.get('content') + return content + ' ' + identigen.generate(content) + +@bottle.route('/<pid>') +@bottle.route('/<pid>/<pformat>') +def route_paste_get(pid, pformat='colored'): + return 'paste: {}, {}'.format(pid, pformat) + +if __name__ == '__main__': + print('I: Starting application with development server') + bottle.run(host='0.0.0.0', port=8080, debug=True, reloader=True) +else: + print('I: Starting application as a wsgi application') + application = bottle.default_app() # application used for wsgi mode @@ -3,7 +3,7 @@ Description WARNING: WIP ! -A simple pastebin like service implemented in python with bottle. +A simple pastebin like service implemented in python3 with bottle. The pastes storage backend are simple files. @@ -13,3 +13,18 @@ It features the following: - Simple and short urls (easy to copy by hands) - Automatic purge of old pastes (1 month by default) - Simple and nice theme. + +It can be used directly (more for development) or from a wsgi compatible +web server. + +Installation +============ + +Clone this repository recursively: + +.. code: shell + + git clone --recusive git://git.devys.org/pasteme + cd pasteme + # to run it with dev mode, just run it + ./pastme.py diff --git a/views/welcome_page.tpl b/views/welcome_page.tpl new file mode 100644 index 0000000..53c6393 --- /dev/null +++ b/views/welcome_page.tpl @@ -0,0 +1,19 @@ +<html> +<head> +<title>Paste snippets</title> +</head> +<body> + +You are on a simple paste deposit service. + +Please copy your text on the box below: + +<form action="/" method="POST"> + +<textarea id="content" name="content"></textarea> + +<button for="content">Paste</button> +</form> + +</body> +</html> |