Skip to content

Commit 366f8cf

Browse files
committed
updated Python 3.5 support
1 parent 394a3dd commit 366f8cf

File tree

10 files changed

+128
-105
lines changed

10 files changed

+128
-105
lines changed

src/CBCPLEX.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
2020
Author: Brett G. Olivier
2121
Contact email: bgoli@users.sourceforge.net
22-
Last edit: $Author: bgoli $ ($Id: CBCPLEX.py 575 2017-04-13 12:18:44Z bgoli $)
22+
Last edit: $Author: bgoli $ ($Id: CBCPLEX.py 629 2017-10-24 22:01:14Z bgoli $)
2323
2424
"""
2525
## gets rid of "invalid variable name" info
@@ -485,7 +485,7 @@ def cplx_setOutputStreams(lp, mode='default'):
485485
CPLX_SILENT_MODE = True
486486
elif CPLX_RESULT_STREAM == 'file':
487487
if CPLX_RESULT_STREAM_FILE == None:
488-
CPLX_RESULT_STREAM_FILE = file('cplex_output.log', 'w')
488+
CPLX_RESULT_STREAM_FILE = open('cplex_output.log', 'w')
489489
lp.set_log_stream(CPLX_RESULT_STREAM_FILE)
490490
lp.set_results_stream(CPLX_RESULT_STREAM_FILE)
491491
CPLX_SILENT_MODE = True

src/CBCommon.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
2020
Author: Brett G. Olivier
2121
Contact email: bgoli@users.sourceforge.net
22-
Last edit: $Author: bgoli $ ($Id: CBCommon.py 616 2017-08-23 11:47:47Z bgoli $)
22+
Last edit: $Author: bgoli $ ($Id: CBCommon.py 629 2017-10-24 22:01:14Z bgoli $)
2323
2424
"""
2525
## gets rid of "invalid variable name" info
@@ -98,9 +98,9 @@
9898
#except Exception as ex:
9999
#print(ex)
100100

101-
#def flushLogToFile(fname):
101+
#def flushLogToopen(fname):
102102
#global CBMPYLOG
103-
#F = file(fname, 'w')
103+
#F = open(fname, 'w')
104104
#CBMPYLOG.seek(0)
105105
#F.write(CBMPYLOG.read())
106106
#F.flush()
@@ -327,7 +327,8 @@ def getGPRasDictFromString(node, out):
327327
if isinstance(node, ast.Expr):
328328
children = [node.value]
329329
else:
330-
children = node.values
330+
#children = node.values
331+
children = []
331332
cntr2 = 0
332333
for v in children:
333334
if isinstance(v, ast.BoolOp) and isinstance(v.op, ast.And):

src/CBConfig.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
2020
Author: Brett G. Olivier
2121
Contact email: bgoli@users.sourceforge.net
22-
Last edit: $Author: bgoli $ ($Id: CBConfig.py 627 2017-10-20 12:23:19Z bgoli $)
22+
Last edit: $Author: bgoli $ ($Id: CBConfig.py 629 2017-10-24 22:01:14Z bgoli $)
2323
2424
"""
2525
## gets rid of "invalid variable name" info
@@ -38,13 +38,13 @@
3838
# release
3939

4040
try:
41-
STATUS = '$Rev: 627 $'.replace('Rev: ', '').replace('$', '').strip()
41+
STATUS = '$Rev: 629 $'.replace('Rev: ', '').replace('$', '').strip()
4242
except Exception:
4343
STATUS = ''
4444

4545
__CBCONFIG__ = {'VERSION_MAJOR' : 0,
4646
'VERSION_MINOR' : 7,
47-
'VERSION_MICRO' : 18,
47+
'VERSION_MICRO' : 19,
4848
'VERSION_STATUS' : STATUS,
4949
'VERSION' : None,
5050
'DEBUG' : False,

src/CBModel.py

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
2020
Author: Brett G. Olivier
2121
Contact email: bgoli@users.sourceforge.net
22-
Last edit: $Author: bgoli $ ($Id: CBModel.py 625 2017-10-20 12:00:53Z bgoli $)
22+
Last edit: $Author: bgoli $ ($Id: CBModel.py 629 2017-10-24 22:01:14Z bgoli $)
2323
2424
"""
2525
## gets rid of "invalid variable name" info
@@ -34,7 +34,14 @@
3434
from __future__ import absolute_import
3535
#from __future__ import unicode_literals
3636

