Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(6)  |  Call(5)  |  Derive(0)  |  Import(1)
Walks recursively through a sequence and calls for each keys
and values matching `types` (defautls to `(str, unicode)`) the
passed `condition`.
If the return value of the `condition` is positive it calls `function`
and replaces the return value of the call in the structure.

Example:

    >>> data = [{'foo': ['upper::bar', 'upper::baz']}]
    >>> result = map_recursive((more...)

        def map_recursive(condition, function, sequence, types=(str, unicode)):
    """Walks recursively through a sequence and calls for each keys
    and values matching `types` (defautls to `(str, unicode)`) the
    passed `condition`.
    If the return value of the `condition` is positive it calls `function`
    and replaces the return value of the call in the structure.

    Example:

        >>> data = [{'foo': ['upper::bar', 'upper::baz']}]
        >>> result = map_recursive(
        ...     lambda item: item.startswith('upper::'),
        ...     lambda item: item.lstrip('upper::').upper(),
        ...     data)
        >>> data == result
        True
        >>> result
        [{'foo': ['BAR', 'BAZ']}]
    """

    if isinstance(sequence, types) and condition(sequence):
        return function(sequence)

    elif isinstance(sequence, list):
        for i, item in enumerate(sequence[:]):
            sequence[i:i + 1] = [map_recursive(
                    condition, function, item, types=types)]

    elif isinstance(sequence, tuple):
        return tuple(map_recursive(condition, function,
                                         list(sequence), types=types))

    elif isinstance(sequence, dict):
        for key, value in sequence.items():
            value = map_recursive(
                condition, function, value, types=types)

            new_key = map_recursive(
                condition, function, key, types=types)

            if new_key != key:
                del sequence[key]

            sequence[new_key] = value

    return sequence
        


src/f/t/ftw.inflator-1.3.2/ftw/inflator/creation/sections/resolveuuid.py   ftw.inflator(Download)
from collective.transmogrifier.interfaces import ISection
from collective.transmogrifier.interfaces import ISectionBlueprint
from collective.transmogrifier.utils import defaultMatcher
from ftw.inflator.creation.sections.helpers import map_recursive
from plone.uuid.interfaces import IUUID
    def __iter__(self):
        for item in self.previous:
            yield map_recursive(
                lambda value: value.startswith(PREFIX),
                lambda value: self._resolve(item, value),

src/f/t/ftw.inflator-1.3.2/ftw/inflator/tests/test_creation_helper.py   ftw.inflator(Download)
    def test_simple_list(self):
        data = ['foo', 'upper::bar', 'baz']
        result = helpers.map_recursive(
            lambda item: item.startswith('upper::'),
            lambda item: item.lstrip('upper::').upper(),
    def test_simple_tuple(self):
        data = ('foo', 'upper::bar', 'baz')
        result = helpers.map_recursive(
            lambda item: item.startswith('upper::'),
            lambda item: item.lstrip('upper::').upper(),
 
        result = helpers.map_recursive(
            lambda item: item.startswith('upper::'),
            lambda item: item.lstrip('upper::').upper(),
            data)
 
        result = helpers.map_recursive(
            lambda item: item.startswith('upper::'),
            lambda item: item.lstrip('upper::').upper(),
            data)