summaryrefslogtreecommitdiff
path: root/pyuno
diff options
context:
space:
mode:
Diffstat (limited to 'pyuno')
-rw-r--r--pyuno/source/loader/pythonloader.py21
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('/')