code: def get_default(self, check=False):
          found = []
          for realm in sorted(self, key=lambda r: r.level):
              if getattr(realm, 'default', False):
                  found.append(realm)
          if not found:
              found_names = sorted([r.get_name() for r in self])
              if not found_names:
                  self.add_error("No realm is defined in this configuration! "
                                 "This should not be possible!")
                  return None
              default_realm_name = found_names[0]
              default_realm = self.find_by_name(default_realm_name)
              default_realm.default = True
              found.append(default_realm)
              if check:
                  self.add_error("No realm is defined as the default one! "
                                 "I set %s as the default realm" % default_realm_name)
          default_realm = found[0]
          if len(found) > 1:
              found_names = sorted([r.get_name() for r in found])
              default_realm_name = found_names[0]
              default_realm = self.find_by_name(default_realm_name)
              for realm in found:
                  if realm.get_name() != default_realm_name:
                      realm.default = False
              if check:
                  self.add_warning("More than one realm is defined as the default one: %s. "
                                   "I set %s as the default realm."
                                   % (','.join(found_names), default_realm_name))
          self.default = default_realm
          return default_realm