docs: def topological_sort(dag):
      """
      topological sort
  
      :param dag: directed acyclic graph
      :type dag: dict
  
      .. seealso:: `Topographical Sorting
          <http://en.wikipedia.org/wiki/Topological_sorting>`_,
          `Directed Acyclic Graph (DAG)
          <https://en.wikipedia.org/wiki/Directed_acyclic_graph>`_
      """
      # find all edges of dag
      topsort = [node for node, edge in dag.iteritems() if not edge]
      # loop through nodes until topologically sorted
      while len(topsort) < len(dag):
          num_nodes = len(topsort)  # number of nodes
          # unsorted nodes
          for node in dag.viewkeys() - set(topsort):
              # nodes with no incoming edges
              if set(dag[node]) <= set(topsort):
                  topsort.append(node)
                  break
          # circular dependencies
          if len(topsort) == num_nodes:
              raise CircularDependencyError(dag.viewkeys() - set(topsort))
      return topsort