From: Vinay Sajip Date: Sun, 28 Oct 2012 12:39:39 +0000 (+0000) Subject: Closes #16340: Handle exception while copying script to venv. X-Git-Tag: v3.3.1rc1~729^2~2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=bdd13fd09819495ce1bf249a705832ce86968b42;p=python Closes #16340: Handle exception while copying script to venv. --- diff --git a/Lib/venv/__init__.py b/Lib/venv/__init__.py index 8d2deb7385..3c0d7af903 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):