Permalink
Browse files

Add python2/3 hack

  • Loading branch information...
bsdphk committed Oct 9, 2018
1 parent fa33ec5 commit 094d11b31c2ddf4a6fdb1ac8c20e9bfd8793ab00
Showing with 26 additions and 3 deletions.
  1. +26 −3 lib/libvcc/vsctool.py
View
@@ -41,6 +41,7 @@
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 @@ def emit_h(self):
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 @@ def emit_c(self):
'''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:]:

0 comments on commit 094d11b

Please sign in to comment.