code: def pisaPreLoop(node, context, collect=False):
      
  
      data = u""
      if node.nodeType == Node.TEXT_NODE and collect:
          data = node.data
  
      elif node.nodeType == Node.ELEMENT_NODE:
          name = node.tagName.lower()
  
          if name in ("style", "link"):
              attr = pisaGetAttributes(context, name, node.attributes)
              media = [x.strip()
                       for x in attr.media.lower().split(",") if x.strip()]
  
              if attr.get("type", "").lower() in ("", "text/css") and \
                      (not media or "all" in media or "print" in media or "pdf" in media):
  
                  if name == "style":
                      for node in node.childNodes:
                          data += pisaPreLoop(node, context, collect=True)
                      context.addCSS(data)
                      return u""
  
                  if name == "link" and attr.href and attr.rel.lower() == "stylesheet":
                      # print "CSS LINK", attr
                      context.addCSS('\n@import "%s" %s;' %
                                     (attr.href, ",".join(media)))
  
      for node in node.childNodes:
          result = pisaPreLoop(node, context, collect=collect)
          if collect:
              data += result
  
      return data
docs: Collect all CSS definitions