Description: Convert Python scripts to Python3 using 2to3
Author: Andreas Tille <tille@debian.org>
Last-Update: Thu, 17 Nov 2022 13:47:06 +0100

--- a/inst/opencpu/ocpu-getdata.py
+++ b/inst/opencpu/ocpu-getdata.py
@@ -1,14 +1,14 @@
-#!/usr/bin/env python
+#!/usr/bin/python3
 # Jeroen Ooms
 #
 # HTTPS+ProtoBuf RPC POC using OpenCPU
 # Script below downloads MASS::Animals using protobuf
-import urllib2;
+import urllib.request, urllib.error, urllib.parse;
 from rexp_pb2 import *;
 
 #HTTP GET
-req = urllib2.Request('https://public.opencpu.org/ocpu/library/MASS/data/Animals/pb');
-res = urllib2.urlopen(req);
+req = urllib.request.Request('https://public.opencpu.org/ocpu/library/MASS/data/Animals/pb');
+res = urllib.request.urlopen(req);
 	
 #parse output pb
 msg = REXP();
--- a/inst/opencpu/ocpu-rpc.py
+++ b/inst/opencpu/ocpu-rpc.py
@@ -1,10 +1,10 @@
-#!/usr/bin/env python
+#!/usr/bin/python3
 # Jeroen Ooms
 #
 # HTTPS+ProtoBuf RPC POC using OpenCPU
 # The call below maps to: do.call(stats::rnorm, list(n=42, mean=100))
-import urllib2;
-from rexp_pb2 import *;
+import urllib.request, urllib.error, urllib.parse
+from rexp_pb2 import *
 
 #create the post payload, i.e. list(n=42, mean=100)
 payload = REXP(
@@ -19,24 +19,24 @@ payload = REXP(
 	attrValue = [
 		REXP(rclass = 0, stringValue = [STRING(strval="n"), STRING(strval="mean")])
 	]
-);
+)
 
 #HTTP POST
-req = urllib2.Request(
+req = urllib.request.Request(
 	'https://public.opencpu.org/ocpu/library/stats/R/rnorm/pb', 
 	data = payload.SerializeToString(), 
 	headers = {
 		'Content-type': 'application/x-protobuf'
 	}
-);
-res = urllib2.urlopen(req);
+)
+res = urllib.request.urlopen(req)
 	
 #parse output pb
-msg = REXP();
-msg.ParseFromString(res.read());
+msg = REXP()
+msg.ParseFromString(res.read())
 
 #the return value is a double vector in this case
-print(msg.realValue);
+print(msg.realValue)
 
 
 ##### To debug: 
--- a/inst/opencpu/rexp_pb2.py
+++ b/inst/opencpu/rexp_pb2.py
@@ -189,7 +189,7 @@ _STRING = descriptor.Descriptor(
     descriptor.FieldDescriptor(
       name='strval', full_name='rexp.STRING.strval', index=0,
       number=1, type=9, cpp_type=9, label=1,
-      has_default_value=False, default_value=unicode("", "utf-8"),
+      has_default_value=False, default_value=str("", "utf-8"),
       message_type=None, enum_type=None, containing_type=None,
       is_extension=False, extension_scope=None,
       options=None),
@@ -260,20 +260,17 @@ DESCRIPTOR.message_types_by_name['REXP']
 DESCRIPTOR.message_types_by_name['STRING'] = _STRING
 DESCRIPTOR.message_types_by_name['CMPLX'] = _CMPLX
 
-class REXP(message.Message):
-  __metaclass__ = reflection.GeneratedProtocolMessageType
+class REXP(message.Message, metaclass=reflection.GeneratedProtocolMessageType):
   DESCRIPTOR = _REXP
   
   # @@protoc_insertion_point(class_scope:rexp.REXP)
 
-class STRING(message.Message):
-  __metaclass__ = reflection.GeneratedProtocolMessageType
+class STRING(message.Message, metaclass=reflection.GeneratedProtocolMessageType):
   DESCRIPTOR = _STRING
   
   # @@protoc_insertion_point(class_scope:rexp.STRING)
 
-class CMPLX(message.Message):
-  __metaclass__ = reflection.GeneratedProtocolMessageType
+class CMPLX(message.Message, metaclass=reflection.GeneratedProtocolMessageType):
   DESCRIPTOR = _CMPLX
   
   # @@protoc_insertion_point(class_scope:rexp.CMPLX)
--- a/inst/python/readmsg.py
+++ b/inst/python/readmsg.py
@@ -1,16 +1,16 @@
-#!/usr/bin/env python
+#!/usr/bin/python3
 #
 # Simple test script to read a serialized message in python
 #
-import rexp_pb2;
-import glob;
+import rexp_pb2
+import glob
 
-messages = glob.glob("*.msg");
+messages = glob.glob("*.msg")
 for myfile in messages:
 	print("Reading message " + myfile + " ...")
 	f = open(myfile, 'rb')
-	msg = rexp_pb2.REXP();	
+	msg = rexp_pb2.REXP()	
 	msg.ParseFromString(f.read())
-	f.close();
+	f.close()
 	print(msg)
 	del msg
