aboutsummaryrefslogtreecommitdiffhomepage
path: root/share/tools/web_config/webconfig.py
diff options
context:
space:
mode:
authorGravatar Kevin Ballard <kevin@sb.org>2014-10-09 20:21:26 -0700
committerGravatar Kevin Ballard <kevin@sb.org>2014-10-09 20:21:26 -0700
commitcc7f1755aa4d33c30f64cfcd6b286d539e3d0519 (patch)
treecbc09bbb41f470e8510abe5b75a4399837150ad4 /share/tools/web_config/webconfig.py
parent7493c9a0409edeebb4caed9bb76d0cba2c33cf37 (diff)
web_config: Interpret fish output as utf-8
Use the unicode replacement character in place of non-utf-8 sequences.
Diffstat (limited to 'share/tools/web_config/webconfig.py')
-rwxr-xr-xshare/tools/web_config/webconfig.py18
1 files changed, 15 insertions, 3 deletions
diff --git a/share/tools/web_config/webconfig.py b/share/tools/web_config/webconfig.py
index a6f11f22..ca720c62 100755
--- a/share/tools/web_config/webconfig.py
+++ b/share/tools/web_config/webconfig.py
@@ -35,13 +35,25 @@ except ImportError:
FISH_BIN_PATH = False # will be set later
def run_fish_cmd(text):
from subprocess import PIPE
- p = subprocess.Popen([FISH_BIN_PATH], stdin=PIPE, stdout=PIPE, stderr=PIPE)
+ # ensure that fish is using UTF-8
+ ctype = os.environ.get("LC_ALL", os.environ.get("LC_CTYPE", os.environ.get("LANG")))
+ env = None
+ if re.search(r"\.utf-?8$", ctype, flags=re.I) is None:
+ # override LC_CTYPE with en_US.UTF-8
+ # We're assuming this locale exists.
+ # Fish makes the same assumption in config.fish
+ env = os.environ.copy()
+ env.update(LC_CTYPE="en_US.UTF-8", LANG="en_US.UTF-8")
+ p = subprocess.Popen([FISH_BIN_PATH], stdin=PIPE, stdout=PIPE, stderr=PIPE, env=env)
if IS_PY2:
out, err = p.communicate(text)
+ # interpret as utf-8 in a lossy fashion
+ out = unicode(out, 'utf-8', 'replace').encode('utf-8')
+ err = unicode(err, 'utf-8', 'replace').encode('utf-8')
else:
out, err = p.communicate(bytes(text, 'utf-8'))
- out = str(out, 'utf-8')
- err = str(err, 'utf-8')
+ out = str(out, 'utf-8', 'replace')
+ err = str(err, 'utf-8', 'replace')
return(out, err)
def escape_fish_cmd(text):