]> granicus.if.org Git - python/commitdiff
Closes #29213: Merged fix from 3.6.
authorVinay Sajip <vinay_sajip@yahoo.co.uk>
Thu, 2 Feb 2017 19:33:43 +0000 (19:33 +0000)
committerVinay Sajip <vinay_sajip@yahoo.co.uk>
Thu, 2 Feb 2017 19:33:43 +0000 (19:33 +0000)
Lib/venv/__init__.py
Lib/venv/scripts/nt/Activate.ps1

index 308e046650e54423511ff5e5ad9b18c6391fdb44..716129d139871043ac27019ab815f29f6d2171b3 100644 (file)
@@ -320,19 +320,17 @@ class EnvBuilder:
                 dstfile = os.path.join(dstdir, f)
                 with open(srcfile, 'rb') as f:
                     data = f.read()
-                if srcfile.endswith('.exe'):
-                    mode = 'wb'
-                else:
-                    mode = 'w'
+                if not srcfile.endswith('.exe'):
                     try:
                         data = data.decode('utf-8')
                         data = self.replace_variables(data, context)
-                    except UnicodeDecodeError as e:
+                        data = data.encode('utf-8')
+                    except UnicodeError 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:
+                    with open(dstfile, 'wb') as f:
                         f.write(data)
                     shutil.copymode(srcfile, dstfile)
 
index c22b1ea1828850a291de298ddf8325bc19eb2bc8..85646c89a81cb3990d36ba376e1b8f5c1838a670 100644 (file)
@@ -26,7 +26,7 @@ function global:deactivate ([switch]$NonDestructive) {
 }\r
 \r
 deactivate -nondestructive\r
-
+\r
 $env:VIRTUAL_ENV="__VENV_DIR__"\r
 \r
 if (! $env:VIRTUAL_ENV_DISABLE_PROMPT) {\r