Bug#1080028: antlr: please update python3-compat.patch to allow python3-six removal

Alexandre Detiste alexandre.detiste at gmail.com
Thu Aug 29 20:08:55 BST 2024


Package: antlr
Version: 2.7.7+dfsg-13
Severity: normal

Hi,

Here's an updated file to replace the old one.

Only 3 lines were changed to keep delta as low as possible.

Then python3-six can be removed from debian/control.

Greetings
-------------- next part --------------
Description: Python3 compat
Author: Thomas Goirand <zigo at debian.org>
Bug-Debian: https://bugs.debian.org/614505
Forwarded: no
Last-Update: 2017-10-24

--- antlr-2.7.7+dfsg.orig/lib/python/antlr/antlr.py
+++ antlr-2.7.7+dfsg/lib/python/antlr/antlr.py
@@ -2,13 +2,11 @@
 ## details..........Copyright (C) Wolfgang Haefelinger, 2004.
 
 ## get sys module
+from __future__ import print_function
 import sys
 
-version = sys.version.split()[0]
-if version < '2.2.1':
-    False = 0
-if version < '2.3':
-    True = not False
+
+
 
 ###xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx###
 ###                     global symbols                             ###
@@ -45,7 +43,7 @@ def version():
 
 def error(fmt,*args):
     if fmt:
-        print "error: ", fmt % tuple(args)
+        print("error: ", fmt % tuple(args))
 
 def ifelse(cond,_then,_else):
     if cond :
@@ -55,7 +53,7 @@ def ifelse(cond,_then,_else):
     return r
 
 def is_string_type(x):
-    return  (isinstance(x,str) or isinstance(x,unicode))
+    return  (isinstance(x,str) or isinstance(x,str))
 
 def assert_string_type(x):
     assert is_string_type(x)
@@ -549,9 +547,9 @@ class Token(object):
 Token.badToken = Token( type=INVALID_TYPE, text="<no text>")
 
 if __name__ == "__main__":
-    print "testing .."
+    print("testing ..")
     T = Token.badToken
-    print T
+    print(T)
 
 ###xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx###
 ###                       CommonToken                              ###
@@ -622,16 +620,16 @@ class CommonToken(Token):
 
 if __name__ == '__main__' :
     T = CommonToken()
-    print T
+    print(T)
     T = CommonToken(col=15,line=1,text="some text", type=5)
-    print T
+    print(T)
     T = CommonToken()
     T.setLine(1).setColumn(15).setText("some text").setType(5)
-    print T
-    print T.getLine()
-    print T.getColumn()
-    print T.getText()
-    print T.getType()
+    print(T)
+    print(T.getLine())
+    print(T.getColumn())
+    print(T.getText())
+    print(T.getType())
 
 ###xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx###
 ###                    CommonHiddenStreamToken                     ###
@@ -811,7 +809,7 @@ class CharBuffer(InputBuffer):
 
                 ### use unicode chars instead of ASCII ..
                 self.queue.append(c)
-        except Exception,e:
+        except Exception as e:
             raise CharStreamIOException(e)
         ##except: # (mk) Cannot happen ...
             ##error ("unexpected exception caught ..")
@@ -901,7 +899,7 @@ class TokenStreamSelector(TokenStream):
         while 1:
             try:
                 return self._input.nextToken()
-            except TokenStreamRetryException,r:
+            except TokenStreamRetryException as r:
                 ### just retry "forever"
                 pass
 
@@ -1342,23 +1340,23 @@ class CharScanner(TokenStream):
         self.setColumn(nc)
 
     def panic(self,s='') :
-        print "CharScanner: panic: " + s
+        print("CharScanner: panic: " + s)
         sys.exit(1)
 
     def reportError(self,ex) :
-        print ex
+        print(ex)
 
     def reportError(self,s) :
         if not self.getFilename():
-            print "error: " + str(s)
+            print("error: " + str(s))
         else:
-            print self.getFilename() + ": error: " + str(s)
+            print(self.getFilename() + ": error: " + str(s))
 
     def reportWarning(self,s) :
         if not self.getFilename():
-            print "warning: " + str(s)
+            print("warning: " + str(s))
         else:
-            print self.getFilename() + ": warning: " + str(s)
+            print(self.getFilename() + ": warning: " + str(s))
 
     def resetText(self) :
         self.text.setLength(0)
@@ -1418,16 +1416,16 @@ class CharScanner(TokenStream):
         return c.__class__.lower()
 
     def traceIndent(self):
-        print ' ' * self.traceDepth
+        print(' ' * self.traceDepth)
 
     def traceIn(self,rname):
         self.traceDepth += 1
         self.traceIndent()
-        print "> lexer %s c== %s" % (rname,self.LA(1))
+        print("> lexer %s c== %s" % (rname,self.LA(1)))
 
     def traceOut(self,rname):
         self.traceIndent()
-        print "< lexer %s c== %s" % (rname,self.LA(1))
+        print("< lexer %s c== %s" % (rname,self.LA(1)))
         self.traceDepth -= 1
 
     def uponEOF(self):
