M README.md +1 -1
@@ 8,7 8,7 @@ stacktraces](https://idle.nprescott.com/
A version is hosted at [glue.nprescott.com](https://glue.nprescott.com).
This iteration (the 3rd) of glue-boy is built on
-[Klein](https://github.com/twisted/klein), sqlite and Python 3.
+[Klein](https://github.com/twisted/klein), SQLite and Python 3.
## Installation
```
R cleanup.sh => +0 -4
@@ 1,4 0,0 @@
-#!/bin/sh
-
-echo "DELETE FROM glues WHERE julianday('now') - julianday(last_accessed) > 7;" | sqlite3 glues.sqlite
-echo "vacuum;" | sqlite3 glues.sqlite
R requirements.txt => +0 -10
@@ 1,10 0,0 @@
-attrs==17.2.0
-Automat==0.6.0
-constantly==15.1.0
-hyperlink==17.2.1
-incremental==17.5.0
-klein==17.2.0
-six==1.10.0
-Twisted==17.5.0
-Werkzeug==0.12.2
-zope.interface==4.4.2
M setup.py +3 -0
@@ 5,4 5,7 @@ setup(
install_requires=["Klein", "Twisted"],
package_dir={"": "src"},
packages=find_packages() + ['twisted.plugins'],
+ extras_require={
+ 'dev': ['treq']
+ }
)
M src/glue_boy/_service.py +35 -1
@@ 1,2 1,36 @@
+from klein import Klein
+
class PasteBin:
- pass
+ _db = GluesDatabase()
+ _app = Klein()
+
+ def resource(self):
+ return self._app.resouce()
+
+ @_app.route('/', methods=['GET', 'POST'])
+ def new_paste(self, request):
+ if request.method == b'GET':
+ # hack to get around: https://github.com/twisted/klein/issues/41
+ f = File('./')
+ f.indexNames = ['index.html']
+ return f
+ elif request.method == b'POST':
+ content, *_ = request.args[b'content']
+ d = ensureDeferred(self.db.write_paste(content))
+ d.addCallback(
+ lambda paste_id: request.redirect(f'./content/{paste_id}'))
+ return d
+
+ @app.route('/content/<paste_id>', methods=['GET'])
+ def existing_paste(self, request, paste_id):
+ request.setHeader('Content-Type', 'text/plain; charset=utf-8')
+ return self.db.get_paste(paste_id)
+
+ @app.handle_errors(NotFound)
+ def not_found(self, request, failure):
+ '''
+ error handling is ... funny, the name of this function doesn't matter
+ because it is resolving through the decorator (by exception type)
+ '''
+ request.setResponseCode(404)
+ return 'Not Found'
M src/glue_boy/test/test_glue_boy.py +4 -0
@@ 1,5 1,9 @@
from twisted.trial.unittest import SynchronousTestCase
+from .. import PasteBin
class PasteBinTests(SynchronousTestCase):
+ def setUp(self):
+ pass
+
def test_nothing(self):
pass