]> granicus.if.org Git - python/commitdiff
Closes #16340: Handle exception while copying script to venv.
authorVinay Sajip <vinay_sajip@yahoo.co.uk>
Sun, 28 Oct 2012 12:39:39 +0000 (12:39 +0000)
committerVinay Sajip <vinay_sajip@yahoo.co.uk>
Sun, 28 Oct 2012 12:39:39 +0000 (12:39 +0000)
Lib/venv/__init__.py

index 8d2deb738560edfc77fe50b8b99b462e62687bbb..3c0d7af903f14bc3f630c4cfc6084eb213228f05 100644 (file)
@@ -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):