From f162ae0de0f71391c56957389cc3c8babc8022e1 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sun, 19 Apr 2015 16:37:00 +0200 Subject: Use with statement --- pyload/webui/app/json.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'pyload/webui/app/json.py') diff --git a/pyload/webui/app/json.py b/pyload/webui/app/json.py index 12dce2484..d4af40dee 100644 --- a/pyload/webui/app/json.py +++ b/pyload/webui/app/json.py @@ -1,5 +1,7 @@ # -*- coding: utf-8 -*- +from __future__ import with_statement + from os.path import join from traceback import print_exc from shutil import copyfileobj @@ -166,9 +168,8 @@ def add_package(): name = f.name fpath = join(PYLOAD.getConfigValue("general", "download_folder"), "tmp_" + f.filename) - destination = open(fpath, 'wb') - copyfileobj(f.file, destination) - destination.close() + with open(fpath, 'wb') as destination: + copyfileobj(f.file, destination) links.insert(0, fpath) except Exception: pass -- cgit v1.2.3 From 1e2e91091664c2fca6a187804b2041eab757dbe3 Mon Sep 17 00:00:00 2001 From: fedeG Date: Mon, 20 Apr 2015 22:01:18 +0200 Subject: PEP-8, Python Zen, refactor and reduce code (part 15 in master module/webui/app) Conflicts: pyload/webui/app/api.py pyload/webui/app/cnl.py pyload/webui/app/json.py pyload/webui/app/pyloadweb.py pyload/webui/app/utils.py --- pyload/webui/app/json.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'pyload/webui/app/json.py') diff --git a/pyload/webui/app/json.py b/pyload/webui/app/json.py index 30778f1f7..3b72cb7ce 100644 --- a/pyload/webui/app/json.py +++ b/pyload/webui/app/json.py @@ -9,9 +9,7 @@ from shutil import copyfileobj from bottle import route, request, HTTPError from pyload.webui import PYLOAD - from pyload.webui.app.utils import login_required, render_to_response, toDict - from pyload.utils import decode, formatSize @@ -227,7 +225,7 @@ def set_captcha(): if task.tid >= 0: src = "data:image/%s;base64,%s" % (task.type, task.data) - return {'captcha': True, 'id': task.tid, 'src': src, 'result_type' : task.resultType} + return {'captcha': True, 'id': task.tid, 'src': src, 'result_type': task.resultType} else: return {'captcha': False} @@ -307,7 +305,6 @@ def update_accounts(): @route('/json/change_password', method='POST') def change_password(): - user = request.POST['user_login'] oldpw = request.POST['login_current_password'] newpw = request.POST['login_new_password'] -- cgit v1.2.3