summaryrefslogtreecommitdiffstats
path: root/Lib/venv
diff options
context:
space:
mode:
authorVinay Sajip <vinay_sajip@yahoo.co.uk>2012-10-28 12:39:39 (GMT)
committerVinay Sajip <vinay_sajip@yahoo.co.uk>2012-10-28 12:39:39 (GMT)
commitbdd13fd09819495ce1bf249a705832ce86968b42 (patch)
tree2e669f46fc665562f439f1b2d58a40d2ca0b44f5 /Lib/venv
parent6d50a5447af687e2a1303876a3c7867734477762 (diff)
downloadcpython-bdd13fd09819495ce1bf249a705832ce86968b42.zip
cpython-bdd13fd09819495ce1bf249a705832ce86968b42.tar.gz
cpython-bdd13fd09819495ce1bf249a705832ce86968b42.tar.bz2
Closes #16340: Handle exception while copying script to venv.
Diffstat (limited to 'Lib/venv')
-rw-r--r--Lib/venv/__init__.py16
1 files changed, 11 insertions, 5 deletions
diff --git a/Lib/venv/__init__.py b/Lib/venv/__init__.py
index 8d2deb7..3c0d7af 100644
--- a/Lib/venv/__init__.py
+++ b/Lib/venv/__init__.py
@@ -305,11 +305,17 @@ class EnvBuilder:
mode = 'wb'
else:
mode = 'w'
- data = data.decode('utf-8')
- data = self.replace_variables(data, context)
- with open(dstfile, mode) as f:
- f.write(data)
- shutil.copymode(srcfile, dstfile)
+ try:
+ data = data.decode('utf-8')
+ data = self.replace_variables(data, context)
+ except UnicodeDecodeError as e:
+ data = None
+ logger.warning('unable to copy script %r, '
+ 'may be binary: %s', srcfile, e)
+ if data is not None:
+ with open(dstfile, mode) as f:
+ f.write(data)
+ shutil.copymode(srcfile, dstfile)
def create(env_dir, system_site_packages=False, clear=False, symlinks=False):