# Path: transitfeed/util.py
# class defaultdict(dict):
#   def __init__(self, default_factory=None, *a, **kw):
#     if (default_factory is not None and
#       not hasattr(default_factory, '__call__')):
#       raise TypeError('first argument must be callable')
#     dict.__init__(self, *a, **kw)
#     self.default_factory = default_factory
#   def __getitem__(self, key):
#     try:
#       return dict.__getitem__(self, key)
#     except KeyError:
#       return self.__missing__(key)
#   def __missing__(self, key):
#     if self.default_factory is None:
#       raise KeyError(key)
#     self[key] = value = self.default_factory()
#     return value
#   def __reduce__(self):
#     if self.default_factory is None:
#       args = tuple()
#     else:
#       args = self.default_factory,
#     return type(self), args, None, None, self.items()
#   def copy(self):
#     return self.__copy__()
#   def __copy__(self):
#     return type(self)(self.default_factory, self)
#   def __deepcopy__(self, memo):
#     import copy
#     return type(self)(self.default_factory,
#                       copy.deepcopy(self.items()))
#   def __repr__(self):
#     return 'defaultdict(%s, %s)' % (self.default_factory,
#                                     dict.__repr__(self))
# 
# Path: transitfeed/compat.py



import bisect
import datetime
import itertools
import os
  import sqlite3 as sqlite
import tempfile
import time
import warnings
import weakref
import zipfile
    from pysqlite2 import dbapi2 as sqlite
    from com.ziclix.python.sql import zxJDBC as sqlite
from . import gtfsfactoryuser
from . import problems as problems_module
from .util import defaultdict
from . import util
from .compat import StringIO
    if not self._default_service_period:
      if len(self.service_periods) == 0:
        self.NewDefaultServicePeriod()
      elif len(self.service_periods) == 1:
        self._default_service_period = self.service_periods.values()[0]
    return self._default_service_period

  def NewDefaultServicePeriod(self):
    """Create a new ServicePeriod object, make it the default service period and
    return it. The default service period is used when you create a trip without
    providing an explict service period. """
    service_period = self._gtfs_factory.ServicePeriod()
    service_period.service_id = util.FindUniqueId(self.service_periods)
    # blank service won't validate in AddServicePeriodObject
    self.SetDefaultServicePeriod(service_period, validate=False)
    return service_period

  def SetDefaultServicePeriod(self, service_period, validate=True):
    assert isinstance(service_period, self._gtfs_factory.ServicePeriod)
    self._default_service_period = service_period
    if service_period.service_id not in self.service_periods:
      self.AddServicePeriodObject(service_period, validate=validate)

  def AddServicePeriodObject(self, service_period, problem_reporter=None,
                             validate=True):
    if not problem_reporter:
      problem_reporter = self.problem_reporter

    if service_period.service_id in self.service_periods:
      problem_reporter.DuplicateID('service_id', service_period.service_id)

# Path: transitfeed/util.py
# class defaultdict(dict):
#   def __init__(self, default_factory=None, *a, **kw):
#     if (default_factory is not None and
#       not hasattr(default_factory, '__call__')):
#       raise TypeError('first argument must be callable')
#     dict.__init__(self, *a, **kw)
#     self.default_factory = default_factory
#   def __getitem__(self, key):
#     try:
#       return dict.__getitem__(self, key)
#     except KeyError:
#       return self.__missing__(key)
#   def __missing__(self, key):
#     if self.default_factory is None:
#       raise KeyError(key)
#     self[key] = value = self.default_factory()
#     return value
#   def __reduce__(self):
#     if self.default_factory is None:
#       args = tuple()
#     else:
#       args = self.default_factory,
#     return type(self), args, None, None, self.items()
#   def copy(self):
#     return self.__copy__()
#   def __copy__(self):
#     return type(self)(self.default_factory, self)
#   def __deepcopy__(self, memo):
#     import copy
#     return type(self)(self.default_factory,
#                       copy.deepcopy(self.items()))
#   def __repr__(self):
#     return 'defaultdict(%s, %s)' % (self.default_factory,
#                                     dict.__repr__(self))
# 
# Path: transitfeed/compat.py



# Path: transitfeed/schedule.py
import bisect
import datetime
import itertools
import os
  import sqlite3 as sqlite
import tempfile
import time
import warnings
import weakref
import zipfile
    from pysqlite2 import dbapi2 as sqlite
    from com.ziclix.python.sql import zxJDBC as sqlite
from . import gtfsfactoryuser
from . import problems as problems_module
from .util import defaultdict
from . import util
from .compat import StringIO

    if not self._default_service_period:
      if len(self.service_periods) == 0:
        self.NewDefaultServicePeriod()
      elif len(self.service_periods) == 1:
        self._default_service_period = self.service_periods.values()[0]
    return self._default_service_period

  def NewDefaultServicePeriod(self):
    """Create a new ServicePeriod object, make it the default service period and
    return it. The default service period is used when you create a trip without
    providing an explict service period. """
    service_period = self._gtfs_factory.ServicePeriod()
    service_period.service_id = util.FindUniqueId(self.service_periods)
    # blank service won't validate in AddServicePeriodObject
    self.SetDefaultServicePeriod(service_period, validate=False)
    return service_period

  def SetDefaultServicePeriod(self, service_period, validate=True):
    assert isinstance(service_period, self._gtfs_factory.ServicePeriod)
    self._default_service_period = service_period
    if service_period.service_id not in self.service_periods:
      self.AddServicePeriodObject(service_period, validate=validate)

  def AddServicePeriodObject(self, service_period, problem_reporter=None,
                             validate=True):
    if not problem_reporter:
      problem_reporter = self.problem_reporter

    if service_period.service_id in self.service_periods:
      problem_reporter.DuplicateID('service_id', service_period.service_id)

      return