當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。