37-
import numpy, re, time, weakref, copy, json, urllib2, ast
37+
import numpy, re, time, weakref, copy, json, ast
38+
39+
try:
40+
from urllib2 import quote as urlquote
41+
from urllib2 import unquote as urlunquote
42+
except ImportError:
43+
from urllib.parse import quote as urlquote
44+
from urllib.parse import unquote as urlunquote
3845

3946
global GENE_CNTR
4047
GENE_CNTR = 0
@@ -218,7 +225,10 @@ def setNotes(self, notes):
218225
219226
"""
220227
#self.notes = self.__urlEncode(notes)
221-
self.notes = notes.decode(errors='ignore')
228+
try:
229+
self.notes = notes.decode(errors='ignore')
230+
except AttributeError:
231+
self.notes=notes
222232

223233
def setAnnotation(self, key, value):
224234
"""
@@ -347,7 +357,7 @@ def serializeToDisk(self, filename, protocol=2):
347357
# Reimplemented in Model
348358
349359
"""
350-
F = file(filename, 'wb')
360+
F = open(filename, 'wb')
351361
pickle.dump(self, F, protocol=protocol)
352362
F.close()
353363

@@ -440,7 +450,7 @@ def __urlEncode(self, txt):
440450
441451
"""
442452
try:
443-
txt = urllib2.quote(txt.encode(self.__text_encoding__, errors='replace'), safe='')
453+
txt = urlquote(txt.encode(self.__text_encoding__, errors='replace'), safe='')
444454
except UnicodeDecodeError as why:
445455
pass
446456
#print(txt)
@@ -451,7 +461,7 @@ def __urlDecode(self, txt):
451461
Decodes a URL encoded string
452462
453463
"""
454-
return urllib2.unquote(txt)
464+
return urlunquote(txt)
455465

456466
class Model(Fbase):
457467
"""
@@ -716,7 +726,7 @@ def serializeToDisk(self, filename, protocol=2):
716726
# overloaded in CBModel
717727
718728
"""
719-
F = file(filename, 'wb')
729+
F = open(filename, 'wb')
720730
pickle.dump(self, F, protocol=protocol)
721731
F.close()
722732
self.__setGlobalIdStore__()
@@ -4584,7 +4594,7 @@ def addAssociation(self, assoc):
45844594
45854595
"""
45864596
#self.assoc = assoc
4587-
raise RuntimeError, '\nThis method has ceased to exist'
4597+
raise RuntimeError('\nThis method has ceased to exist')
45884598

45894599
def createAssociationAndGeneRefsFromTree(self, gprtree, altlabels=None):
45904600
"""
@@ -4633,7 +4643,7 @@ def createAssociationAndGeneRefsFromTree(self, gprtree, altlabels=None):
46334643
self.buildEvalFunc()
46344644

46354645
def createAssociationAndGeneRefs(self):
4636-
raise RuntimeError, "\n\nDEPRECATED CHANGE NOW!"
4646+
raise RuntimeError("\n\nDEPRECATED CHANGE NOW!")
46374647

46384648
def createAssociationAndGeneRefsFromString(self, assoc, altlabels=None):
46394649
"""
@@ -4688,7 +4698,7 @@ def createAssociationAndGeneRefsFromString(self, assoc, altlabels=None):
46884698
except SyntaxError:
46894699
err = '\nError in Gene Association String: {}\n'.format(assoc)
46904700
#print(err)
4691-
raise SyntaxError, err
4701+
raise SyntaxError(err)
46924702
self.setTree(newtree)
46934703
genes = self.__getGeneRefsfromGPRDict__(newtree, [])
46944704
genes.sort()
@@ -4788,7 +4798,7 @@ def getAssociationStr(self, use_labels=False):
47884798
keymap = {}
47894799
for g in self.generefs:
47904800
keymap[g] = self.__objref__().getGene(g).getLabel()
4791-
keys = keymap.keys()
4801+
keys = list(keymap.keys())
47924802
keys.sort(reverse=True)
47934803
for k in keys:
47944804
out = out.replace(k, keymap[k])

