From 753f1d95913915f62d3f18c1075ff1ff08db20eb Mon Sep 17 00:00:00 2001 From: VG Date: Fri, 28 Nov 2014 00:15:19 +0100 Subject: add hash generation from content, and default page display --- .gitignore | 2 ++ bottle.py | 1 + identigen.py | 34 ++++++++++++++++++++++++++++++++++ pasteme.py | 25 +++++++++++++++++++++++++ readme.rst | 17 ++++++++++++++++- views/welcome_page.tpl | 19 +++++++++++++++++++ 6 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 120000 bottle.py create mode 100644 identigen.py create mode 100755 pasteme.py create mode 100644 views/welcome_page.tpl 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('/') +@bottle.route('//') +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 diff --git a/readme.rst b/readme.rst index abba2e8..9108a99 100644 --- a/readme.rst +++ b/readme.rst @@ -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 @@ + + +Paste snippets + + + +You are on a simple paste deposit service. + +Please copy your text on the box below: + +
+ + + + +
+ + + -- cgit v1.2.3