Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.zx2c4.com/cgit.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2017-03-09 03:18:10 +0300
committerLukas Fleischer <lfleischer@lfos.de>2017-08-10 16:15:55 +0300
commit67e2b69ec96a117b98c9028013ce0258574efe80 (patch)
treeb15b6f1753bdd3b941ace3ce4cd1e0cf81885807
parent7f7f91141ced1085dd2c6dbc5c65703d73b1b8c7 (diff)
filter: set environment variable PYTHONIOENCODING to utf-8
This allows different versions of Python to be used rather than forcing version specific encoding in each script. Signed-off-by: Roy Marples <roy@marples.name> Signed-off-by: John Keeping <john@keeping.me.uk>
-rw-r--r--filter.c2
-rwxr-xr-xfilters/email-gravatar.py3
-rwxr-xr-xfilters/syntax-highlighting.py5
3 files changed, 3 insertions, 7 deletions
diff --git a/filter.c b/filter.c
index 949c931..84dd0ed 100644
--- a/filter.c
+++ b/filter.c
@@ -55,6 +55,8 @@ static int open_exec_filter(struct cgit_filter *base, va_list ap)
close(filter->pipe_fh[1]);
chk_non_negative(dup2(filter->pipe_fh[0], STDIN_FILENO),
"Unable to use pipe as STDIN");
+ /* Always input/output utf-8 for a Python filter. */
+ setenv("PYTHONIOENCODING", "utf-8", 1);
execvp(filter->cmd, filter->argv);
die_errno("Unable to exec subprocess %s", filter->cmd);
}
diff --git a/filters/email-gravatar.py b/filters/email-gravatar.py
index d70440e..8b98471 100755
--- a/filters/email-gravatar.py
+++ b/filters/email-gravatar.py
@@ -30,9 +30,6 @@ if email[-1] == '>':
page = sys.argv[2]
-sys.stdin = codecs.getreader("utf-8")(sys.stdin.detach())
-sys.stdout = codecs.getwriter("utf-8")(sys.stdout.detach())
-
md5 = hashlib.md5(email.encode()).hexdigest()
text = sys.stdin.read().strip()
diff --git a/filters/syntax-highlighting.py b/filters/syntax-highlighting.py
index 5888b50..936fdb7 100755
--- a/filters/syntax-highlighting.py
+++ b/filters/syntax-highlighting.py
@@ -29,9 +29,6 @@ from pygments.lexers import guess_lexer
from pygments.lexers import guess_lexer_for_filename
from pygments.formatters import HtmlFormatter
-
-sys.stdin = io.TextIOWrapper(sys.stdin.buffer, encoding='utf-8', errors='replace')
-sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8', errors='replace')
data = sys.stdin.read()
filename = sys.argv[1]
formatter = HtmlFormatter(style='pastie')
@@ -52,4 +49,4 @@ except TypeError:
sys.stdout.write('<style>')
sys.stdout.write(formatter.get_style_defs('.highlight'))
sys.stdout.write('</style>')
-sys.stdout.write(highlight(data, lexer, formatter, outfile=None))
+highlight(data, lexer, formatter, outfile=sys.stdout)