Package: golang-github-ugorji-go-codec / 1.1.7-2

0001-python3.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
From: cclauss <cclauss@me.com>
Date: Tue, 16 Jul 2019 11:10:46 +0200
Subject: python3

Based on https://github.com/ugorji/go/pull/309
---
 codec/codec_test.go |  6 +++---
 codec/test.py       | 22 ++++++++++------------
 2 files changed, 13 insertions(+), 15 deletions(-)

diff --git a/codec/codec_test.go b/codec/codec_test.go
index e9d5e02..b33bce8 100644
--- a/codec/codec_test.go
+++ b/codec/codec_test.go
@@ -1671,7 +1671,7 @@ func doTestPythonGenStreams(t *testing.T, h Handle) {
 	if testVerbose {
 		t.Logf("tmpdir: %v", tmpdir)
 	}
-	cmd := exec.Command("python", "test.py", "testdata", tmpdir)
+	cmd := exec.Command("python3", "test.py", "testdata", tmpdir)
 	//cmd.Stdin = strings.NewReader("some input")
 	//cmd.Stdout = &out
 	var cmdout []byte
@@ -1779,7 +1779,7 @@ func doTestMsgpackRpcSpecGoClientToPythonSvc(t *testing.T) {
 	r := rand.New(rand.NewSource(time.Now().UnixNano()))
 	openPort := strconv.FormatInt(6700+r.Int63n(99), 10)
 	// openPort := "6792"
-	cmd := exec.Command("python", "test.py", "rpc-server", openPort, "4")
+	cmd := exec.Command("python3", "test.py", "rpc-server", openPort, "4")
 	checkErrT(t, cmd.Start())
 	bs, err2 := net.Dial("tcp", ":"+openPort)
 	for i := 0; i < 10 && err2 != nil; i++ {
@@ -1806,7 +1806,7 @@ func doTestMsgpackRpcSpecPythonClientToGoSvc(t *testing.T) {
 	testOnce.Do(testInitAll)
 	port := testCodecRpcOne(t, MsgpackSpecRpc, testMsgpackH, false, 1*time.Second)
 	//time.Sleep(1000 * time.Millisecond)
-	cmd := exec.Command("python", "test.py", "rpc-client-go-service", strconv.Itoa(port))
+	cmd := exec.Command("python3", "test.py", "rpc-client-go-service", strconv.Itoa(port))
 	var cmdout []byte
 	var err error
 	if cmdout, err = cmd.CombinedOutput(); err != nil {
diff --git a/codec/test.py b/codec/test.py
index 800376f..2222c05 100755
--- a/codec/test.py
+++ b/codec/test.py
@@ -11,6 +11,7 @@
 
 # Ensure all "string" keys are utf strings (else encoded as bytes)
 
+from __future__ import print_function
 import cbor, msgpack, msgpackrpc, sys, os, threading
 
 def get_test_data_list():
@@ -69,13 +70,11 @@ def build_test_data(destdir):
     for i in range(len(l)):
         # packer = msgpack.Packer()
         serialized = msgpack.dumps(l[i])
-        f = open(os.path.join(destdir, str(i) + '.msgpack.golden'), 'wb')
-        f.write(serialized)
-        f.close()
+        with open(os.path.join(destdir, str(i) + '.msgpack.golden'), 'wb') as f:
+            f.write(serialized)
         serialized = cbor.dumps(l[i])
-        f = open(os.path.join(destdir, str(i) + '.cbor.golden'), 'wb')
-        f.write(serialized)
-        f.close()
+        with open(os.path.join(destdir, str(i) + '.cbor.golden'), 'wb') as f:
+            f.write(serialized)
 
 def doRpcServer(port, stopTimeSec):
     class EchoHandler(object):
@@ -98,15 +97,15 @@ def doRpcServer(port, stopTimeSec):
 def doRpcClientToPythonSvc(port):
     address = msgpackrpc.Address('127.0.0.1', port)
     client = msgpackrpc.Client(address, unpack_encoding='utf-8')
-    print client.call("Echo123", "A1", "B2", "C3")
-    print client.call("EchoStruct", {"A" :"Aa", "B":"Bb", "C":"Cc"})
+    print(client.call("Echo123", "A1", "B2", "C3"))
+    print(client.call("EchoStruct", {"A" :"Aa", "B":"Bb", "C":"Cc"}))
    
 def doRpcClientToGoSvc(port):
-    # print ">>>> port: ", port, " <<<<<"
+    # print(">>>> port: ", port, " <<<<<")
     address = msgpackrpc.Address('127.0.0.1', port)
     client = msgpackrpc.Client(address, unpack_encoding='utf-8')
-    print client.call("TestRpcInt.Echo123", ["A1", "B2", "C3"])
-    print client.call("TestRpcInt.EchoStruct", {"A" :"Aa", "B":"Bb", "C":"Cc"})
+    print(client.call("TestRpcInt.Echo123", ["A1", "B2", "C3"]))
+    print(client.call("TestRpcInt.EchoStruct", {"A" :"Aa", "B":"Bb", "C":"Cc"}))
 
 def doMain(args):
     if len(args) == 2 and args[0] == "testdata":
@@ -123,4 +122,3 @@ def doMain(args):
     
 if __name__ == "__main__":
     doMain(sys.argv[1:])
-