src/CBNetDB.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
2020
Author: Brett G. Olivier
2121
Contact email: bgoli@users.sourceforge.net
22-
Last edit: $Author: bgoli $ ($Id: CBNetDB.py 575 2017-04-13 12:18:44Z bgoli $)
22+
Last edit: $Author: bgoli $ ($Id: CBNetDB.py 629 2017-10-24 22:01:14Z bgoli $)
2323
2424
"""
2525

@@ -29,7 +29,12 @@
2929
#from __future__ import unicode_literals
3030

3131
import os, time, re, webbrowser, csv
32-
import urllib2
32+
try:
33+
from urllib2 import quote as urlquote
34+
from urllib2 import unquote as urlunquote
35+
except ImportError:
36+
from urllib.parse import quote as urlquote
37+
from urllib.parse import unquote as urlunquote
3338

3439
HAVE_SQLITE2 = False
3540
HAVE_SQLITE3 = False
@@ -51,22 +56,21 @@
5156

5257

5358
class NetDBbase(object):
54-
urllib2 = urllib2
5559
text_encoding = 'utf8'
5660

5761
def URLEncode(self, txt):
5862
"""
5963
URL encodes a string.
6064
6165
"""
62-
return self.urllib2.quote(txt.encode(self.text_encoding))
66+
return urlquote(txt.encode(self.text_encoding))
6367

6468
def URLDecode(self, txt):
6569
"""
6670
Decodes a URL encoded string
6771
6872
"""
69-
return self.urllib2.unquote(txt)
73+
return urlunquote(txt)
7074

7175
class DBTools(NetDBbase):
7276
"""
@@ -88,7 +92,7 @@ def __init__(self):
8892
self.sqlite = sqlite2
8993
self.sqlite_version = 2
9094
else:
91-
raise RuntimeError, "\nSQLite not installed"
95+
raise RuntimeError("\nSQLite not installed")
9296

9397
self.db_tables = []
9498

src/CBReadtxt.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
2020
Author: Brett G. Olivier
2121
Contact email: bgoli@users.sourceforge.net
22-
Last edit: $Author: bgoli $ ($Id: CBReadtxt.py 575 2017-04-13 12:18:44Z bgoli $)
22+
Last edit: $Author: bgoli $ ($Id: CBReadtxt.py 629 2017-10-24 22:01:14Z bgoli $)
2323
2424
"""
2525

@@ -124,7 +124,7 @@ def getReactions(fname, reaction_prefix='R_', has_header=False, save_rpt=False,
124124
rF.close()
125125

126126
if save_rpt:
127-
F = file('csv_read_rpt.txt','w')
127+
F = open('csv_read_rpt.txt','w')
128128
F.write('\nCSV Read Report\n********************\n')
129129
F.write('\nDuplicate entries ignored:\n')
130130
for d in real_duplicates:
@@ -200,7 +200,7 @@ def getReactions_old_format(fname, reaction_prefix='R_', has_header=False, save_
200200
rF.close()
201201

202202
if save_rpt:
203-
F = file('csv_read_rpt.txt','w')
203+
F = open('csv_read_rpt.txt','w')
204204
F.write('\nCSV Read Report\n********************\n')
205205
F.write('\nDuplicate entries ignored:\n')
206206
for d in real_duplicates:

src/CBSolver2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def addLinearConstraint(self, cid, arr, sense, rhs, overwrite=False):
105105
if self.linear_constraints is None:
106106
self.linear_constraints = {}
107107
if cid in self.linear_constraints and not overwrite:
108-
raise RuntimeWarning, '\nConstraint id {} already exists.'.format(cid)
108+
raise RuntimeWarning('\nConstraint id {} already exists.'.format(cid))
109109
else:
110110
self.linear_constraints[cid] = (arr, sense, rhs)
111111

0 commit comments

Comments
 (0)