Skip to content

Commit f8cbe5b

Browse files
author
212304420
committed
Initial upload of all modifications to make java2python Python 3 compliant for GE ASKE
1 parent b803756 commit f8cbe5b

10 files changed

Lines changed: 207 additions & 444 deletions

File tree

java2python/compiler/block.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,16 @@
1616
from java2python.compiler import template, visitor
1717

1818

19-
def addTypeToModule((className, factoryName)):
19+
#def addTypeToModule((className, factoryName)):
20+
def addTypeToModule(cftuple):
21+
(className, factoryName) = cftuple
2022
""" Constructs and adds a new type to this module. """
2123
bases = (getattr(template, className), getattr(visitor, className))
2224
newType = type(className, bases, dict(factoryName=factoryName))
2325
setattr(modules[__name__], className, newType)
2426

2527

26-
map(addTypeToModule, (
28+
list(map(addTypeToModule, (
2729
('Annotation', 'at'),
2830
('Class', 'klass'),
2931
('Comment', 'comment'),
@@ -35,4 +37,4 @@ def addTypeToModule((className, factoryName)):
3537
('Module', 'module'),
3638
('Statement', 'statement'),
3739
)
38-
)
40+
))

java2python/compiler/template.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@
1313
# are usually a sign of a bad design and/or language limitations, and
1414
# this case is no exception.
1515

16-
from cStringIO import StringIO
17-
from functools import partial
18-
from itertools import chain, ifilter, imap
16+
#from cStringIO import StringIO
17+
from io import StringIO
18+
from functools import partial, reduce
19+
#from itertools import chain, ifilter, imap
20+
from itertools import chain
1921

2022
from java2python.lang import tokens
2123
from java2python.lib import FS, colors
@@ -74,7 +76,8 @@ def __init__(cls, name, bases, namespace):
7476
pass
7577

7678

77-
class Base(object):
79+
#class Base(object):
80+
class Base(object, metaclass=FactoryTypeDetector):
7881
""" Base -> base class for formatting Python output.
7982
8083
This class defines a large set of attributes and methods for the
@@ -119,7 +122,6 @@ def __init__(self, config, name=None, type=None, parent=None):
119122
self.children = []
120123
self.config = config
121124
self.decorators = []
122-
self.overloaded = None
123125
self.factory = Factory(config)
124126
self.modifiers = []
125127
self.name = name
@@ -162,7 +164,9 @@ def altIdent(self, name):
162164
return name
163165
if name in method.variables:
164166
return name
165-
return ('cls' if method.isStatic else 'self') + '.' + name
167+
#return ('cls' if method.isStatic else 'self') + '.' + name
168+
## Below change make by VSK on Apr 16, 2020 so as to not generate any Python classmethods for ASKE
169+
return ('self' if method.isStatic else 'self') + '.' + name
166170
return name
167171

168172
def configHandler(self, part, suffix='Handler', default=None):
@@ -173,20 +177,20 @@ def configHandler(self, part, suffix='Handler', default=None):
173177
def configHandlers(self, part, suffix='Handlers'):
174178
""" Returns config handlers for this type of template """
175179
name = '{0}{1}{2}'.format(self.typeName, part, suffix)
176-
return imap(self.toIter, chain(*self.config.every(name, [])))
180+
return map(self.toIter, self.config.last(name, ()))
177181

178182
def dump(self, fd, level=0):
179183
""" Writes the Python source code for this template to the given file. """
180184
indent, isNotNone = level * self.indent, lambda x:x is not None
181185
lineFormat = '{0}{1}\n'.format
182-
for line in ifilter(isNotNone, self.iterPrologue()):
186+
for line in filter(isNotNone, self.iterPrologue()):
183187
line = lineFormat(indent, line)
184188
fd.write(line if line.strip() else '\n')
185-
for item in ifilter(isNotNone, self.iterHead()):
189+
for item in filter(isNotNone, self.iterHead()):
186190
item.dump(fd, level+1)
187191
for item in self.iterBody():
188192
item.dump(fd, level+1)
189-
for line in ifilter(isNotNone, self.iterEpilogue()):
193+
for line in filter(isNotNone, self.iterEpilogue()):
190194
line = lineFormat(indent, line)
191195
fd.write(line if line.strip() else '\n')
192196

@@ -200,7 +204,7 @@ def dumpRepr(self, fd, level=0):
200204
""" Writes a debug string for this template to the given file. """
201205
indent, default = self.indent, lambda x, y:None
202206
fd.write('{0}{1!r}\n'.format(indent*level, self))
203-
for child in ifilter(None, self.children):
207+
for child in filter(None, self.children):
204208
getattr(child, 'dumpRepr', default)(fd, level+1)
205209

206210
@property
@@ -230,7 +234,7 @@ def iterPrologue(self):
230234
def iterHead(self):
231235
""" Yields the items in the head of this template. """
232236
items = chain(*(h(self) for h in self.configHandlers('Head')))
233-
return imap(self.toExpr, items)
237+
return map(self.toExpr, items)
234238

235239
def iterBody(self):
236240
""" Yields the items in the body of this template. """
@@ -310,10 +314,6 @@ def __repr__(self):
310314
if isinstance(self.right, (basestring, )) and self.right:
311315
parts.append(colors.white('right:') + colors.yellow(self.right))
312316
showfs = False
313-
if self.modifiers:
314-
parts.append(colors.white('modifiers:') + colors.cyan(','.join(self.modifiers)))
315-
if self.type:
316-
parts.append(colors.white('type:') + colors.cyan(self.type))
317317
if showfs:
318318
parts.append(colors.white('format:') + colors.yellow(self.fs))
319319
if self.tail:

0 commit comments

Comments
 (0)