diff options
author | Walter Purcaro <vuolter@users.noreply.github.com> | 2015-04-19 16:37:00 +0200 |
---|---|---|
committer | Walter Purcaro <vuolter@users.noreply.github.com> | 2015-04-19 16:37:00 +0200 |
commit | f162ae0de0f71391c56957389cc3c8babc8022e1 (patch) | |
tree | c85c8117da6e20fe49f91c933d8c7e57eb808cb8 /pyload/webui/app | |
parent | Merge pull request #8 from ardi69/0.4.10 (diff) | |
download | pyload-f162ae0de0f71391c56957389cc3c8babc8022e1.tar.xz |
Use with statement
Diffstat (limited to 'pyload/webui/app')
-rw-r--r-- | pyload/webui/app/cnl.py | 8 | ||||
-rw-r--r-- | pyload/webui/app/json.py | 7 |
2 files changed, 9 insertions, 6 deletions
diff --git a/pyload/webui/app/cnl.py b/pyload/webui/app/cnl.py index 73087ad2d..b6cbd6b55 100644 --- a/pyload/webui/app/cnl.py +++ b/pyload/webui/app/cnl.py @@ -1,4 +1,7 @@ # -*- coding: utf-8 -*- + +from __future__ import with_statement + from os.path import join import re from urllib import unquote @@ -57,9 +60,8 @@ def addcrypted(): dlc = request.forms['crypted'].replace(" ", "+") dlc_path = join(DL_ROOT, package.replace("/", "").replace("\\", "").replace(":", "") + ".dlc") - dlc_file = open(dlc_path, "wb") - dlc_file.write(dlc) - dlc_file.close() + with open(dlc_path, "wb") as dlc_file: + dlc_file.write(dlc) try: PYLOAD.addPackage(package, [dlc_path], 0) 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 |