@@ -93,6 +93,14 @@ class ListAction(argparse.Action):
93
93
else :
94
94
setattr (namespace , self .dest, {key : value })|}
95
95
96
+ let compat_block = [
97
+ Line " if sys.version_info[0] > 2:"
98
+ ; Block [
99
+ Line " long = int"
100
+ ; Line " unicode = str"
101
+ ; Line " str = bytes" ]
102
+ ; Line " " ]
103
+
96
104
let reserved_exns =
97
105
[ " Rpc_light_failure"
98
106
; " Unimplemented"
@@ -250,8 +258,8 @@ let rec typecheck : type a. a typ -> string -> t list =
250
258
let rec value_of : type a. a typ -> string =
251
259
let open Printf in
252
260
function
253
- | Basic Int64 -> " 0L "
254
- | Basic Int -> " 0L "
261
+ | Basic Int64 -> " long(0) "
262
+ | Basic Int -> " long(0) "
255
263
| Basic Int32 -> " 0"
256
264
| Basic Char -> " 'c'"
257
265
| Basic String -> {| " string" | }
@@ -386,7 +394,7 @@ let example_stub_user i (BoxedFunction m) =
386
394
m.Method. name) )
387
395
(value_of a.Idl.Param. typedef.ty) )
388
396
Method. (find_inputs m.ty))))
389
- ; Line " print (repr(results))" ] ]
397
+ ; Line " print(repr(results))" ] ]
390
398
391
399
let example_skeleton_user i m =
392
400
let open Printf in
@@ -619,7 +627,7 @@ let commandline_run _ (BoxedFunction m) =
619
627
; Line " use_json = 'json' in request and request['json']"
620
628
; Line
621
629
(sprintf " results = self.dispatcher.%s(request)" m.Method. name)
622
- ; Line " print json.dumps(results)" ]
630
+ ; Line " print( json.dumps(results) )" ]
623
631
; Line " except Exception as exn:"
624
632
; Block
625
633
[ Line " if use_json:"
@@ -664,16 +672,19 @@ let of_interfaces ?(helpers= inline_defaults) i =
664
672
in
665
673
[Line " self._dispatcher_dict = {" ] @ intersperse_commas methods @ [Line " }" ]
666
674
in
667
- [ Line
668
- (sprintf {| " " " Bindings generated for interface %s by rpclib" " " | }
675
+ [ Line (sprintf {| " " " Bindings generated for interface %s by rpclib" " " | }
669
676
i.Interfaces. name)
670
677
; Line " "
678
+ ; Line " from __future__ import print_function, division"
679
+ ; Line " "
671
680
; Line " import argparse"
672
681
; Line " import json"
673
682
; Line " import logging"
674
683
; Line " import sys"
675
684
; Line " import traceback"
676
- ; Line " " ]
685
+ ; Line " "
686
+ ]
687
+ @ compat_block
677
688
@ (helpers |> String. split_on_char '\n' |> List. map (fun line -> Line line))
678
689
@ ( try List. map exn_var i.Interfaces. error_decls |> List. flatten with e ->
679
690
Printf. fprintf stderr " Error while generating exceptions of %s"
0 commit comments