• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python util.is_iterable函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: unique

def unique(values, stable=False):
    assert is_iterable(values)
    if stable:
        s = set()
        r = []
        for v in values:
            if not v in s:
                r.append(v)
                s.add(v)
        return r
    else:
        return list(set(values))
开发者ID:zjutjsj1004,项目名称:third,代码行数:12,代码来源:sequence.py


示例17: max_element

def max_element (elements, ordered = None):
    """ Returns the maximum number in 'elements'. Uses 'ordered' for comparisons,
        or '<' is none is provided.
    """
    assert is_iterable(elements)
    assert callable(ordered) or ordered is None
    if not ordered: ordered = operator.lt

    max = elements [0]
    for e in elements [1:]:
        if ordered (max, e):
            max = e

    return max
开发者ID:Cabriter,项目名称:abelkhan,代码行数:14,代码来源:sequence.py


示例18: __add_flag

def __add_flag (rule_or_module, variable_name, condition, values):
    """ Adds a new flag setting with the specified values.
        Does no checking.
    """
    assert isinstance(rule_or_module, basestring)
    assert isinstance(variable_name, basestring)
    assert is_iterable_typed(condition, property_set.PropertySet)
    assert is_iterable(values) and all(
        isinstance(v, (basestring, type(None))) for v in values)
    f = Flag(variable_name, values, condition, rule_or_module)

    # Grab the name of the module
    m = __re_first_segment.match (rule_or_module)
    assert m
    module = m.group(1)

    __module_flags.setdefault(module, []).append(f)
    __flags.setdefault(rule_or_module, []).append(f)
开发者ID:LocutusOfBorg,项目名称:poedit,代码行数:18,代码来源:toolset.py


示例19: flags

def flags(rule_or_module, variable_name, condition, values = []):
    """ Specifies the flags (variables) that must be set on targets under certain
        conditions, described by arguments.
        rule_or_module:   If contains dot, should be a rule name.
                          The flags will be applied when that rule is
                          used to set up build actions.

                          If does not contain dot, should be a module name.
                          The flags will be applied for all rules in that
                          module.
                          If module for rule is different from the calling
                          module, an error is issued.

         variable_name:   Variable that should be set on target

         condition        A condition when this flag should be applied.
                          Should be set of property sets. If one of
                          those property sets is contained in build
                          properties, the flag will be used.
                          Implied values are not allowed:
                          "<toolset>gcc" should be used, not just
                          "gcc". Subfeatures, like in "<toolset>gcc-3.2"
                          are allowed. If left empty, the flag will
                          always used.

                          Property sets may use value-less properties
                          ('<a>'  vs. '<a>value') to match absent
                          properties. This allows to separately match

                             <architecture>/<address-model>64
                             <architecture>ia64/<address-model>

                          Where both features are optional. Without this
                          syntax we'd be forced to define "default" value.

         values:          The value to add to variable. If <feature>
                          is specified, then the value of 'feature'
                          will be added.
    """
    assert isinstance(rule_or_module, basestring)
    assert isinstance(variable_name, basestring)
    assert is_iterable_typed(condition, basestring)
    assert is_iterable(values) and all(isinstance(v, (basestring, type(None))) for v in values)
    caller = bjam.caller()
    if not '.' in rule_or_module and caller and caller[:-1].startswith("Jamfile"):
        # Unqualified rule name, used inside Jamfile. Most likely used with
        # 'make' or 'notfile' rules. This prevents setting flags on the entire
        # Jamfile module (this will be considered as rule), but who cares?
        # Probably, 'flags' rule should be split into 'flags' and
        # 'flags-on-module'.
        rule_or_module = qualify_jam_action(rule_or_module, caller)
    else:
        # FIXME: revive checking that we don't set flags for a different
        # module unintentionally
        pass

    if condition and not replace_grist (condition, ''):
        # We have condition in the form '<feature>', that is, without
        # value. That's a previous syntax:
        #
        #   flags gcc.link RPATH <dll-path> ;
        # for compatibility, convert it to
        #   flags gcc.link RPATH : <dll-path> ;
        values = [ condition ]
        condition = None

    if condition:
        transformed = []
        for c in condition:
            # FIXME: 'split' might be a too raw tool here.
            pl = [property.create_from_string(s,False,True) for s in c.split('/')]
            pl = feature.expand_subfeatures(pl);
            transformed.append(property_set.create(pl))
        condition = transformed

        property.validate_property_sets(condition)

    __add_flag (rule_or_module, variable_name, condition, values)
开发者ID:LocutusOfBorg,项目名称:poedit,代码行数:78,代码来源:toolset.py


示例20: register_components

def register_components(components):
    """Declare that the components specified by the parameter exist."""
    assert is_iterable(components)
    __components.extend(components)
开发者ID:zjutjsj1004,项目名称:third,代码行数:4,代码来源:configure.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python util.is_iterable_typed函数代码示例发布时间:2022-05-24
下一篇:
Python manager.get_manager函数代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap