Skip to content

Commit

Permalink
'U' mode for file opening deprecated in Python 3
Browse files Browse the repository at this point in the history
  • Loading branch information
acroucher committed Feb 18, 2020
1 parent b43e30c commit 8504c3f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
12 changes: 6 additions & 6 deletions mulgrids.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
You should have received a copy of the GNU Lesser General Public License along with PyTOUGH. If not, see <http://www.gnu.org/licenses/>."""

from __future__ import print_function

import sys
from string import ascii_lowercase, ascii_uppercase
from geometry import *
from fixed_format_file import *
Expand Down Expand Up @@ -1285,7 +1285,8 @@ def read_wells(self, geo):
def read(self, filename):
"""Reads MULgraph grid from file"""
self.empty()
geo = fixed_format_file(filename, 'rU',
mode = 'r' if sys.version_info > (3,) else 'rU'
geo = fixed_format_file(filename, mode,
mulgrid_format_specification, self.read_function)
self.read_header(geo)
if self.type == 'GENER':
Expand Down Expand Up @@ -1558,7 +1559,8 @@ def from_gmsh(self, filename, layers, convention = 0, atmos_type = 2,
specified layer structure."""
grid = mulgrid(type = 'GENER', convention = convention, atmos_type = atmos_type)
grid.empty()
gmsh = open(filename, 'rU')
mode = 'r' if sys.version_info > (3,) else 'rU'
gmsh = open(filename, mode)
line = ''
chars = uniqstring(chars)
while not '$Nodes' in line: line = gmsh.readline()
Expand Down Expand Up @@ -3673,7 +3675,6 @@ def fit_columns(self, data, alpha = 0.1, beta = 0.1, columns = [],
if grid_boundary: bounds = geo.boundary_polygon
else: bounds = None
qtree = geo.column_quadtree(columns)
import sys
nd = len(data)
for idata, d in enumerate(data):
col = geo.column_containing_point(d[0:2], geo_columns,
Expand Down Expand Up @@ -4050,9 +4051,8 @@ def parse_layers(filename):
def parse_segments(filename, bottom_layer):
"""Parse AMESH segment file and return list of 2-D segments, together
with the minimum segment length."""
from sys import float_info
segment_data = []
min_segment_length = float_info.max
min_segment_length = sys.float_info.max
for line in open(filename):
x1, y1, x2, y2 = float(line[0: 15]), float(line[15: 30]), \
float(line[30: 45]), float(line[45: 60])
Expand Down
11 changes: 7 additions & 4 deletions t2data.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
You should have received a copy of the GNU Lesser General Public License along with PyTOUGH. If not, see <http://www.gnu.org/licenses/>."""

from __future__ import print_function

import sys
from fixed_format_file import *
from t2grids import *
from t2incons import *
Expand Down Expand Up @@ -1521,7 +1521,8 @@ def read_extra_precision(self):
from os.path import exists
filename = self.extra_precision_filename
if exists(filename):
xpfile = t2_extra_precision_data_parser(self.extra_precision_filename, 'rU',
mode = 'r' if sys.version_info > (3,) else 'rU'
xpfile = t2_extra_precision_data_parser(self.extra_precision_filename, mode,
read_function = self.read_function)
read_fn = dict(zip(t2_extra_precision_sections,
[self.read_rocktypes, self.read_blocks, self.read_connections,
Expand Down Expand Up @@ -1566,7 +1567,8 @@ def read(self, filename = '', meshfilename = ''):
an associated '.pdat' file, if it exists.
"""
if filename: self.filename = filename
infile = t2data_parser(self.filename, 'rU', read_function = self.read_function)
mode = 'r' if sys.version_info > (3,) else 'rU'
infile = t2data_parser(self.filename, mode, read_function = self.read_function)
self.read_title(infile)
self._sections = []
more = True
Expand All @@ -1591,7 +1593,8 @@ def read(self, filename = '', meshfilename = ''):
if meshfilename and (self.grid.num_blocks == 0):
self.meshfilename = meshfilename
if isinstance(meshfilename, str):
meshfile = t2data_parser(self.meshfilename, 'rU', read_function = self.read_function)
mode = 'r' if sys.version_info > (3,) else 'rU'
meshfile = t2data_parser(self.meshfilename, mode, read_function = self.read_function)
self.read_meshfile(meshfile)
meshfile.close()
elif isinstance(meshfilename, (list, tuple)):
Expand Down
3 changes: 2 additions & 1 deletion t2incons.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ def delete_incon(self, block):
def read(self, filename, num_variables = None):
"""Reads initial conditions from file."""
self.empty()
infile = t2incon_parser(filename, 'rU', read_function = self.read_function)
mode = 'r' if sys.version_info > (3,) else 'rU'
infile = t2incon_parser(filename, mode, read_function = self.read_function)
infile.readline() # skip header
finished = False
timing = False
Expand Down
7 changes: 4 additions & 3 deletions t2listing.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from mulgrids import fix_blockname, valid_blockname
from fixed_format_file import fortran_float, fortran_int
import io
from sys import version_info
import sys

class listingtable(object):

Expand Down Expand Up @@ -191,7 +191,7 @@ def __repr__(self): return self.title
def close(self):
self._file.close()

if version_info[0] < 3:
if sys.version_info < (3,):
def readline(self):
"""Reads next line and returns it as a string. In Python 2.x,
readline() already returns a string and doesn't need decoding.
Expand Down Expand Up @@ -1388,7 +1388,8 @@ def read(self, filename):
files = glob(filename)
configured = False
for i, fname in enumerate(files):
self._file = open(fname,'rU')
mode = 'r' if sys.version_info > (3,) else 'rU'
self._file = open(fname, mode)
header = self._file.readline()
if header:
if not configured:
Expand Down

0 comments on commit 8504c3f

Please sign in to comment.