Commits

Tobias Berling committed 0b661c2

PEP8ified paste2.py

Comments (0)

Files changed (1)

 
 DATABASE = '/path/to/sqlite3.db'
 
+
 def connect_db():
     return sqlite3.connect(DATABASE)
 
+
 @app.before_request
 def before_request():
     g.db = connect_db()
 
+
 @app.after_request
 def after_request(response):
     g.db.close()
     return response
 
+
 def query_db(query, args=(), one=False):
     cur = g.db.execute(query, args)
     rv = [dict((cur.description[idx][0], value)
                for idx, value in enumerate(row)) for row in cur.fetchall()]
     return (rv[0] if rv else None) if one else rv
 
+
 def init_db():
     from contextlib import closing
     with closing(connect_db()) as db:
             db.cursor().executescript(f.read())
         db.commit()
 
+
 def make_plain_response(*args, **kwargs):
-    response = make_response(*args,**kwargs)
+    response = make_response(*args, **kwargs)
     response.mimetype = 'text/plain'
     return response
 
+
 def new_key():
     key = ''
     chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
     i = 0
     r = 0
     while i < 4:
-        n = random.randint(0,35)
+        n = random.randint(0, 35)
         key += chars[n]
-        i+=1
+        i += 1
     return key
 
+
 @app.route('/', methods=['GET'])
 def help():
     return "nothing to see here\n"
 
+
 @app.route('/favicon.ico')
 def favicon():
     abort(404)
 
+
 @app.route('/', methods=['POST'])
 def post():
     content = request.form.get('content', '')
             abort(500)
 
     g.db.execute("""
-        INSERT INTO entries (key, content, created)  
+        INSERT INTO entries (key, content, created)
         VALUES(?, ?, datetime('now'))
         """, [key, content])
     g.db.commit()
 
     return make_plain_response(" %s%s\n" % (request.url_root, key))
 
+
 @app.route('/<key>')
 def get(key):
     a = request.args
-    content = query_db('SELECT content FROM entries WHERE key = ?', 
-                       [key], 
+    content = query_db('SELECT content FROM entries WHERE key = ?',
+                       [key],
                        one=True)
     if not content:
-        abort(404) 
+        abort(404)
 
     content = content['content']
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.