当前位置: 首页>>代码示例>>Python>>正文


Python util.is_iterable函数代码示例

本文整理汇总了Python中b2.util.is_iterable函数的典型用法代码示例。如果您正苦于以下问题:Python is_iterable函数的具体用法?Python is_iterable怎么用?Python is_iterable使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了is_iterable函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: register_action

    def register_action (self, action_name, command, bound_list = [], flags = [],
                         function = None):
        """Creates a new build engine action.

        Creates on bjam side an action named 'action_name', with
        'command' as the command to be executed, 'bound_variables'
        naming the list of variables bound when the command is executed
        and specified flag.
        If 'function' is not None, it should be a callable taking three
        parameters:
            - targets
            - sources
            - instance of the property_set class
        This function will be called by set_update_action, and can
        set additional target variables.
        """
        assert isinstance(action_name, basestring)
        assert isinstance(command, basestring)
        assert is_iterable(bound_list)
        assert is_iterable(flags)
        assert function is None or callable(function)

        bjam_flags = reduce(operator.or_,
                            (action_modifiers[flag] for flag in flags), 0)

        # We allow command to be empty so that we can define 'action' as pure
        # python function that would do some conditional logic and then relay
        # to other actions.
        assert command or function
        if command:
            bjam_interface.define_action(action_name, command, bound_list, bjam_flags)

        self.actions[action_name] = BjamAction(action_name, function)
开发者ID:zjutjsj1004,项目名称:third,代码行数:33,代码来源:engine.py

示例2: equal

def equal (a, b):
    """ Returns True iff 'a' contains the same elements as 'b', irrespective of their order.
        # TODO: Python 2.4 has a proper set class.
    """
    assert is_iterable(a)
    assert is_iterable(b)
    return contains (a, b) and contains (b, a)
开发者ID:zjutjsj1004,项目名称:third,代码行数:7,代码来源:set.py

示例3: option

    def option(self, name, value):
        assert is_iterable(name) and isinstance(name[0], basestring)
        assert is_iterable(value) and isinstance(value[0], basestring)
        name = name[0]
        if not name in ["site-config", "user-config", "project-config"]:
            get_manager().errors()("The 'option' rule may be used only in site-config or user-config")

        option.set(name, value[0])
开发者ID:Cabriter,项目名称:abelkhan,代码行数:8,代码来源:project.py

示例4: do_set_update_action

 def do_set_update_action (self, action_name, targets, sources, property_set_):
     assert isinstance(action_name, basestring)
     assert is_iterable(targets)
     assert is_iterable(sources)
     assert isinstance(property_set_, property_set.PropertySet)
     action = self.actions.get(action_name)
     if not action:
         raise Exception("No action %s was registered" % action_name)
     action(targets, sources, property_set_)
开发者ID:zjutjsj1004,项目名称:third,代码行数:9,代码来源:engine.py

示例5: intersection

def intersection (set1, set2):
    """ Removes from set1 any items which don't appear in set2 and returns the result.
    """
    assert is_iterable(set1)
    assert is_iterable(set2)
    result = []
    for v in set1:
        if v in set2:
            result.append (v)
    return result
开发者ID:zjutjsj1004,项目名称:third,代码行数:10,代码来源:set.py

示例6: difference

def difference (b, a):
    """ Returns the elements of B that are not in A.
    """
    assert is_iterable(b)
    assert is_iterable(a)
    result = []
    for element in b:
        if not element in a:
            result.append (element)

    return result
开发者ID:zjutjsj1004,项目名称:third,代码行数:11,代码来源:set.py

示例7: __call__

 def __call__(self, targets, sources, property_set_):
     assert is_iterable(targets)
     assert is_iterable(sources)
     assert isinstance(property_set_, property_set.PropertySet)
     # Bjam actions defined from Python have only the command
     # to execute, and no associated jam procedural code. So
     # passing 'property_set' to it is not necessary.
     bjam_interface.call("set-update-action", self.action_name,
                         targets, sources, [])
     if self.function:
         self.function(targets, sources, property_set_)
开发者ID:zjutjsj1004,项目名称:third,代码行数:11,代码来源:engine.py

示例8: project

    def project(self, *args):
        assert is_iterable(args) and all(is_iterable(arg) for arg in args)
        jamfile_module = self.registry.current().project_module()
        attributes = self.registry.attributes(jamfile_module)

        id = None
        if args and args[0]:
            id = args[0][0]
            args = args[1:]

        if id:
            attributes.set('id', [id])

        explicit_build_dir = None
        for a in args:
            if a:
                attributes.set(a[0], a[1:], exact=0)
                if a[0] == "build-dir":
                    explicit_build_dir = a[1]

        # If '--build-dir' is specified, change the build dir for the project.
        if self.registry.global_build_dir:

            location = attributes.get("location")
            # Project with empty location is 'standalone' project, like
            # user-config, or qt.  It has no build dir.
            # If we try to set build dir for user-config, we'll then
            # try to inherit it, with either weird, or wrong consequences.
            if location and location == attributes.get("project-root"):
                # Re-read the project id, since it might have been changed in
                # the project's attributes.
                id = attributes.get('id')

                # This is Jamroot.
                if id:
                    if explicit_build_dir and os.path.isabs(explicit_build_dir):
                        self.registry.manager.errors()(
"""Absolute directory specified via 'build-dir' project attribute
Don't know how to combine that with the --build-dir option.""")

                    rid = id
                    if rid[0] == '/':
                        rid = rid[1:]

                    p = os.path.join(self.registry.global_build_dir, rid)
                    if explicit_build_dir:
                        p = os.path.join(p, explicit_build_dir)
                    attributes.set("build-dir", p, exact=1)
            elif explicit_build_dir:
                self.registry.manager.errors()(
"""When --build-dir is specified, the 'build-dir'
attribute is allowed only for top-level 'project' invocations""")
开发者ID:Cabriter,项目名称:abelkhan,代码行数:52,代码来源:project.py

