pep8: fix indentation to be a multiple of four

note: i used pycharm "reformat file", so there are other reformattings also
This commit is contained in:
Thomas Waldmann 2014-11-18 18:03:34 +01:00
parent d51f762ddd
commit 5deb3f9e0f
2 changed files with 38 additions and 17 deletions

View file

@ -28,6 +28,8 @@ app = Flask(__name__)
file_info = []
zip_filename = None
zip_filesize = None
def set_file_info(filenames):
global file_info, zip_filename, zip_filesize
@ -59,6 +61,7 @@ def set_file_info(filenames):
zip_filename = z.zip_filename
zip_filesize = os.path.getsize(zip_filename)
REQUEST_LOAD = 0
REQUEST_DOWNLOAD = 1
REQUEST_PROGRESS = 2
@ -66,6 +69,7 @@ REQUEST_OTHER = 3
REQUEST_CANCELED = 4
q = Queue.Queue()
def add_request(type, path, data=None):
global q
q.put({
@ -74,16 +78,22 @@ def add_request(type, path, data=None):
'data': data
})
slug = helpers.random_string(16)
download_count = 0
stay_open = False
def set_stay_open(new_stay_open):
global stay_open
stay_open = new_stay_open
def get_stay_open():
return stay_open
def debug_mode():
import logging
@ -96,6 +106,7 @@ def debug_mode():
log_handler.setLevel(logging.WARNING)
app.logger.addHandler(log_handler)
@app.route("/<slug_candidate>")
def index(slug_candidate):
if not helpers.constant_time_compare(slug.encode('ascii'), slug_candidate.encode('ascii')):
@ -112,6 +123,7 @@ def index(slug_candidate):
strings=strings.strings
)
@app.route("/<slug_candidate>/download")
def download(slug_candidate):
global download_count
@ -150,7 +162,8 @@ def download(slug_candidate):
# tell GUI the progress
downloaded_bytes = fp.tell()
percent = round((1.0 * downloaded_bytes / zip_filesize) * 100, 2)
sys.stdout.write("\r{0}, {1}% ".format(helpers.human_readable_filesize(downloaded_bytes), percent))
sys.stdout.write(
"\r{0}, {1}% ".format(helpers.human_readable_filesize(downloaded_bytes), percent))
sys.stdout.flush()
add_request(REQUEST_PROGRESS, path, {'id': download_id, 'bytes': downloaded_bytes})
except:
@ -181,6 +194,7 @@ def download(slug_candidate):
r.headers.add('Content-Type', content_type)
return r
@app.errorhandler(404)
def page_not_found(e):
add_request(REQUEST_OTHER, request.path)
@ -188,6 +202,8 @@ def page_not_found(e):
# shutting down the server only works within the context of flask, so the easiest way to do it is over http
shutdown_slug = helpers.random_string(16)
@app.route("/<shutdown_slug_candidate>/shutdown")
def shutdown(shutdown_slug_candidate):
if not helpers.constant_time_compare(shutdown_slug.encode('ascii'), shutdown_slug_candidate.encode('ascii')):
@ -201,16 +217,19 @@ def shutdown(shutdown_slug_candidate):
return ""
def start(port, stay_open=False):
set_stay_open(stay_open)
app.run(port=port, threaded=True)
def stop(port):
# to stop flask, load http://127.0.0.1:<port>/<shutdown_slug>/shutdown
if helpers.get_platform() == 'Tails':
# in Tails everything is proxies over Tor, so we need to get lower level
# to connect not over the proxy
import socket
s = socket.socket()
s.connect(('127.0.0.1', port))
s.sendall('GET /{0}/shutdown HTTP/1.1\r\n\r\n'.format(shutdown_slug))

View file

@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
import tempfile
class MockSubprocess():
def __init__(self):
self.last_call = None
@ -28,6 +29,7 @@ class MockSubprocess():
def last_call_args(self):
return self.last_call
def write_tempfile(text):
tempdir = tempfile.mkdtemp()
path = tempdir + "/test-file.txt"