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


Python more_itertools.first方法代码示例

本文整理汇总了Python中more_itertools.first方法的典型用法代码示例。如果您正苦于以下问题:Python more_itertools.first方法的具体用法?Python more_itertools.first怎么用?Python more_itertools.first使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在more_itertools的用法示例。


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

示例1: find_default_route

# 需要导入模块: import more_itertools [as 别名]
# 或者: from more_itertools import first [as 别名]
def find_default_route(self, ezone, intent):
        intent = intent or ROUTE_DEFAULT_INTENT
        self.check_default_route_args(ezone, intent)
        data = self.data or {}
        default_route = data.get('default_route', {})

        # This value should be able to be found always. Because we demand the
        # ROUTE_DEFAULT_POLICY to cover all intent in the service_check script.
        # A ``ValueError`` will be raised if this premise is fake.
        cluster_name = first(
            route.get(intent) for route in (
                default_route.get(ezone, {}),
                default_route.get(OVERALL, {}),
                settings.ROUTE_DEFAULT_POLICY)
            if route.get(intent) is not None)
        return self._prefix_cluster_name(ezone, cluster_name) 
开发者ID:huskar-org,项目名称:huskar,代码行数:18,代码来源:default_route.py

示例2: test_many

# 需要导入模块: import more_itertools [as 别名]
# 或者: from more_itertools import first [as 别名]
def test_many(self):
        """Test that it works on many-item iterables."""
        # Also try it on a generator expression to make sure it works on
        # whatever those return, across Python versions.
        self.assertEqual(mi.first(x for x in range(4)), 0) 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:7,代码来源:test_more.py

示例3: test_one

# 需要导入模块: import more_itertools [as 别名]
# 或者: from more_itertools import first [as 别名]
def test_one(self):
        """Test that it doesn't raise StopIteration prematurely."""
        self.assertEqual(mi.first([3]), 3) 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:5,代码来源:test_more.py

示例4: test_empty_stop_iteration

# 需要导入模块: import more_itertools [as 别名]
# 或者: from more_itertools import first [as 别名]
def test_empty_stop_iteration(self):
        """It should raise StopIteration for empty iterables."""
        self.assertRaises(ValueError, lambda: mi.first([])) 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:5,代码来源:test_more.py

示例5: test_default

# 需要导入模块: import more_itertools [as 别名]
# 或者: from more_itertools import first [as 别名]
def test_default(self):
        """It should return the provided default arg for empty iterables."""
        self.assertEqual(mi.first([], 'boo'), 'boo') 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:5,代码来源:test_more.py

示例6: test_unpacking

# 需要导入模块: import more_itertools [as 别名]
# 或者: from more_itertools import first [as 别名]
def test_unpacking(self):
        original_iterable = iter('abcdefg')
        (first, second, third), new_iterable = mi.spy(original_iterable, 3)
        self.assertEqual(first, 'a')
        self.assertEqual(second, 'b')
        self.assertEqual(third, 'c')
        self.assertEqual(
            list(new_iterable), ['a', 'b', 'c', 'd', 'e', 'f', 'g']
        ) 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:11,代码来源:test_more.py

示例7: unroll

# 需要导入模块: import more_itertools [as 别名]
# 或者: from more_itertools import first [as 别名]
def unroll(list_of_lists):
    """
    :param list_of_lists: a list that contains lists
    :param rec: unroll recursively
    :return: a flattened list
    """
    if isinstance(first(list_of_lists), (np.ndarray, list)):
        return list(flatten(list_of_lists))
    return list_of_lists 
开发者ID:Unbabel,项目名称:OpenKiwi,代码行数:11,代码来源:utils.py

示例8: put

# 需要导入模块: import more_itertools [as 别名]
# 或者: from more_itertools import first [as 别名]
def put(self, application_name):
        """Creates or updates a default route policy of specific application.

        :param application_name: The name of specific application.
        :form ezone: Optional. The ezone of default route. Default: ``overall``
        :form intent: Optional. The intent of default route. Default:
                      ``direct``
        :form cluster_name: The name of destination cluster. The cluster name
                            must not be ezone prefixed.
        :<header Authorization: Huskar Token (See :ref:`token`)
        :status 200: Operation success.
        """
        check_application_auth(application_name, Authority.WRITE)
        ezone = request.form.get('ezone') or OVERALL
        intent = request.form.get('intent') or ROUTE_DEFAULT_INTENT
        cluster_name = request.form['cluster_name']
        check_cluster_name(cluster_name, application_name)
        facade = RouteManagement(huskar_client, application_name, None)
        try:
            default_route = facade.set_default_route(
                ezone, intent, cluster_name)
        except ValueError as e:
            # TODO: Use a better validator instead
            return api_response(
                status='InvalidArgument', message=first(e.args, '')), 400
        audit_log.emit(
            audit_log.types.UPDATE_DEFAULT_ROUTE,
            application_name=application_name, ezone=ezone, intent=intent,
            cluster_name=cluster_name)
        return api_response({
            'default_route': default_route,
            'global_default_route': settings.ROUTE_DEFAULT_POLICY}) 
开发者ID:huskar-org,项目名称:huskar,代码行数:34,代码来源:service_route.py

示例9: delete

# 需要导入模块: import more_itertools [as 别名]
# 或者: from more_itertools import first [as 别名]
def delete(self, application_name):
        """Discards a default route policy of specific application.

        :param application_name: The name of specific application.
        :form ezone: Optional. The ezone of default route. Default: ``overall``
        :form intent: Optional. The intent of default route. Default:
                      ``direct``
        :<header Authorization: Huskar Token (See :ref:`token`)
        :status 200: Operation success.
        """
        check_application_auth(application_name, Authority.WRITE)
        ezone = request.form.get('ezone') or OVERALL
        intent = request.form.get('intent') or ROUTE_DEFAULT_INTENT
        facade = RouteManagement(huskar_client, application_name, None)
        try:
            default_route = facade.discard_default_route(ezone, intent)
        except ValueError as e:
            # TODO: Use a better validator instead
            return api_response(
                status='InvalidArgument', message=first(e.args, '')), 400
        audit_log.emit(
            audit_log.types.DELETE_DEFAULT_ROUTE,
            application_name=application_name, ezone=ezone, intent=intent)
        return api_response({
            'default_route': default_route,
            'global_default_route': settings.ROUTE_DEFAULT_POLICY}) 
开发者ID:huskar-org,项目名称:huskar,代码行数:28,代码来源:service_route.py

示例10: normalize_cluster_name

# 需要导入模块: import more_itertools [as 别名]
# 或者: from more_itertools import first [as 别名]
def normalize_cluster_name(cluster_name):
    """Normalizes the cluster name to avoid from duplicated E-Zone prefix."""
    fragments = cluster_name.split(u'-')
    prefix = first(fragments)
    if prefix and prefix in settings.ROUTE_EZONE_LIST:
        return u'-'.join(dedupleft(fragments, prefix))
    return unicode(cluster_name) 
开发者ID:huskar-org,项目名称:huskar,代码行数:9,代码来源:utils.py


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