History

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.

Roy Marples committed 9 years ago

Commit 67e2b691 parent 7f7f9113 files · +3 −7Browse files

Unified · Split

3 files
  1. filter.c +2 −0
  2. filters/email-gravatar.py +0 −3
  3. filters/syntax-highlighting.py +1 −4
filter.c+2−0
@@ -55,6 +55,8 @@ static int open_exec_filter(struct cgit_filter *base, va_list ap) · 54 unmodified lines
5555 close(filter->pipe_fh[1]);
5656 chk_non_negative(dup2(filter->pipe_fh[0], STDIN_FILENO),
5757 "Unable to use pipe as STDIN");
58+ /* Always input/output utf-8 for a Python filter. */
59+ setenv("PYTHONIOENCODING", "utf-8", 1);
5860 execvp(filter->cmd, filter->argv);
5961 die_errno("Unable to exec subprocess %s", filter->cmd);
6062 }
filters/email-gravatar.py+0−3
@@ -30,9 +30,6 @@ if email[-1] == '>': · 29 unmodified lines
3030
3131 page = sys.argv[2]
3232
33−sys.stdin = codecs.getreader("utf-8")(sys.stdin.detach())
34−sys.stdout = codecs.getwriter("utf-8")(sys.stdout.detach())
35−
3633 md5 = hashlib.md5(email.encode()).hexdigest()
3734 text = sys.stdin.read().strip()
3835
filters/syntax-highlighting.py+1−4
@@ -29,9 +29,6 @@ from pygments.lexers import guess_lexer · 28 unmodified lines
2929 from pygments.lexers import guess_lexer_for_filename
3030 from pygments.formatters import HtmlFormatter
3131
32−
33−sys.stdin = io.TextIOWrapper(sys.stdin.buffer, encoding='utf-8', errors='replace')
34−sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8', errors='replace')
3532 data = sys.stdin.read()
3633 filename = sys.argv[1]
3734 formatter = HtmlFormatter(style='pastie')
@@ -52,4 +49,4 @@ except TypeError: · 14 unmodified lines
5249 sys.stdout.write('<style>')
5350 sys.stdout.write(formatter.get_style_defs('.highlight'))
5451 sys.stdout.write('</style>')
55−sys.stdout.write(highlight(data, lexer, formatter, outfile=None))
52+highlight(data, lexer, formatter, outfile=sys.stdout)