def _flattenTree(request, root, write):
 stack = [_flattenElement(request, root, write, [], None, escapeForContent)]
 while stack:
  try:
   frame = stack[(-1)].gi_frame
   element = next(stack[(-1)])
  except StopIteration:
   stack.pop()
  except Exception as e:
   stack.pop()
   roots = []
   for generator in stack:
    roots.append(generator.gi_frame.f_locals['root'])
   roots.append(frame.f_locals['root'])
   raise FlattenerError(e, roots, extract_tb(exc_info()[2]))
  else:
   if isinstance(element, Deferred):
    def cbx(originalAndToFlatten):
     (original, toFlatten) = originalAndToFlatten
     stack.append(toFlatten)
     return original
    (yield element.addCallback(cbx))
   else:
    stack.append(element)

def _flattenTree ( request , root , write ) : stack = [ _flattenElement ( request , root , write , [ ] , None , escapeForContent ) ] while stack : try : frame = stack [ ( - 1 ) ] . gi_frame element = next ( stack [ ( - 1 ) ] ) except StopIteration : stack . pop ( ) except Exception as e : stack . pop ( ) roots = [ ] for generator in stack : roots . append ( generator . gi_frame . f_locals [ 'root' ] ) roots . append ( frame . f_locals [ 'root' ] ) raise FlattenerError ( e , roots , extract_tb ( exc_info ( ) [ 2 ] ) ) else : if isinstance ( element , Deferred ) : def cbx ( originalAndToFlatten ) : ( original , toFlatten ) = originalAndToFlatten stack . append ( toFlatten ) return original ( yield element . addCallback ( cbx ) ) else : stack . append ( element )
make c{root} into an iterable of l{bytes} and l{deferred} by doing a depth first traversal of the tree .