summaryrefslogtreecommitdiff
path: root/cmd2.py
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2017-07-08 11:36:48 -0400
committerTodd Leonhardt <todd.leonhardt@gmail.com>2017-07-08 11:36:48 -0400
commit400b8317c21600fe68c0ac4c98449f73a64ac309 (patch)
treeacaf7c79a059e1037ebb117a0df4e976e56723ea /cmd2.py
parentce8da647908a984950fb3b329d2bdd98a99b09e2 (diff)
downloadcmd2-git-400b8317c21600fe68c0ac4c98449f73a64ac309.tar.gz
Load command uses utf-8 encoding for opening files in Python 3 instead of OS-default
This fixes a unit test bug where on Windows it was trying to load a utf-8 file as some other encoding starting with "cp".
Diffstat (limited to 'cmd2.py')
-rwxr-xr-xcmd2.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/cmd2.py b/cmd2.py
index b7a6151a..c83a9bf0 100755
--- a/cmd2.py
+++ b/cmd2.py
@@ -1659,9 +1659,15 @@ Script should contain one command per line, just like command would be typed in
return
try:
- # Add all commands in the script to the command queue
- with open(expanded_path) as target:
- self.cmdqueue.extend(target.read().splitlines())
+ # Specify file encoding in Python 3, but Python 2 doesn't allow that argument to open()
+ if six.PY3:
+ # Add all commands in the script to the command queue
+ with open(expanded_path, encoding='utf-8') as target:
+ self.cmdqueue.extend(target.read().splitlines())
+ else:
+ # Add all commands in the script to the command queue
+ with open(expanded_path) as target:
+ self.cmdqueue.extend(target.read().splitlines())
# Append in an "end of script (eos)" command to cleanup the self._script_dir list
self.cmdqueue.append('eos')