[4.0] 45362c9 Support both python2 and python3.

Lasse Karstensen lkarsten at varnish-software.com
Tue Jun 24 11:31:48 CEST 2014


commit 45362c9c1ad0aa2b949d5aa49c2c8fa39d363565
Author: Lasse Karstensen <lkarsten at varnish-software.com>
Date:   Wed May 14 10:26:12 2014 +0200

    Support both python2 and python3.

diff --git a/lib/libvcc/vmodtool.py b/lib/libvcc/vmodtool.py
index 6e875bf..25e0624 100755
--- a/lib/libvcc/vmodtool.py
+++ b/lib/libvcc/vmodtool.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python2
+#!/usr/bin/env python
 #-
 # Copyright (c) 2010-2014 Varnish Software AS
 # All rights reserved.
@@ -37,6 +37,9 @@
 # as a string, suitable for inclusion in the C-source of the compile VCL
 # program.
 
+# This script should work with both Python 2 and Python 3.
+from __future__ import print_function
+
 import sys
 import re
 import optparse
@@ -45,7 +48,6 @@ from os import unlink
 from os.path import dirname, basename, realpath, exists
 from pprint import pprint, pformat
 
-
 ctypes = {
 	'BACKEND':	"VCL_BACKEND",
 	'BOOL':		"VCL_BOOL",
@@ -89,7 +91,7 @@ class FormatError(Exception):
 	"""
 		Raised if the content of the (otherwise well-formed) input file
 		is invalid.
-  """
+	"""
 	def __init__(self, msg, details):
 		self.msg = msg
 		self.details = details
@@ -699,8 +701,8 @@ class file_section(object):
 			if opts.strict:
 				raise FormatError(m, details)
 			else:
-				print >>sys.stderr, "WARNING: %s:" % m
-				print >>sys.stderr, details
+				print("WARNING: %s:" % m, file=sys.stderr)
+				print(details, file=sys.stderr)
 		else:
 			for ln, i in self.l:
 				o.doc(i)
@@ -798,12 +800,12 @@ def runmain(inputvcc, outputname="vcc_if"):
 			i.parse(vx)
 			assert len(i.tl) == 0
 	except ParseError as e:
-		print "ERROR: Parse error reading \"%s\":" % inputvcc
+		print("ERROR: Parse error reading \"%s\":" % inputvcc)
 		pprint(str(e))
 		exit(-1)
 	except FormatError as e:
-		print "ERROR: Format error reading \"%s\": %s" % (inputvcc, pformat(e.msg))
-		print e.details
+		print("ERROR: Format error reading \"%s\": %s" % (inputvcc, pformat(e.msg)))
+		print(e.details)
 		exit(-2)
 
 	#######################################################################
@@ -879,7 +881,7 @@ if __name__ == "__main__":
 		if not inputvcc:
 		    inputvcc = "vmod.vcc"
 	else:
-		print >>sys.stderr, "ERROR: No vmod.vcc file supplied or found."
+		print("ERROR: No vmod.vcc file supplied or found.", file=sys.stderr)
 		oparser.print_help()
 		exit(-1)
 



More information about the varnish-commit mailing list