def init_url_map(self, url_module):
    self.has_error_on_init_url_map = False
    mod = import_string(url_module)
    if hasattr(mod, 'view_groups'):
      base_rules = []
      self.views = {}
      for view_group in getattr(mod, 'view_groups'):
        try:
          base_rules = base_rules + view_group.get_rules()
          self.views.update(view_group.get_views())
        except Exception, e:
          logging.error("Failed to mount ViewGroup: %s", e)
          raise
      import copy
      self.url_map = Map(copy.deepcopy(base_rules))
    else:
      make_url = getattr(mod, 'make_url')
      all_views = getattr(mod, 'all_views')
      self.views = all_views
      self.url_map = make_url()
    for app in self.get_installed_apps():
      mountpoint = self.get_mount_point(app)
      if mountpoint is None:
        logging.debug("Mountpoint for app '%s' is set to None explicitly,"
                      " skipped." % app)
        continue
      try:
        url_mod = import_string("%s.%s" % (app, url_module))
      except (ImportError, __HOLE__):
        try:
          url_mod = import_string("%s.urls" % app)
        except (ImportError, AttributeError):
          logging.error("Failed to import app '%s.urls'." % app)
          logging.debug("Reason:\n%s" % self._get_traceback(sys.exc_info()))
          raise
      rules = []
      if hasattr(url_mod, 'view_groups'):
        for view_group in getattr(url_mod, 'view_groups'):
          try:
            endpoint_prefix = app.split(".")[-1]
            rules = rules + view_group.get_rules(endpoint_prefix)
            self.views.update(view_group.get_views(endpoint_prefix))
          except Exception, e:
            logging.error("Failed to mount ViewGroup: %s", e)
            raise
      else:
        make_rules = getattr(url_mod, 'make_rules', None)
        if make_rules:
          rules = make_rules()
        all_views = getattr(url_mod, 'all_views', None)
        if all_views:
          self.views.update(all_views)
      self.url_map.add(Submount(mountpoint, rules))
    # TODO move the block bellow to somewhere else
    if 'kay.auth.middleware.AuthenticationMiddleware' in \
          self.app_settings.MIDDLEWARE_CLASSES:
      try:
        klass = import_string(self.app_settings.AUTH_USER_BACKEND)
      except (AttributeError, ImportError), e:
        raise exceptions.ImproperlyConfigured, \
            'Failed to import %s: "%s".' %\
            (self.app_settings.AUTH_USER_BACKEND, e)
      self.auth_backend = klass()
dataset/ETHPy150Open IanLewis/kay/kay/app.py/KayApp.init_url_map