From 2731fe3e6a4ba6fd858947e343160c95c96042e2 Mon Sep 17 00:00:00 2001 From: Kyle Manna Date: Sat, 19 Sep 2015 14:30:21 -0700 Subject: generator: Use python2/3 binary read/write method * This works with python2 and python3 --- generator/nanopb_generator.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/generator/nanopb_generator.py b/generator/nanopb_generator.py index 17cb674f..c2acb060 100755 --- a/generator/nanopb_generator.py +++ b/generator/nanopb_generator.py @@ -1440,14 +1440,15 @@ def main_cli(): def main_plugin(): '''Main function when invoked as a protoc plugin.''' - import sys + import io, sys if sys.platform == "win32": import os, msvcrt # Set stdin and stdout to binary mode msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY) msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY) - data = sys.stdin.read() + data = io.open(sys.stdin.fileno(), "rb").read() + request = plugin_pb2.CodeGeneratorRequest.FromString(data) try: @@ -1490,7 +1491,7 @@ def main_plugin(): f.name = results['sourcename'] f.content = results['sourcedata'] - sys.stdout.write(response.SerializeToString()) + io.open(sys.stdout.fileno(), "wb").write(response.SerializeToString()) if __name__ == '__main__': # Check if we are running as a plugin under protoc -- cgit 1.2.3-korg