From patchwork Mon Dec 21 20:47:21 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Russell Bryant X-Patchwork-Id: 559718 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from archives.nicira.com (li376-54.members.linode.com [96.126.127.54]) by ozlabs.org (Postfix) with ESMTP id 52524140BB2 for ; Tue, 22 Dec 2015 07:51:43 +1100 (AEDT) Received: from archives.nicira.com (localhost [127.0.0.1]) by archives.nicira.com (Postfix) with ESMTP id 3D65110709; Mon, 21 Dec 2015 12:48:29 -0800 (PST) X-Original-To: dev@openvswitch.org Delivered-To: dev@openvswitch.org Received: from mx3v3.cudamail.com (mx3.cudamail.com [64.34.241.5]) by archives.nicira.com (Postfix) with ESMTPS id CC8DD106F9 for ; Mon, 21 Dec 2015 12:48:26 -0800 (PST) Received: from bar4.cudamail.com (localhost [127.0.0.1]) by mx3v3.cudamail.com (Postfix) with ESMTPS id 5B7141610EB for ; Mon, 21 Dec 2015 13:48:26 -0700 (MST) X-ASG-Debug-ID: 1450730906-03dc213fef439580001-byXFYA Received: from mx3-pf2.cudamail.com ([192.168.14.1]) by bar4.cudamail.com with ESMTP id Iy6GVnotDtLjFyCH (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Mon, 21 Dec 2015 13:48:26 -0700 (MST) X-Barracuda-Envelope-From: russell@ovn.org X-Barracuda-RBL-Trusted-Forwarder: 192.168.14.1 Received: from unknown (HELO mx1.redhat.com) (209.132.183.28) by mx3-pf2.cudamail.com with ESMTPS (DHE-RSA-AES256-SHA encrypted); 21 Dec 2015 20:48:25 -0000 Received-SPF: neutral (mx3-pf2.cudamail.com: 209.132.183.28 is neither permitted nor denied by SPF record at ovn.org) X-Barracuda-Apparent-Source-IP: 209.132.183.28 X-Barracuda-RBL-IP: 209.132.183.28 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id 431ABC0A146B; Mon, 21 Dec 2015 20:48:25 +0000 (UTC) Received: from x1c.redhat.com ([10.3.112.11]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id tBLKm0di002018; Mon, 21 Dec 2015 15:48:24 -0500 X-CudaMail-Envelope-Sender: russell@ovn.org From: Russell Bryant To: dev@openvswitch.org X-CudaMail-Whitelist-To: dev@openvswitch.org X-CudaMail-MID: CM-V2-1220053659 X-CudaMail-DTE: 122115 X-CudaMail-Originating-IP: 209.132.183.28 Date: Mon, 21 Dec 2015 15:47:21 -0500 X-ASG-Orig-Subj: [##CM-V2-1220053659##][PATCH 21/55] xml2nroff: Make compatible with Python 3. Message-Id: <1450730875-18083-22-git-send-email-russell@ovn.org> In-Reply-To: <1450730875-18083-1-git-send-email-russell@ovn.org> References: <1450730875-18083-1-git-send-email-russell@ovn.org> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Barracuda-Connect: UNKNOWN[192.168.14.1] X-Barracuda-Start-Time: 1450730906 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://web.cudamail.com:443/cgi-mod/mark.cgi X-ASG-Whitelist: Header =?UTF-8?B?eFwtY3VkYW1haWxcLXdoaXRlbGlzdFwtdG8=?= X-Virus-Scanned: by bsmtpd at cudamail.com X-Barracuda-BRTS-Status: 1 Subject: [ovs-dev] [PATCH 21/55] xml2nroff: Make compatible with Python 3. X-BeenThere: dev@openvswitch.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dev-bounces@openvswitch.org Sender: "dev" Update xml2nroff to work with either Python 2 or Python 3. The changes are minor and can be managed without the use of the six library. For iterating a dict, we now use: for k, v in subst.items(): This is the same as .iteritems() in Python 2. It's technically a little less efficient for Python 2, as items() returns a list instead of an iterator in Python 2. We're dealing with a very small set of items here so it really doesn't matter. Signed-off-by: Russell Bryant --- build-aux/xml2nroff | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/build-aux/xml2nroff b/build-aux/xml2nroff index 00ef649..a4f8fbc 100755 --- a/build-aux/xml2nroff +++ b/build-aux/xml2nroff @@ -14,6 +14,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import print_function + import getopt import sys import xml.dom.minidom @@ -24,7 +26,7 @@ argv0 = sys.argv[0] def usage(): - print """\ + print("""\ %(argv0)s: XML to nroff converter Converts the XML format supplied as input into an nroff-formatted manpage. usage: %(argv0)s [OPTIONS] INPUT.XML [VAR=VALUE]... @@ -36,14 +38,14 @@ corresponding VALUE, with characters &<>"' in VALUE escaped. The following options are also available: --version=VERSION use VERSION to display on document footer -h, --help display this help message\ -""" % {'argv0': argv0} +""" % {'argv0': argv0}) sys.exit(0) def manpage_to_nroff(xml_file, subst, version=None): with open(xml_file) as f: content = f.read() - for k, v in subst.iteritems(): + for k, v in subst.items(): content = content.replace(k, v) doc = xml.dom.minidom.parseString(content).documentElement @@ -82,7 +84,7 @@ if __name__ == "__main__": try: options, args = getopt.gnu_getopt(sys.argv[1:], 'hV', ['version=', 'help']) - except getopt.GetoptError, geo: + except getopt.GetoptError as geo: sys.stderr.write("%s: %s\n" % (argv0, geo.msg)) sys.exit(1) @@ -114,13 +116,13 @@ if __name__ == "__main__": try: s = manpage_to_nroff(args[0], subst, version) - except build.nroff.error.Error, e: + except build.nroff.error.Error as e: sys.stderr.write("%s: %s\n" % (argv0, e.msg)) sys.exit(1) for line in s.splitlines(): line = line.strip() if line: - print line + print(line) # Local variables: