Skip to content
Permalink
Browse files

Fix excpetion style to be Python3 compatible

by running

    2to3 -nw -f except .

Part of google#412
  • Loading branch information...
jarondl committed Nov 15, 2018
1 parent 54a4081 commit ffc87281982cf8125786a3fa34c6b9e81122d97e
@@ -28,7 +28,7 @@

try:
import xml.etree.ElementTree as ET # python 2.5
except ImportError, e:
except ImportError as e:
import elementtree.ElementTree as ET # older pythons


@@ -333,7 +333,7 @@ def FormatException(self, e, output):
transitfeed.EncodeUnicode(table_header))
output.append('<tr>%s</tr></table>\n' %
transitfeed.EncodeUnicode(table_data))
except AttributeError, e:
except AttributeError as e:
pass # Hope this was getting an attribute from e ;-)
output.append('<br></li>\n')

@@ -513,7 +513,7 @@ def RunValidationOutputToFilename(feed, options, output_filename):
output_file = open(output_filename, 'w')
exit_code = RunValidationOutputToFile(feed, options, output_file)
output_file.close()
except IOError, e:
except IOError as e:
print 'Error while writing %s: %s' % (output_filename, e)
output_filename = None
exit_code = 2
@@ -71,7 +71,7 @@

try:
import xml.etree.ElementTree as ET # python 2.5
except ImportError, e:
except ImportError as e:
import elementtree.ElementTree as ET # older pythons
import extensions.googletransit as googletransit
import optparse
@@ -790,7 +790,7 @@ def main():
try:
loader = transitfeed.Loader(input_path)
feed = loader.Load()
except transitfeed.ExceptionWithContext, e:
except transitfeed.ExceptionWithContext as e:
print >>sys.stderr, (
"\n\nGTFS feed must load without any errors.\n"
"While loading %s the following error was found:\n%s\n%s\n" %
@@ -358,7 +358,7 @@ def LoadWithoutErrors(path, memory_db):
memory_db=memory_db,
problems=loading_problem_handler,
extra_validation=True).Load()
except transitfeed.ExceptionWithContext, e:
except transitfeed.ExceptionWithContext as e:
print >>sys.stderr, (
"\n\nFeeds to merge must load without any errors.\n"
"While loading %s the following error was found:\n%s\n%s\n" %
@@ -509,7 +509,7 @@ def _SchemedMerge(self, scheme, a, b):
b_attr = getattr(b, attr, None)
try:
merged_attr = merger(a_attr, b_attr)
except MergeError, merge_error:
except MergeError as merge_error:
raise MergeError("Attribute '%s' could not be merged: %s." % (
attr, merge_error))
setattr(migrated, attr, merged_attr)
@@ -549,7 +549,7 @@ def _MergeSameId(self):
try:
self._Add(a, b, self._MergeEntities(a, b))
self._num_merged += 1
except MergeError, merge_error:
except MergeError as merge_error:
a_not_merged.append(a)
b_not_merged.append(b)
self._ReportSameIdButNotMerged(self._GetId(a), merge_error)
@@ -82,7 +82,7 @@ def show_tran(dist, tz_name, tran, inf):
from_noon.append((distance_from_noon, tz_name, tran, inf))
distance_from_midnight = hour_dist(average, 0)
from_midnight.append((distance_from_midnight, tz_name, tran, inf))
except Exception, e:
except Exception as e:
print "Trouble with %s %s %s: %s" % (tz_name, tran, inf, e)


@@ -65,7 +65,7 @@ def default(self, line):
print s[0:2000]
else:
print s
except sqlite.DatabaseError, e:
except sqlite.DatabaseError as e:
print "error %s" % e


@@ -119,7 +119,7 @@ def do_GET(self):
try:
f, mime_type = self.OpenFile(m.group(1))
return self.handle_static_file_GET(f, mime_type)
except IOError, e:
except IOError as e:
print "Error: unable to open %s" % m.group(1)
# Ignore and treat as 404

@@ -31,7 +31,7 @@
try:
import py2exe
has_py2exe = True
except ImportError, e:
except ImportError as e:
# Won't be able to generate win32 exe
has_py2exe = False

@@ -28,7 +28,7 @@

try:
import xml.etree.ElementTree as ET # python 2.5
except ImportError, e:
except ImportError as e:
import elementtree.ElementTree as ET # older pythons


@@ -290,7 +290,7 @@ def BadMerger(a, b):

try:
self.ds._SchemedMerge(scheme, a, b)
except merge.MergeError, merge_error:
except merge.MergeError as merge_error:
error_text = str(merge_error)
self.assert_(reason in error_text)
self.assert_(attribute_name in error_text)
@@ -779,7 +779,7 @@ def testMergeDifferentTypes(self):
try:
self.fm.MergeSchedules()
self.fail("Expecting MergeError")
except merge.SameIdButNotMerged, merge_error:
except merge.SameIdButNotMerged as merge_error:
self.assertTrue(("%s" % merge_error).find("location_type") != -1)

def AssertS1ParentIsS2(self):
@@ -263,7 +263,7 @@ def runTest(self):
try:
loader.Load()
self.fail('FeedNotFound exception expected')
except transitfeed.FeedNotFound, e:
except transitfeed.FeedNotFound as e:
self.assertEqual(feed_name, e.feed_name)

class LoadUnknownFormatTestCase(util.TestCase):
@@ -276,7 +276,7 @@ def runTest(self):
try:
loader.Load()
self.fail('UnknownFormat exception expected')
except transitfeed.UnknownFormat, e:
except transitfeed.UnknownFormat as e:
self.assertEqual(feed_name, e.feed_name)

class LoadUnrecognizedColumnsTestCase(util.TestCase):
@@ -382,7 +382,7 @@ def runTest(self):
try:
loader.Load()
self.fail('EmptyFile exception expected')
except transitfeed.EmptyFile, e:
except transitfeed.EmptyFile as e:
self.assertEqual('agency.txt', e.file_name)


@@ -395,7 +395,7 @@ def runTest(self):
try:
loader.Load()
self.fail('MissingColumn exception expected')
except transitfeed.MissingColumn, e:
except transitfeed.MissingColumn as e:
self.assertEqual('agency.txt', e.file_name)
self.assertEqual('agency_name', e.column_name)

@@ -422,7 +422,7 @@ def runTest(self):
loader.Load()
# TODO: make sure processing proceeds beyond the problem
self.fail('FileFormat exception expected')
except transitfeed.FileFormat, e:
except transitfeed.FileFormat as e:
# make sure these don't raise an exception
self.assertTrue(re.search(r'encoded in utf-16', e.FormatProblem()))
e.FormatContext()
@@ -452,7 +452,7 @@ def runTest(self):
try:
loader.Load()
self.fail('FileFormat exception expected')
except transitfeed.FileFormat, e:
except transitfeed.FileFormat as e:
self.assertTrue(re.search(r'contains a null', e.FormatProblem()))
# make sure these don't raise an exception
e.FormatContext()
@@ -739,7 +739,7 @@ def runTest(self):
try:
schedule.AddTripObject(trip2)
self.fail("Expected Duplicate ID validation failure")
except transitfeed.DuplicateID, e:
except transitfeed.DuplicateID as e:
self.assertEqual("trip_id", e.column_name)
self.assertEqual("SAMPLE_TRIP", e.value)

@@ -756,7 +756,7 @@ def runTest(self):
try:
schedule.AddRouteObject(route)
self.fail("Expected validation error")
except transitfeed.InvalidValue, e:
except transitfeed.InvalidValue as e:
self.assertEqual('agency_id', e.column_name)
self.assertEqual(None, e.value)

@@ -775,7 +775,7 @@ def runTest(self):
try:
schedule.AddRouteObject(route)
self.fail("Expected validation error")
except transitfeed.InvalidValue, e:
except transitfeed.InvalidValue as e:
self.assertEqual('agency_id', e.column_name)
self.assertEqual(None, e.value)

@@ -453,7 +453,7 @@ def testWithoutSchedule(self):
try:
t = stop.new_column
self.fail('Expecting AttributeError')
except AttributeError, e:
except AttributeError as e:
pass # Expected
stop.stop_id = 'a'
stop.stop_name = 'my stop'
@@ -643,7 +643,7 @@ def ExpectInvalidValue(self, start_time, end_time, headway,
trip = transitfeed.Trip()
trip.AddFrequency(start_time, end_time, headway)
self.fail("Expected InvalidValue error on %s" % column_name)
except transitfeed.InvalidValue, e:
except transitfeed.InvalidValue as e:
self.assertEqual(column_name, e.column_name)
self.assertEqual(value, e.value)
self.assertEqual(0, len(trip.GetFrequencyTuples()))
@@ -653,7 +653,7 @@ def ExpectMissingValue(self, start_time, end_time, headway, column_name):
trip = transitfeed.Trip()
trip.AddFrequency(start_time, end_time, headway)
self.fail("Expected MissingValue error on %s" % column_name)
except transitfeed.MissingValue, e:
except transitfeed.MissingValue as e:
self.assertEqual(column_name, e.column_name)
self.assertEqual(0, len(trip.GetFrequencyTuples()))

@@ -56,7 +56,7 @@ def check_call(cmd, expected_retcode=0, stdin_str="", **kwargs):
**kwargs)
(out, err) = p.communicate(stdin_str)
retcode = p.returncode
except Exception, e:
except Exception as e:
raise Exception("When running %s: %s" % (cmd, e))
if retcode < 0:
raise Exception(
@@ -604,7 +604,7 @@ def ValidateStopTimesSequenceHasIncreasingTimeAndDistance(self,
try:
route_type = self._schedule.GetRoute(self.route_id).route_type
max_speed = route_class._ROUTE_TYPES[route_type]['max_speed']
except KeyError, e:
except KeyError as e:
# If route_type cannot be found, assume it is 0 (Tram) for checking
# speeds between stops.
max_speed = route_class._ROUTE_TYPES[0]['max_speed']
@@ -91,7 +91,7 @@ def RunWithCrashHandler(f):
for local_name, local_val in frame_obj.f_locals.items():
try:
truncated_val = str(local_val)[0:500]
except Exception, e:
except Exception as e:
dump.append(' Exception in str(%s): %s' % (local_name, e))
else:
if len(truncated_val) >= 500:
@@ -556,7 +556,7 @@ def writerow(self, row):
encoded_row.append(s)
try:
self.writer.writerow(encoded_row)
except Exception, e:
except Exception as e:
print 'error writing %s as %s' % (row, encoded_row)
raise e

0 comments on commit ffc8728

Please sign in to comment.
You can’t perform that action at this time.