Martijn Pieters wrote:
On 7/16/07, Martijn Pieters <[EMAIL PROTECTED]> wrote:
If the one-group limitation were removed, the pattern would be:

pattern = re.compile(
    # Opening brackets or parens
    r'(?: (?P<parens>\(\() | \[\[ )'

    r'(?P<text> [\w\W]+?)'                  # the text between the
brackets or parens)

    # Closing brackets or parens
    r'(?(parens) \(\( | \[\[)', re.X)

which will have a 'parens' and a 'text' group, and split and findall
will have to be re-thought.

Looking at the code, I realized we could easily do this in the
WickedFilter class. The following overrides would help us deal with
the additional pattern information:

import itertools

    def findall(self, value):
        result = []
        for groups in super(WickedFilter, self).findall(value):
            result.append(groups[1])
        return result

   def chunks(self):
        chunks = super(WickedFilter, self).chunks
        # every 2nd entry is the parens group, so filter out by
        # grabbing every 1st and 3rd
        firsts = itertools.islice(chunks, 0, None, 3)
        thirds = itertools.islice(chunks, 2, None, 3)
        result = []
        # then append every 1st and 3rd to a list
        map(result.extend, itertools.izip(firsts, thirds))

any difference between this and:

for slice in itertools.izip(firsts, thirds):
    result.extend(slice)

?
        return result

I still have to deal with the fact that super(WickedFilter,
self).chunks doesn't actually work (it's a property), but I can work
that out too. Should I continue down this path?

Once this works, you can mix [[one format]] with the ((other format))
in one document.


there may be a simpler juncture for getting the desired effect.

the filter is run by a subscriber, and running it twice (once for each desired pattern) would be trivial, rather than pushing additional complexity into the filtering classes. This would happen for both the findall call that is part of the storing event and the split call that is part of rendering.

Plone would use these special subscribers and if folks just wanted either/or behavior, they could disable them and use the old subscribers.

I'll take a look at this tomorrow.

-w



--

------ d. whit morriss ------
- senior engineer, opencore -
- http://www.openplans.org  -
- m: 415-710-8975           -

"If you don't know where you are,
you don't know anything at all"

Dr. Edgar Spencer, Ph.D., 1995


_______________________________________________
Framework-Team mailing list
Framework-Team@lists.plone.org
http://lists.plone.org/mailman/listinfo/framework-team

Reply via email to