diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2020-12-07 09:09:24 +0300 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2020-12-07 08:14:46 +0100 |
commit | 3e524922b93b1fe811d3b20f8f6cdf01461348ac (patch) | |
tree | 417325a075eb966df0dc474a085fa7d3c132f05f /pyuno/source | |
parent | cc1b4f455e8ab231b5c7a3b9e3fbd69d8935783e (diff) |
Wrap "open" into "with"
Change-Id: I1ecc16ddf565ac1f7306289fd51b673ed928cc20
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107329
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'pyuno/source')
-rw-r--r-- | pyuno/source/loader/pythonloader.py | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/pyuno/source/loader/pythonloader.py b/pyuno/source/loader/pythonloader.py index 7c16e226bad9..9a7114aea210 100644 --- a/pyuno/source/loader/pythonloader.py +++ b/pyuno/source/loader/pythonloader.py @@ -90,17 +90,16 @@ class Loader( XImplementationLoader, XServiceInfo, unohelper.Base ): # read the file filename = unohelper.fileUrlToSystemPath( url ) - fileHandle = open( filename, encoding='utf_8' ) - src = fileHandle.read().replace("\r","") - if not src.endswith( "\n" ): - src = src + "\n" - - # compile and execute the module - codeobject = compile( src, encfile(filename), "exec" ) - mod.__file__ = filename - exec(codeobject, mod.__dict__) - g_loadedComponents[url] = mod - fileHandle.close() + with open( filename, encoding='utf_8' ) as fileHandle: + src = fileHandle.read().replace("\r","") + if not src.endswith( "\n" ): + src = src + "\n" + + # compile and execute the module + codeobject = compile( src, encfile(filename), "exec" ) + mod.__file__ = filename + exec(codeobject, mod.__dict__) + g_loadedComponents[url] = mod return mod elif "vnd.openoffice.pymodule" == protocol: nSlash = dependent.rfind('/') |