Skip to content

Commit c994f83

Browse files
committed
some changes for py3 compat
1 parent 2d5e911 commit c994f83

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

java2python/config/default.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
modulePrologueHandlers = [
2525
basic.shebangLine,
2626
basic.simpleDocString,
27+
'from __future__ import print_function',
2728
basic.maybeBsr,
2829
basic.maybeSyncHelpers,
2930
]
@@ -193,8 +194,8 @@
193194

194195
# module output subs.
195196
moduleOutputSubs = [
196-
(r'System\.out\.println\((.*)\)', r'print \1'),
197-
(r'System\.out\.print_\((.*?)\)', r'print \1,'),
197+
(r'System\.out\.println\((.*)\)', r'print(\1)'),
198+
(r'System\.out\.print_\((.*?)\)', r'print(\1, end="")'),
198199
(r'(.*?)\.equals\((.*?)\)', r'\1 == \2'),
199200
(r'(.*?)\.equalsIgnoreCase\((.*?)\)', r'\1.lower() == \2.lower()'),
200201
(r'([\w.]+)\.size\(\)', r'len(\1)'),

java2python/mod/include/overloading.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,13 @@
3636
3737
"""
3838

39-
import new
39+
from types import MethodType as instancemethod
4040

41-
# Make the environment more like Python 3.0
42-
__metaclass__ = type
43-
from itertools import izip as zip
41+
import sys
42+
if sys.version_info[0] < 3:
43+
# Make the environment more like Python 3.0
44+
__metaclass__ = type
45+
from itertools import izip as zip
4446

4547

4648
class overloaded:
@@ -55,7 +57,7 @@ def __init__(self, default_func):
5557
def __get__(self, obj, type=None):
5658
if obj is None:
5759
return self
58-
return new.instancemethod(self, obj)
60+
return instancemethod(self, obj)
5961

6062
def register(self, *types):
6163
"""Decorator to register an implementation for a specific set of types.

test/Self0.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ public static void main(String[] args) {
1717
System.out.println("True");
1818
else
1919
System.out.println("False");
20+
System.out.print("test");
21+
System.out.print("ing");
22+
System.out.println();
2023
}
2124

2225
}

0 commit comments

Comments
 (0)