Description: converted code to python3
 modified code and Makefiles to be compatible with python 3
 unfortunately, lost compatibility with python2.
 .
Author: Joao Pedro Pedroso <jpp@fc.up.pt>
Bug-Debian: http://bugs.debian.org/638649

---
The information above should follow the Patch Tagging Guidelines, please
checkout http://dep.debian.net/deps/dep3/ to learn about the format. Here
are templates for supplementary fields that you might want to add:

Origin: <vendor|upstream|other>, <url of original patch>
Bug: <url in upstream bugtracker>
Bug-Debian: http://bugs.debian.org/<bugnumber>
Bug-Ubuntu: https://launchpad.net/bugs/<bugnumber>
Forwarded: <no|not-needed|url proving that it has been forwarded>
Reviewed-By: <name and email of someone who approved the patch>
Last-Update: <YYYY-MM-DD>

--- python-glpk-0.4.45.orig/examples/test.py
+++ python-glpk-0.4.45/examples/test.py
@@ -1,17 +1,17 @@
 from glpk import *
 
 def problem0():
-    print "\n>>problem 0:\n"    
+    print("\n>>problem 0:\n")    
     problem = glpk("models/samp1.mps")
     problem.solve()
     
-    print problem.solution()
+    print(problem.solution())
     problem = glpk("models/plan.lp")
     problem.solve()
-    print problem.solution()
+    print(problem.solution())
 
 def problem1():
-    print "\n>>problem 1:\n"
+    print("\n>>problem 1:\n")
     problem = glpk("models/net3.mod","models/net3.dat")
     problem.solve()
     sol1 = problem.solution()
@@ -23,28 +23,28 @@ def problem1():
     problem.solve()
     sol2 = problem.solution()
     
-    print "solution1:", sol1
-    print "solution2:", sol2
+    print("solution1:", sol1)
+    print("solution2:", sol2)
 
 def problem2():
-    print "\n>>problem 2:\n"
+    print("\n>>problem 2:\n")
     problem = glpk("models/multi.mod","models/multi.dat")
     problem.update()
     problem.solve()
-    print problem.supply['GARY','bands']
-    print "solution:", problem.solution()
+    print(problem.supply['GARY','bands'])
+    print("solution:", problem.solution())
 
 def problem3():
-    print "\n>>problem 3:\n"
+    print("\n>>problem 3:\n")
     problem = glpk("models/steel.mod","models/steel.dat")
     problem.update()
     problem.solve()
-    print "solution:", problem.solution()
-    print "problem.total_profit =", problem.total_profit
-    print "problem.Make =", problem.Make
+    print("solution:", problem.solution())
+    print("problem.total_profit =", problem.total_profit)
+    print("problem.Make =", problem.Make)
     
 def problem4():
-    print "\n>>problem 4:\n"
+    print("\n>>problem 4:\n")
     problem = glpk("models/steel.mod")
     problem.PROD = ['bands', 'coils']
     problem.rate['bands'] = 200
@@ -56,33 +56,33 @@ def problem4():
     problem.avail = 40
     problem.update()
     problem.solve()
-    print "problem.solution() =", problem.solution()
-    print "problem.sets() =", problem.sets()
-    print "problem.parameters() =", problem.parameters()
-    print "problem.variables() =", problem.variables()
-    print "problem.constraints() =", problem.constraints()
-    print "problem.objectives() =", problem.objectives()
-    print "problem.Make =", problem.Make
-    print "problem.Make['bands'] =", problem.Make['bands']
-    print "problem.Make['bands'].value() =", problem.Make['bands'].value()    
-    print "problem.total_profit =", problem.total_profit
-    print "problem.total_profit.value() =", problem.total_profit.value()
+    print("problem.solution() =", problem.solution())
+    print("problem.sets() =", problem.sets())
+    print("problem.parameters() =", problem.parameters())
+    print("problem.variables() =", problem.variables())
+    print("problem.constraints() =", problem.constraints())
+    print("problem.objectives() =", problem.objectives())
+    print("problem.Make =", problem.Make)
+    print("problem.Make['bands'] =", problem.Make['bands'])
+    print("problem.Make['bands'].value() =", problem.Make['bands'].value())    
+    print("problem.total_profit =", problem.total_profit)
+    print("problem.total_profit.value() =", problem.total_profit.value())
     problem.Make >= 10
     problem.Make['coils'] <= 100
     0 <= problem.total_profit <= 100000
 
     problem.Make <= 15
     problem.Make['bands'] <= 10
-    print problem.Make['bands']._bounds()
+    print(problem.Make['bands']._bounds())
     #problem.Time <= 10
     
     
