[prev in list] [next in list] [prev in thread] [next in thread]
List: varnish-commit
Subject: [6.0] 187ce707e Add python2/3 hack
From: Dridi Boukelmoune <dridi.boukelmoune () gmail ! com>
Date: 2018-10-31 13:08:30
Message-ID: 20181031130830.090CF958E3 () lists ! varnish-cache ! org
[Download RAW message or body]
commit 187ce707efa4dbf0ce27973930587dc1c19080a7
Author: Poul-Henning Kamp <phk@FreeBSD.org>
Date: Tue Oct 9 08:36:02 2018 +0000
Add python2/3 hack
diff --git a/lib/libvcc/vsctool.py b/lib/libvcc/vsctool.py
index eb795e076..f1e0d02ab 100644
--- a/lib/libvcc/vsctool.py
+++ b/lib/libvcc/vsctool.py
@@ -41,6 +41,7 @@ import getopt
import json
import sys
import collections
+import codecs
# Parameters of 'varnish_vsc_begin', first element is default
TYPES = ["counter", "gauge", "bitmap"]
@@ -164,7 +165,12 @@ class CounterSet(object):
assert self.completed
fon = "VSC_" + self.name + ".h"
- fo = open(fon, "w")
+ try:
+ # Python3
+ fo = open(fon, "w", encoding="UTF-8")
+ except TypeError:
+ # Python2
+ fo = open(fon, "w")
genhdr(fo, self.name)
fo.write(self.struct + " {\n")
@@ -288,7 +294,12 @@ class CounterSet(object):
'''Emit .c file'''
assert self.completed
fon = "VSC_" + self.name + ".c"
- fo = open(fon, "w")
+ try:
+ # Python3
+ fo = open(fon, "w", encoding="UTF-8")
+ except TypeError:
+ # Python2
+ fo = open(fon, "w")
genhdr(fo, self.name)
fo.write('#include "config.h"\n')
fo.write('#include <stdio.h>\n')
@@ -437,10 +448,22 @@ def mainfunc(argv):
rstfile = None
for f, v in optlist:
if f == '-r':
+ try:
+ # Python3
+ sys.stdout = codecs.getwriter("utf-8")(sys.stdout.detach())
+ except AttributeError:
+ # Python2
+ pass
rstfile = sys.stdout
vscset = []
- scs = open(args[0]).read().split("\n.. ")
+ try:
+ # Python3
+ f = open(args[0], encoding="UTF-8")
+ except TypeError:
+ # Python2
+ f = open(args[0])
+ scs = f.read().split("\n.. ")
if rstfile:
rstfile.write(scs[0])
for i in scs[1:]:
_______________________________________________
varnish-commit mailing list
varnish-commit@varnish-cache.org
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-commit
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic