'Replace each {for} or {/for} tag with a unique token the
wiki formatter will treat as inline.
Return (stripped text,
dehydrated fors for use with unstrip_fors).'

@classmethod
def strip_fors(cls, text):

    dehydrations = {}
    indexes = count()
    def dehydrate(match):
        'Close    over    `dehydrations`,    sock    the    {for}s    away    therein,    and\n                                                replace    {for}s    and    {/for}s    with    tokens.'
        def paragraph_padding(str):
            "If    str    doesn't    contain    at    least    2    newlines,    return    enough\n                                                                such    that    appending    them    will    cause    it    to."
            return ('\n' * max((2 - str.count('\n')), 0))
        def preceding_whitespace(str, pos):
            'Return    all    contiguous    whitespace    preceding    str[pos].'
            whitespace = []
            for i in xrange((pos - 1), 0, (-1)):
                if (str[i] in ' DCTB     \n\r'):
                    whitespace.append(str[i])
                else:
                    break
            whitespace.reverse()
            return ''.join(whitespace)
        (prespace, tag, attrs, postspace) = match.groups()
        if (tag != '{/for}'):
            i = indexes.next()
            dehydrations[i] = cls._wiki_to_tag(attrs)
            token = (u'\x07%i\x07' % i)
        else:
            token = u'\x07/sf\x07'
        (on_own_line, at_top, at_bottom) = cls._on_own_line(match, postspace)
        if on_own_line:
            if (not at_top):
                prespace += paragraph_padding((preceding_whitespace(match.string, match.start(1)) + prespace))
            if (not at_bottom):
                postspace += paragraph_padding(postspace)
        return ((prespace + token) + postspace)
    pos = 0
    while True:
        m = cls._FOR_OR_CLOSER.search(text, pos)
        if (m is None):
            return (text, dehydrations)
        done = (text[:m.start()] + dehydrate(m))
        pos = len(done)
        text = (done + text[m.end():])
