From 7e0c48e3a941ce874361b442a02624e586db810b Mon Sep 17 00:00:00 2001 From: Paul Vinciguerra Date: Fri, 1 Feb 2019 19:37:45 -0800 Subject: Python3: Move vppapigen to python3. Change-Id: I26846d0c12211a29ccfca7c269b9094f6fdbd95c Signed-off-by: Paul Vinciguerra --- src/tools/vppapigen/test_vppapigen.py | 5 +++-- src/tools/vppapigen/vppapigen.py | 19 ++++++++++++------- 2 files changed, 15 insertions(+), 9 deletions(-) (limited to 'src/tools') diff --git a/src/tools/vppapigen/test_vppapigen.py b/src/tools/vppapigen/test_vppapigen.py index 09187f4c965..a8a0a49a8db 100755 --- a/src/tools/vppapigen/test_vppapigen.py +++ b/src/tools/vppapigen/test_vppapigen.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 import unittest from vppapigen import VPPAPI, Option, ParseError @@ -60,7 +60,8 @@ class TestDefine(unittest.TestCase): test_string = ''' nonexisting_flag define foo { u8 foo; }; ''' - self.assertRaises(ParseError, self.parser.parse_string, test_string) + with self.assertRaises(ParseError): + self.parser.parse_string(test_string) class TestService(unittest.TestCase): diff --git a/src/tools/vppapigen/vppapigen.py b/src/tools/vppapigen/vppapigen.py index 4ca9b954e67..431a9dc7f93 100755 --- a/src/tools/vppapigen/vppapigen.py +++ b/src/tools/vppapigen/vppapigen.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 from __future__ import print_function import ply.lex as lex @@ -133,11 +133,11 @@ def crc_block(block): class Service(): - def __init__(self, caller, reply, events=[], stream=False): + def __init__(self, caller, reply, events=None, stream=False): self.caller = caller self.reply = reply self.stream = stream - self.events = events + self.events = [] if events is None else events class Typedef(): @@ -170,8 +170,8 @@ class Using(): else: a = { 'type': alias.fieldtype } self.alias = a - self.crc = binascii.crc32(str(alias)) & 0xffffffff - global_crc = binascii.crc32(str(alias), global_crc) + self.crc = binascii.crc32(str(alias).encode()) & 0xffffffff + global_crc = binascii.crc32(str(alias).encode(), global_crc) global_type_add(name) def __repr__(self): @@ -759,12 +759,17 @@ def main(): if sys.version[0] == '2': cliparser.add_argument('--input', type=argparse.FileType('r'), default=sys.stdin) + cliparser.add_argument('--output', nargs='?', + type=argparse.FileType('w'), + default=sys.stdout) + else: cliparser.add_argument('--input', type=argparse.FileType('r', encoding='UTF-8'), default=sys.stdin) - cliparser.add_argument('--output', nargs='?', type=argparse.FileType('w'), - default=sys.stdout) + cliparser.add_argument('--output', nargs='?', + type=argparse.FileType('w', encoding='UTF-8'), + default=sys.stdout) cliparser.add_argument('output_module', nargs='?', default='C') cliparser.add_argument('--debug', action='store_true') -- cgit 1.2.3-korg