示例9: get_target_variable

    def get_target_variable(self, targets, variable):
        """Gets the value of `variable` on set on the first target in `targets`.

        Args:
            targets (str or list): one or more targets to get the variable from.
            variable (str): the name of the variable

        Returns:
             the value of `variable` set on `targets` (list)

        Example:

            >>> ENGINE = get_manager().engine()
            >>> ENGINE.set_target_variable(targets, 'MY-VAR', 'Hello World')
            >>> ENGINE.get_target_variable(targets, 'MY-VAR')
            ['Hello World']

        Equivalent Jam code:

            MY-VAR on $(targets) = "Hello World" ;
            echo [ on $(targets) return $(MY-VAR) ] ;
            "Hello World"
        """
        if isinstance(targets, str):
            targets = [targets]
        assert is_iterable(targets)
        assert isinstance(variable, basestring)

        return bjam_interface.call('get-target-variable', targets, variable)
开发者ID:zjutjsj1004,项目名称:third,代码行数:29,代码来源:engine.py

示例10: add_dependency

    def add_dependency (self, targets, sources):
        """Adds a dependency from 'targets' to 'sources'

        Both 'targets' and 'sources' can be either list
        of target names, or a single target name.
        """
        if isinstance (targets, str):
            targets = [targets]
        if isinstance (sources, str):
            sources = [sources]
        assert is_iterable(targets)
        assert is_iterable(sources)

        for target in targets:
            for source in sources:
                self.do_add_dependency (target, source)
开发者ID:zjutjsj1004,项目名称:third,代码行数:16,代码来源:engine.py

示例11: do_set_target_variable

 def do_set_target_variable (self, target, variable, value, append):
     assert isinstance(target, basestring)
     assert isinstance(variable, basestring)
     assert is_iterable(value)
     assert isinstance(append, int)  # matches bools
     if append:
         bjam_interface.call("set-target-variable", target, variable, value, "true")
     else:
         bjam_interface.call("set-target-variable", target, variable, value)
开发者ID:zjutjsj1004,项目名称:third,代码行数:9,代码来源:engine.py

示例12: set_target_variable

    def set_target_variable (self, targets, variable, value, append=0):
        """ Sets a target variable.

        The 'variable' will be available to bjam when it decides
        where to generate targets, and will also be available to
        updating rule for that 'taret'.
        """
        if isinstance (targets, str):
            targets = [targets]
        if isinstance(value, str):
            value = [value]

        assert is_iterable(targets)
        assert isinstance(variable, basestring)
        assert is_iterable(value)

        for target in targets:
            self.do_set_target_variable (target, variable, value, append)
开发者ID:zjutjsj1004,项目名称:third,代码行数:18,代码来源:engine.py

示例13: __init__

 def __init__(self, variable_name, values, condition, rule = None):
     assert isinstance(variable_name, basestring)
     assert is_iterable(values) and all(
         isinstance(v, (basestring, type(None))) for v in values)
     assert is_iterable_typed(condition, property_set.PropertySet)
     assert isinstance(rule, (basestring, type(None)))
     self.variable_name = variable_name
     self.values = values
     self.condition = condition
     self.rule = rule
开发者ID:LocutusOfBorg,项目名称:poedit,代码行数:10,代码来源:toolset.py

示例14: set_update_action

    def set_update_action (self, action_name, targets, sources, properties=None):
        """ Binds a target to the corresponding update action.
            If target needs to be updated, the action registered
            with action_name will be used.
            The 'action_name' must be previously registered by
            either 'register_action' or 'register_bjam_action'
            method.
        """
        if isinstance(targets, str):
            targets = [targets]
        if isinstance(sources, str):
            sources = [sources]
        if properties is None:
            properties = property_set.empty()
        assert isinstance(action_name, basestring)
        assert is_iterable(targets)
        assert is_iterable(sources)
        assert(isinstance(properties, property_set.PropertySet))

        self.do_set_update_action (action_name, targets, sources, properties)
开发者ID:zjutjsj1004,项目名称:third,代码行数:20,代码来源:engine.py

示例15: select_highest_ranked

def select_highest_ranked(elements, ranks):
    """ Returns all of 'elements' for which corresponding element in parallel
        list 'rank' is equal to the maximum value in 'rank'.
    """
    assert is_iterable(elements)
    assert is_iterable(ranks)
    if not elements:
        return []

    max_rank = max_element(ranks)

    result = []
    while elements:
        if ranks[0] == max_rank:
            result.append(elements[0])

        elements = elements[1:]
        ranks = ranks[1:]

    return result
开发者ID:zjutjsj1004,项目名称:third,代码行数:20,代码来源:sequence.py


注:本文中的b2.util.is_iterable函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。