@@ -1492,7 +1490,7 @@ class CharScanner(TokenStream):
                 func=args[0]
                 args=args[1:]
                 apply(func,args)
-            except RecognitionException, e:
+            except RecognitionException as e:
                 ## catastrophic failure
                 self.reportError(e);
                 self.consume();
@@ -1548,7 +1546,7 @@ class BitSet(object):
 
     def __init__(self,data=None):
         if not data:
-            BitSet.__init__(self,[long(0)])
+            BitSet.__init__(self,[0])
             return
         if isinstance(data,int):
             BitSet.__init__(self,[long(data)])
@@ -1568,7 +1566,7 @@ class BitSet(object):
     def __str__(self):
         bits = len(self.data) * BitSet.BITS
         s = ""
-        for i in xrange(0,bits):
+        for i in range(0,bits):
             if self.at(i):
                 s += "1"
             else:
@@ -1607,7 +1605,7 @@ class BitSet(object):
 
     def bitMask(self,bit):
         pos = bit & BitSet.MOD_MASK  ## bit mod BITS
-        return (1L << pos)
+        return (1 << pos)
 
     def set(self,bit,on=True):
         # grow bitset as required (use with care!)
@@ -1615,8 +1613,8 @@ class BitSet(object):
         mask = self.bitMask(bit)
         if i>=len(self.data):
             d = i - len(self.data) + 1
-            for x in xrange(0,d):
-                self.data.append(0L)
+            for x in range(0,d):
+                self.data.append(0)
             assert len(self.data) == i+1
         if on:
             self.data[i] |=  mask
@@ -1908,16 +1906,16 @@ class Parser(object):
             col  = x.getLine()
             text = x.getText()
             fmt  = fmt + 'unexpected symbol at line %s (column %s) : "%s"'
-            print >>sys.stderr, fmt % (line,col,text)
+            print(fmt % (line,col,text), file=sys.stderr)
         else:
-            print >>sys.stderr, fmt,str(x)
+            print(fmt,str(x), file=sys.stderr)
 
     def reportWarning(self,s):
         f = self.getFilename()
         if f:
-            print "%s:warning: %s" % (f,str(x))
+            print("%s:warning: %s" % (f,str(x)))
         else:
-            print "warning: %s" % (str(x))
+            print("warning: %s" % (str(x)))
 
     def rewind(self, pos) :
         self.inputState.input.rewind(pos)
@@ -1945,7 +1943,7 @@ class Parser(object):
         self.inputState.input = t
 
     def traceIndent(self):
-        print " " * self.traceDepth
+        print(" " * self.traceDepth)
 
     def traceIn(self,rname):
         self.traceDepth += 1
@@ -2034,20 +2032,20 @@ class LLkParser(Parser):
             self.k = 1
 
     def trace(self,ee,rname):
-        print type(self)
+        print(type(self))
         self.traceIndent()
         guess = ""
         if self.inputState.guessing > 0:
             guess = " [guessing]"
         print(ee + rname + guess)
-        for i in xrange(1,self.k+1):
+        for i in range(1,self.k+1):
             if i != 1:
                 print(", ")
             if self.LT(i) :
                 v = self.LT(i).getText()
             else:
                 v = "null"
-            print "LA(%s) == %s" % (i,v)
+            print("LA(%s) == %s" % (i,v))
         print("\n")
 
     def traceIn(self,rname):
@@ -2108,10 +2106,10 @@ class TreeParser(object):
             raise MismatchedTokenException(getTokenNames(), t, ttype, True)
 
     def reportError(self,ex):
-        print >>sys.stderr,"error:",ex
+        print("error:",ex, file=sys.stderr)
 
     def  reportWarning(self, s):
-        print "warning:",s
+        print("warning:",s)
 
     def setASTFactory(self,f):
         self.astFactory = f
@@ -2123,7 +2121,7 @@ class TreeParser(object):
         self.astFactory.setASTNodeType(nodeType)
 
     def traceIndent(self):
-        print " " * self.traceDepth
+        print(" " * self.traceDepth)
 
     def traceIn(self,rname,t):
         self.traceDepth += 1
@@ -2683,7 +2681,7 @@ class ASTFactory(object):
 
     def error(self, e):
         import sys
-        print >> sys.stderr, e
+        print(e, file=sys.stderr)
 
     def setTokenTypeASTNodeType(self, tokenType, className):
         """
@@ -2770,7 +2768,7 @@ def make(*nodes):
     if not nodes:
         return None
 
-    for i in xrange(0,len(nodes)):
+    for i in range(0,len(nodes)):
         node = nodes[i]
         if node:
             assert isinstance(node,AST)
@@ -2780,7 +2778,7 @@ def make(*nodes):
     if root:
         root.setFirstChild(None)
 
-    for i in xrange(1,len(nodes)):
+    for i in range(1,len(nodes)):
         if not nodes[i]:
             continue
         if not root:


More information about the pkg-java-maintainers mailing list