def split(cls,
            n,
            contiguous,
            can_query=itertools.chain(itertools.repeat(True, 50),
                                      itertools.repeat(False)).next,
            _app=None):
    if n < 1:
      raise ValueError('n must be >= 1')
    ranges = None
    if can_query():
      if not contiguous:
        ns_keys = get_namespace_keys(_app, n + 1)
        if not ns_keys:
          return []
        else:
          if len(ns_keys) <= n:
            ns_range = []
            for ns_key in ns_keys:
              ns_range.append(NamespaceRange(ns_key.name() or '',
                                             ns_key.name() or '',
                                             _app=_app))
            return sorted(ns_range,
                          key=lambda ns_range: ns_range.namespace_start)
          ranges = [NamespaceRange(ns_keys[0].name() or '', _app=_app)]
      else:
        ns_range = NamespaceRange(_app=_app).normalized_start()
        if ns_range is None:
          return [NamespaceRange(_app=_app)]
        ranges = [ns_range]
    else:
      ranges = [NamespaceRange(_app=_app)]
    singles = []
    while ranges and (len(ranges) + len(singles)) < n:
      namespace_range = ranges.pop(0)
      if namespace_range.is_single_namespace:
        singles.append(namespace_range)
      else:
        left, right = namespace_range.split_range()
        if can_query():
          right = right.normalized_start()
        if right is not None:
          ranges.append(right)
        ranges.append(left)
    ns_ranges = sorted(singles + ranges,
                       key=lambda ns_range: ns_range.namespace_start)
    if contiguous:
      if not ns_ranges:
        return [NamespaceRange(_app=_app)]
      continuous_ns_ranges = []
      for i in range(len(ns_ranges)):
        if i == 0:
          namespace_start = MIN_NAMESPACE
        else:
          namespace_start = ns_ranges[i].namespace_start
        if i == len(ns_ranges) - 1:
          namespace_end = MAX_NAMESPACE
        else:
          namespace_end = _ord_to_namespace(
              _namespace_to_ord(ns_ranges[i+1].namespace_start) - 1)
        continuous_ns_ranges.append(NamespaceRange(namespace_start,
                                                   namespace_end,
                                                   _app=_app))
      return continuous_ns_ranges
    else:
      return ns_ranges