-    print "problem.total_profit =", problem.total_profit    
+    print("problem.total_profit =", problem.total_profit)    
     problem.solve()
     #print "problem.Make.bounds() =", problem.Make._bounds()
     #print "problem.Make['coils'].bounds() =", problem.Make['coils']._bounds()
     #print "problem.Make['bands'].bounds() =", problem.Make['bands']._bounds()       
-    print "problem.solution() =", problem.solution()
+    print("problem.solution() =", problem.solution())
 
 if __name__ == "__main__":
     problem0()
--- python-glpk-0.4.45.orig/src/Makefile
+++ python-glpk-0.4.45/src/Makefile
@@ -1,10 +1,11 @@
+PYVERS :=$(shell py3versions -d)
 all:
 	make -C swig all
 	cp swig/glpkpi.py python/glpkpi.py
-	python setup.py build
+	$(PYVERS) setup.py build
 
 install: all
-	python setup.py install
+	$(PYVERS) setup.py install
 
 clean:
 	make -C swig clean
--- python-glpk-0.4.45.orig/src/python/parsetab.py
+++ python-glpk-0.4.45/src/python/parsetab.py
@@ -9,18 +9,18 @@ _lr_signature = '\xf2,\xacM\x91,\x8de~=\
 _lr_action_items = {'RBRACK':([13,14,15,17,19,20,22,23,24,],[-15,-16,-13,-14,-9,23,-10,-12,-11,]),'PROMPT':([0,1,2,4,6,13,14,15,16,17,18,19,22,23,24,],[-2,3,-1,-3,-4,-15,-16,-13,-8,-14,-7,-9,-10,-12,-11,]),'STRING':([3,8,9,11,12,13,14,15,17,18,19,20,21,22,23,24,],[7,13,13,13,13,-15,-16,-13,-14,13,-9,13,13,-10,-12,-11,]),'RPAREN':([13,14,15,17,19,21,22,23,24,],[-15,-16,-13,-14,-9,24,-10,-12,-11,]),'FLOAT':([8,9,11,12,13,14,15,17,18,19,20,21,22,23,24,],[15,15,15,15,-15,-16,-13,-14,15,-9,15,15,-10,-12,-11,]),'LBRACK':([7,8,9,11,12,13,14,15,17,18,19,20,21,22,23,24,],[11,11,11,11,11,-15,-16,-13,-14,11,-9,11,11,-10,-12,-11,]),'LPAREN':([7,8,9,11,12,13,14,15,17,18,19,20,21,22,23,24,],[12,12,12,12,12,-15,-16,-13,-14,12,-9,12,12,-10,-12,-11,]),'INTEGER':([8,9,11,12,13,14,15,17,18,19,20,21,22,23,24,],[17,17,17,17,-15,-16,-13,-14,17,-9,17,17,-10,-12,-11,]),':':([5,7,10,23,24,],[9,-5,-6,-12,-11,]),'=':([5,7,10,23,24,],[8,-5,-6,-12,-11,]),'$end':([0,1,2,4,6,13,14,15,16,17,18,19,22,23,24,],[-2,0,-1,-3,-4,-15,-16,-13,-8,-14,-7,-9,-10,-12,-11,]),}
 
 _lr_action = { }
-for _k, _v in _lr_action_items.items():
+for _k, _v in list(_lr_action_items.items()):
    for _x,_y in zip(_v[0],_v[1]):
-      if not _lr_action.has_key(_x):  _lr_action[_x] = { }
+      if _x not in _lr_action:  _lr_action[_x] = { }
       _lr_action[_x][_k] = _y
 del _lr_action_items
 
 _lr_goto_items = {'decl':([1,],[2,]),'set':([3,],[4,]),'name':([3,],[5,]),'tuple':([7,8,9,11,12,18,20,21,],[10,14,14,14,14,14,14,14,]),'list':([9,11,12,],[18,20,21,]),'param':([3,],[6,]),'record':([8,9,11,12,18,20,21,],[16,19,19,19,22,22,22,]),'data':([0,],[1,]),}
 
 _lr_goto = { }
-for _k, _v in _lr_goto_items.items():
+for _k, _v in list(_lr_goto_items.items()):
    for _x,_y in zip(_v[0],_v[1]):
