summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTiago Gomes <tiago.gomes@codethink.co.uk>2016-09-30 16:41:31 +0100
committerTiago Gomes <tiago.gomes@codethink.co.uk>2016-10-06 12:06:04 +0100
commit7a7e5848020edaea8cb90c165da44fa436905aaf (patch)
treed560b82848c987d6440d3e929c90c5b894df346c
parentc924e6477c90bb64a9f79ed317527cc9ada9e3e3 (diff)
downloadsandboxlib-7a7e5848020edaea8cb90c165da44fa436905aaf.tar.gz
Avoid attempt to load string-escape with Python 3
This module is not included in Python 3.
-rw-r--r--sandboxlib/chroot.py14
1 files changed, 9 insertions, 5 deletions
diff --git a/sandboxlib/chroot.py b/sandboxlib/chroot.py
index b7a07ad..9f5ed23 100644
--- a/sandboxlib/chroot.py
+++ b/sandboxlib/chroot.py
@@ -33,6 +33,7 @@ that the sandbox contains a shell and we do some hack like running
'''
+import sys
import contextlib
import multiprocessing
import os
@@ -225,13 +226,16 @@ def run_sandbox(command, cwd=None, env=None,
with mount_all(filesystem_root, extra_mounts):
- # Awful hack to ensure string-escape is loaded:
+ # Awful hack to ensure string-escape/unicode-escape are loaded:
#
# this ensures that when propagating an exception back from
- # the child process in a chroot, the required string-escape
- # python module is already in memory and no attempt to
- # lazy load it in the chroot is made.
- unused = "Some Text".encode('string-escape')
+ # the child process in a chroot, the required string-escape/
+ # unicode-escape python modules are already in memory and no
+ # attempt to lazy load them in the chroot is made.
+ if sys.version_info.major == 2:
+ unused = "Some Text".encode('string-escape')
+ elif sys.version_info.major == 3:
+ unused = "Some Text".encode('unicode-escape')
process = multiprocessing.Process(
target=run_command_in_chroot,