1
0
mirror of https://github.com/Tygs/0bin.git synced 2023-08-10 21:13:00 +03:00

Python code passed linter

This commit is contained in:
sam 2012-05-12 10:33:01 +02:00
parent 2b2ab65b73
commit 53a7b886fe
6 changed files with 18 additions and 25 deletions

View File

@ -19,7 +19,7 @@ PASTE_FILES_ROOT = os.path.join(STATIC_FILES_ROOT, 'content')
# You can also specify them using the --host and --port script options
# which have priority on these settings
HOST = "127.0.0.1"
PORT= "8000"
PORT = "8000"
# User and group the server should run as. Set to None if it should be the
# current user. Some OS don't support it and if so, it will be ignored.

View File

@ -21,7 +21,7 @@ PASTE_FILES_ROOT = os.path.join(STATIC_FILES_ROOT, 'content')
# You can also specify them using the --host and --port script options
# which have priority on these settings
HOST = "127.0.0.1"
PORT= "8000"
PORT = "8000"
# User and group the server should run as. Set to None if it should be the
# current user. Some OS don't support it and if so, it will be ignored.
@ -40,4 +40,3 @@ MENU = (
# browser
MAX_SIZE = 1024 * 500
MAX_SIZE_KB = int(math.ceil(MAX_SIZE / 1024.0))

View File

@ -33,7 +33,7 @@ class Paste(object):
self.comments = comments
if isinstance(self.content, unicode):
self.content = self.content.encode('utf8')
self.content = self.content.encode('utf8')
self.expiration = self.get_expiration(expiration)
@ -97,7 +97,7 @@ class Paste(object):
content = paste.next().strip()
comments = paste.read()[:-1] # remove the last coma
if "burn_after_reading" not in str(expiration):
expiration = datetime.strptime(expiration,'%Y-%m-%d %H:%M:%S.%f')
expiration = datetime.strptime(expiration, '%Y-%m-%d %H:%M:%S.%f')
except StopIteration:
raise TypeError(u'File %s is malformed' % path)
@ -153,13 +153,13 @@ class Paste(object):
if self.expiration == "burn_after_reading":
self.expiration = self.expiration + '#%s' % datetime.now()
# write the paste
# write the paste
with open(self.path, 'w') as f:
f.write(unicode(self.expiration) + '\n')
f.write(self.content + '\n')
if self.comments:
f.write(comments)
f.write(self.comments)
return self

View File

@ -1,9 +1,7 @@
# -*- coding: utf-8 -*-
import time
import sys
import os
import settings
import glob
import tempfile
@ -28,8 +26,8 @@ def drop_privileges(user=None, group=None, wait=5):
user = coerce_user(user)
group = coerce_group(group)
lock_files = glob.glob(os.path.join(tempfile.gettempdir(),
'bottle.*.lock'))
lock_files = glob.glob(os.path.join(tempfile.gettempdir(),
'bottle.*.lock'))
for lock_file in lock_files:
os.chown(lock_file, user, group)

View File

@ -9,9 +9,7 @@
import sys
import os
import hashlib
import thread
import math
from datetime import datetime, timedelta
@ -22,8 +20,7 @@ sys.path.insert(0, os.path.dirname(settings.ROOT_DIR))
sys.path.append(os.path.join(settings.ROOT_DIR, 'libs'))
import bottle
from bottle import (Bottle, route, run, abort, error,
static_file, debug, view, request)
from bottle import (Bottle, run, static_file, view, request)
import clize
@ -34,13 +31,14 @@ from src.utils import drop_privileges, dmerge
app = Bottle()
global_vars = {
'settings' : settings
global_vars = {
'settings': settings
}
@app.route('/')
@view('home')
def index():
def index():
return global_vars
@ -75,7 +73,6 @@ def create_paste():
@view('paste')
def display_paste(paste_id):
now = datetime.now()
keep_alive = False
try:
@ -88,7 +85,7 @@ def display_paste(paste_id):
# to the paste that happens during the paste creation
try:
keep_alive = paste.expiration.split('#')[1]
keep_alive = datetime.strptime(keep_alive,'%Y-%m-%d %H:%M:%S.%f')
keep_alive = datetime.strptime(keep_alive, '%Y-%m-%d %H:%M:%S.%f')
keep_alive = now < keep_alive + timedelta(seconds=10)
except IndexError:
keep_alive = False
@ -106,11 +103,13 @@ def display_paste(paste_id):
context = {'paste': paste, 'keep_alive': keep_alive}
return dmerge(context, global_vars)
@app.error(404)
@view('404')
def error404(code):
return global_vars
@clize.clize
def runserver(host=settings.HOST, port=settings.PORT, debug=settings.DEBUG,
serve_static=settings.DEBUG, user=settings.USER,
@ -131,8 +130,5 @@ def runserver(host=settings.HOST, port=settings.PORT, debug=settings.DEBUG,
if __name__ == "__main__":
clize.run(runserver)

View File

@ -1,4 +1,4 @@
/*global sjcl:true, jQuery:true, $:true, lzw:true, zerobin:true, ZeroClipboard:true, vizhash:true, prettyPrint:true */
/*global sjcl:true, jQuery:true, $:true, lzw:true, zerobin:true, ZeroClipboard:true, vizhash:true, prettyPrint:true, confirm:true */
;(function(){
"use strict";