-       if not _lr_goto.has_key(_x): _lr_goto[_x] = { }
+       if _x not in _lr_goto: _lr_goto[_x] = { }
        _lr_goto[_x][_k] = _y
 del _lr_goto_items
 _lr_productions = [
--- python-glpk-0.4.45.orig/src/python/glpk_parser.py
+++ python-glpk-0.4.45/src/python/glpk_parser.py
@@ -28,8 +28,8 @@ import ply.lex as lex
 import ply.yacc as yacc
 
 # Get the token map from the lexer.
-from glpk_lex import *
-from model_objects import *
+from .glpk_lex import *
+from .model_objects import *
 
 class regexcache:
     def __init__(self):
@@ -209,7 +209,7 @@ class glpk_parser:
             s += decl+'\n'
         s += "end;"
         f = open(filename, "w")
-        print >>f, s
+        print(s, file=f)
 
 def load_data(parser, outputfile, glpkobj):    
     text = open(outputfile).read()
@@ -334,9 +334,9 @@ def p_record(p):
 
 def p_error(p):
     # Error rule for syntax errors
-    print "[",p,"]"
-    print "<",p.value,">"
-    print "Syntax error in input!"
+    print("[",p,"]")
+    print("<",p.value,">")
+    print("Syntax error in input!")
     import sys
     sys.exit(0)
 
@@ -346,7 +346,7 @@ def show_tokens():
     while True:
         tok = lexer.token()
         if not tok: break
-        print tok
+        print(tok)
 
 # Build the parser
 yacc.yacc(write_tables=0, debug=0)
--- python-glpk-0.4.45.orig/src/python/__init__.py
+++ python-glpk-0.4.45/src/python/__init__.py
@@ -22,9 +22,9 @@
 -- Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 -- 02110-1301, USA.
 """
-from model_objects import *
-from glpk_parser import *
-from glpkpi import *
+from .model_objects import *
+from .glpk_parser import *
+from .glpkpi import *
 from array import *
 import sys
 import os
@@ -57,28 +57,28 @@ class glpk:
 
         if mod_file == None:
             if VERBOSE:
-                print "creating problem -- no file associated"
+                print("creating problem -- no file associated")
             self._lp = glp_create_prob();
         elif mod_file.find(".mps") != -1:
             if VERBOSE:
-                print "creating problem from mps file"
+                print("creating problem from mps file")
             self._ptype = "mps"
             self._lp = glp_create_prob();
             ret = glp_read_mps(self._lp, GLP_MPS_FILE, None, mod_file);# !self._parm
             if ret != 0:
-                print "Error reading model", mod_file
+                print("Error reading model", mod_file)
                 raise IOError
             self._read_variables()
         elif mod_file.find(".lp") != -1:
             if VERBOSE:
-                print "creating problem from lp file"
+                print("creating problem from lp file")
             self._ptype = "lp"
             self._lp = glp_create_prob();
             ret = glp_read_lp(self._lp, None, mod_file);# !self._parm
             self._read_variables()
         elif mod_file.find(".mod") != -1:
             if VERBOSE:
-                print "creating problem from mod file"
+                print("creating problem from mod file")
             self._ptype = "mod"
             t = mod_file.rfind('.')
             if t<0: name = mod_file
@@ -89,7 +89,7 @@ class glpk:
             parser = glpk_parser(mod_file, dat_file)
             parser.generate_model(tmp_file)
             if VERBOSE:
-                print "temporary model file '%s' created" % (tmp_file)
+                print("temporary model file '%s' created" % (tmp_file))
             
             # read model           
             mod_file = tmp_file
@@ -97,7 +97,7 @@ class glpk:
             self._tran = glp_mpl_alloc_wksp();
             ret = glp_mpl_read_model(self._tran, mod_file, 0);
             if ret != 0:
-                print "Error reading model", mod_file
+                print("Error reading model", mod_file)
                 raise IOError
             
             # load data        
@@ -106,7 +106,7 @@ class glpk:
             os.close(f)
             ret = glp_mpl_generate(self._tran, output)
             if ret != 0:
-                print "Error generating model"
+                print("Error generating model")
                 raise IOError
             load_data(parser, output, self)
             if not DEBUG:
@@ -127,18 +127,18 @@ class glpk:
         # read model
         s = self._dump()
         f, mod_file = tempfile.mkstemp()
-        os.write(f, s)
+        os.write(f, s.encode())
         os.close(f)
         self._lp = glp_create_prob();
         self._tran = glp_mpl_alloc_wksp();        
         ret = glp_mpl_read_model(self._tran, mod_file, 0);
         if ret != 0:
-            print "Error reading model", mod_file
+            print("Error reading model", mod_file)
             raise IOError        
         #if not VERBOSE: glp_term_out(GLP_OFF);            
         ret = glp_mpl_generate(self._tran, None);
         if ret != 0:
-            print "Error generating model"
+            print("Error generating model")
             raise IOError
         glp_mpl_build_prob(self._tran, self._lp);
         #if not VERBOSE: glp_term_out(GLP_ON);
@@ -237,7 +237,7 @@ class glpk:
         bounds = self._default_bounds = {}  
         
         cols = self._cols = {} 
-        for i in xrange(1,glp_get_num_cols(self._lp)+1):
+        for i in range(1,glp_get_num_cols(self._lp)+1):
             name = glp_get_col_name(self._lp, i)
             tname = name[:max(0,name.find('['))]         
             bounds[name] = self._get_col_bnds(i)
@@ -249,7 +249,7 @@ class glpk:
                     cols[tname].append(i)
                     
         rows = self._rows = {}
-        for i in xrange(1,glp_get_num_rows(self._lp)+1):
+        for i in range(1,glp_get_num_rows(self._lp)+1):
             name = glp_get_row_name(self._lp, i)
             tname = name[:max(0,name.find('['))]
             bounds[name] = self._get_row_bnds(i)
@@ -300,9 +300,10 @@ class glpk:
                 for i in rows[name]:
                     glp_set_row_bnds(self._lp, i, tp, lb, ub);
             else:
-                print 'model object not found!'
+                print('model object not found!')
         
-    def _set_bounds(self, varname,(_type,_value)):
+    def _set_bounds(self, varname, xxx_todo_changeme):
+        (_type,_value) = xxx_todo_changeme
         dic = self._bounds
         if varname in dic:
             bnds = dic[varname]
@@ -329,14 +330,14 @@ class glpk:
         if glp_get_num_int(self._lp) == 0:  # problem is continuous
             value = glp_get_obj_val(self._lp)
             sol[name] = value
-            for i in xrange(1,glp_get_num_cols(self._lp)+1):
+            for i in range(1,glp_get_num_cols(self._lp)+1):
                 name = glp_get_col_name(self._lp, i)
                 value = glp_get_col_prim(self._lp, i)
                 sol[name] = value
         else:   # problem is MIP
             value = glp_mip_obj_val(self._lp)
             sol[name] = value
-            for i in xrange(1,glp_get_num_cols(self._lp)+1):
+            for i in range(1,glp_get_num_cols(self._lp)+1):
                 name = glp_get_col_name(self._lp, i)
                 if glp_get_col_kind(self._lp, i) == GLP_CV:
                     value = glp_mip_col_val(self._lp, i)
@@ -344,14 +345,14 @@ class glpk:
                     # to avoid finite precision problems:
                     value = int(round(glp_mip_col_val(self._lp, i),0))
                 else:
-                    print "unkown col kind"
+                    print("unkown col kind")
                     raise AttributeError
                 sol[name] = value             
         self._sol = sol
         load_solution(sol, self)        
         
     def __del__(self):
-        print "deleting glpk object"
+        print("deleting glpk object")
         self._delete()         
         
     def __getitem__(self, name):
@@ -435,7 +436,7 @@ class glpk:
             if self._tran:
                 ret = glp_mpl_postsolve(self._tran, self._lp, GLP_MIP);
                 if ret != 0:
-                    print "Error on postsolving model"
+                    print("Error on postsolving model")
                     raise AttributeError
         if instantiate:
             self._instantiate_solution()     
--- python-glpk-0.4.45.orig/src/python/glpk_lex.py
+++ python-glpk-0.4.45/src/python/glpk_lex.py
@@ -82,7 +82,7 @@ t_ignore  = ' \r\t,'
 
 # Error handling rule
 def t_error(t):
-    print "Illegal character %s" % repr(t.value[0])
+    print("Illegal character %s" % repr(t.value[0]))
     t.lexer.skip(1)
 
 # Build the lexer
--- python-glpk-0.4.45.orig/src/swig/Makefile
+++ python-glpk-0.4.45/src/swig/Makefile
@@ -1,10 +1,10 @@
-PYVERS := $(shell pyversions -d)
+PYVERS :=$(shell py3versions -d)
 DIR := $(shell basename `pwd`)
 
 all:	_glpkpi.so glpkpi.py
 
 glpkpi.py:	glpkpi.i glpkpi.c glpkpi.h Makefile
-	swig -python  glpkpi.i
+	swig -python -py3 glpkpi.i
 	sed -i 's/:in /:_in /g' glpkpi.py
 
 _glpkpi.so:	glpkpi.py glpkpi.o glpkpi_wrap.o
@@ -15,7 +15,7 @@ glpkpi.o:	glpkpi.c
 glpkpi_wrap.o:	glpkpi_wrap.c
 	gcc -Wall -c -fPIC glpkpi_wrap.c -DHAVE_CONFIG_H -I/usr/include/$(PYVERS) -I/usr/lib/$(PYVERS)/config
 glpkpi_wrap.c:	glpkpi.i glpkpi.c glpkpi.h Makefile
-	swig -python  glpkpi.i
+	swig -python -py3 glpkpi.i
 
 clean:
 	rm -f *.o *~ *.pyc *.pyo _*.so glpkpi_wrap.c glpkpi.py
