Skip to content

Commit

Permalink
python 3 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
avilaton committed May 23, 2018
1 parent b3c6899 commit a205524
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion transitfeed/gtfsfactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def GetLoadingOrder(self):
"""Returns a list of filenames sorted by loading order.
Only includes files that Loader's standardized loading knows how to load"""
result = {}
for filename, mapping in self._file_mapping.iteritems():
for filename, mapping in self._file_mapping.items():
loading_order = mapping['loading_order']
if loading_order is not None:
result[loading_order] = filename
Expand Down
4 changes: 2 additions & 2 deletions transitfeed/gtfsfactoryuser.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ def GetGtfsFactory(self):
# This is why the import is here and not at the top level.
# When this runs, gtfsfactory should have already been loaded
# by other modules, avoiding the circular imports.
import gtfsfactory
self._gtfs_factory = gtfsfactory.GetGtfsFactory()
import transitfeed.gtfsfactory
self._gtfs_factory = transitfeed.gtfsfactory.GetGtfsFactory()
return self._gtfs_factory

def SetGtfsFactory(self, factory):
Expand Down
6 changes: 4 additions & 2 deletions transitfeed/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
# limitations under the License.

import codecs
from six import StringIO
import csv
import os
import re
import zipfile

from six import StringIO
from six import string_types

import transitfeed.gtfsfactory
from transitfeed import problems
import transitfeed.util
Expand Down Expand Up @@ -73,7 +75,7 @@ def _DetermineFormat(self):
assert not self._path
return True

if not isinstance(self._path, basestring) and hasattr(self._path, 'read'):
if not isinstance(self._path, string_types) and hasattr(self._path, 'read'):
# A file-like object, used for testing with a StringIO file
self._zip = zipfile.ZipFile(self._path, mode='r')
return True
Expand Down
4 changes: 2 additions & 2 deletions transitfeed/schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def GetDefaultAgency(self):
if len(self._agencies) == 0:
self.NewDefaultAgency()
elif len(self._agencies) == 1:
self._default_agency = self._agencies.values()[0]
self._default_agency = list(self._agencies.values())[0]
return self._default_agency

def NewDefaultAgency(self, **kwargs):
Expand Down Expand Up @@ -225,7 +225,7 @@ def GetDefaultServicePeriod(self):
if len(self.service_periods) == 0:
self.NewDefaultServicePeriod()
elif len(self.service_periods) == 1:
self._default_service_period = self.service_periods.values()[0]
self._default_service_period = list(self.service_periods.values())[0]
return self._default_service_period

def NewDefaultServicePeriod(self):
Expand Down
11 changes: 6 additions & 5 deletions transitfeed/trip.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@

import warnings

from six import string_types, text_type

from transitfeed.gtfsobjectbase import GtfsObjectBase
from transitfeed.problems import default_problem_reporter
import transitfeed.problems
# import problems as problems_module
import transitfeed.util

class Trip(GtfsObjectBase):
Expand Down Expand Up @@ -424,7 +425,7 @@ def AddFrequency(self, start_time, end_time, headway_secs, exact_times=0,
if start_time == None or start_time == '': # 0 is OK
problem_reporter.MissingValue('start_time')
return
if isinstance(start_time, basestring):
if isinstance(start_time, string_types):
try:
start_time = transitfeed.util.TimeToSecondsSinceMidnight(start_time)
except transitfeed.problems.Error:
Expand All @@ -436,7 +437,7 @@ def AddFrequency(self, start_time, end_time, headway_secs, exact_times=0,
if end_time == None or end_time == '':
problem_reporter.MissingValue('end_time')
return
if isinstance(end_time, basestring):
if isinstance(end_time, string_types):
try:
end_time = transitfeed.util.TimeToSecondsSinceMidnight(end_time)
except transitfeed.problems.Error:
Expand Down Expand Up @@ -478,8 +479,8 @@ def _HeadwayOutputTuple(self, headway):
return (self.trip_id,
transitfeed.util.FormatSecondsSinceMidnight(headway[0]),
transitfeed.util.FormatSecondsSinceMidnight(headway[1]),
unicode(headway[2]),
unicode(headway[3]))
text_type(headway[2]),
text_type(headway[3]))

def GetFrequencyOutputTuples(self):
tuples = []
Expand Down

0 comments on commit a205524

Please sign in to comment.