import re
import time
import xml.etree.ElementTree as et


def wait(delay):
    def decorator(method):
        def clocked(self, *args, **kwargs):
            if self.clock:
                elapsed = time.time() - self.clock
                if elapsed < delay:
                    time.sleep(delay - elapsed)
            result = method(self, *args, **kwargs)
            self.clock = time.time()
            return result
        return clocked
    return decorator


def parse_xml(content, tag, namespace=None, keep_namespace=False):
    """
    >>> xml = '<oai xmlns="http://foo" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://foo bar.xsd">' \
              '<record>' \
                '<header>' \
                  '<date>2009-11-23</date>' \
                '</header>' \
                '<metadata>' \
                  '<id>007.0001</id>' \
                  '<submitter>toto</submitter>' \
                '</metadata>' \
              '</record>' \
            '</oai>'
    >>> parse_xml(xml, '{http://foo}record', keep_namespace=False)
    [{'date': '2009-11-23', 'submitter': 'toto', 'id': '007.0001'}]
    >>> parse_xml(xml, '{http://foo}record', keep_namespace=True)
    [{'{http://foo}date': '2009-11-23', '{http://foo}submitter': 'toto', '{http://foo}id': '007.0001'}]
    """
    ns = re.compile('^{.*?}')
    clean = lambda string: string if keep_namespace else ns.sub('', string)
    node_to_dict = lambda node: {intern(clean(c.tag)): c.text.replace('\n', ' ')
                                 for c in node.iter() if c.text and c.text.strip()}

    tag = tag if not namespace else '{' + namespace + '}' + tag
    nodes = et.fromstring(content).iter(tag)
    return map(node_to_dict, nodes)


def identity(arg):
    return arg

@@ -1767,15 +1767,371 @@
     
-return arg
+%22%22%22%0A    %3E%3E%3E a = 257%0A    %3E%3E%3E identity(a) is a%0A    True%0A    %22%22%22%0A    return arg%0A%0A%0Adef true(*args):%0A    %22%22%22%0A    %3E%3E%3E true(1)%0A    True%0A    %3E%3E%3E true(None)%0A    True%0A    %22%22%22%0A    return True%0A%0A%0Adef false(*args):%0A    %22%22%22%0A    %3E%3E%3E false(1)%0A    False%0A    %3E%3E%3E false(None)%0A    False%0A    %22%22%22%0A    return False%0A%0A%0Adef compose(first, second):%0A    return lambda *args: second(first(*args))
 %0A

Add some functional utilities