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


Python builtins.next方法代码示例

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


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

示例1: get_plexpy_pms_token

# 需要导入模块: from future import builtins [as 别名]
# 或者: from future.builtins import next [as 别名]
def get_plexpy_pms_token(self, force=False):
        if force:
            logger.debug("Tautulli PlexTV :: Forcing refresh of Plex.tv token.")
            devices_list = self.get_devices_list()
            device_id = next((d for d in devices_list if d['device_identifier'] == plexpy.CONFIG.PMS_UUID), {}).get('device_id', None)

            if device_id:
                logger.debug("Tautulli PlexTV :: Removing Tautulli from Plex.tv devices.")
                try:
                    self.delete_plextv_device(device_id=device_id)
                except:
                    logger.error("Tautulli PlexTV :: Failed to remove Tautulli from Plex.tv devices.")
                    return None
            else:
                logger.warn("Tautulli PlexTV :: No existing Tautulli device found.")

        logger.info("Tautulli PlexTV :: Fetching a new Plex.tv token for Tautulli.")
        user = self.get_token()
        if user:
            token = user['auth_token']
            plexpy.CONFIG.__setattr__('PMS_TOKEN', token)
            plexpy.CONFIG.write()
            logger.info("Tautulli PlexTV :: Updated Plex.tv token for Tautulli.")
            return token 
开发者ID:Tautulli,项目名称:Tautulli,代码行数:26,代码来源:plextv.py

示例2: test_stop_test

# 需要导入模块: from future import builtins [as 别名]
# 或者: from future.builtins import next [as 别名]
def test_stop_test(self):
        """Test that the stop_test method ends the test's data."""
        MockTestSuite.components = (SuccessCase,)

        run_data = RunData(run_name=None)
        main_test = MockTestSuite(run_data=run_data)
        test_case = next(iter(main_test))

        self.client.start_test_run(main_test)
        self._validate_has_times(test_case, start_time=False, end_time=False)

        self.client.start_test(test_case)
        self._validate_has_times(test_case, start_time=True, end_time=False)

        self.client.stop_test(test_case)
        self._validate_has_times(test_case, start_time=True, end_time=True) 
开发者ID:gregoil,项目名称:rotest,代码行数:18,代码来源:test_result_manager.py

示例3: test_implements_py2_iterator

# 需要导入模块: from future import builtins [as 别名]
# 或者: from future.builtins import next [as 别名]
def test_implements_py2_iterator(self):
        
        class Upper(object):
            def __init__(self, iterable):
                self._iter = iter(iterable)
            def __next__(self):                 # note the Py3 interface
                return next(self._iter).upper()
            def __iter__(self):
                return self

        self.assertEqual(list(Upper('hello')), list('HELLO'))

        # Try combining it with the next() function:

        class MyIter(object):
            def __next__(self):
                return 'Next!'
            def __iter__(self):
                return self
        
        itr = MyIter()
        self.assertEqual(next(itr), 'Next!')

        itr2 = MyIter()
        for i, item in enumerate(itr2):
            if i >= 10:
                break
            self.assertEqual(item, 'Next!') 
开发者ID:hughperkins,项目名称:kgsgo-dataset-preprocessor,代码行数:30,代码来源:test_object.py

示例4: test_non_iterator

# 需要导入模块: from future import builtins [as 别名]
# 或者: from future.builtins import next [as 别名]
def test_non_iterator(self):
        """
        The default behaviour of next(o) for a newobject o should be to raise a
        TypeError, as with the corresponding builtin object.
        """
        o = object()
        with self.assertRaises(TypeError):
            next(o) 
开发者ID:hughperkins,项目名称:kgsgo-dataset-preprocessor,代码行数:10,代码来源:test_object.py

示例5: add_newsletter_config

# 需要导入模块: from future import builtins [as 别名]
# 或者: from future.builtins import next [as 别名]
def add_newsletter_config(agent_id=None, **kwargs):
    if str(agent_id).isdigit():
        agent_id = int(agent_id)
    else:
        logger.error("Tautulli Newsletters :: Unable to add new newsletter: invalid agent_id %s."
                     % agent_id)
        return False

    agent = next((a for a in available_newsletter_agents() if a['id'] == agent_id), None)

    if not agent:
        logger.error("Tautulli Newsletters :: Unable to retrieve new newsletter agent: invalid agent_id %s."
                     % agent_id)
        return False

    agent_class = get_agent_class(agent_id=agent['id'])

    keys = {'id': None}
    values = {'agent_id': agent['id'],
              'agent_name': agent['name'],
              'agent_label': agent['label'],
              'id_name': '',
              'friendly_name': '',
              'newsletter_config': json.dumps(agent_class.config),
              'email_config': json.dumps(agent_class.email_config),
              'subject': agent_class.subject,
              'body': agent_class.body,
              'message': agent_class.message
              }

    db = database.MonitorDatabase()
    try:
        db.upsert(table_name='newsletters', key_dict=keys, value_dict=values)
        newsletter_id = db.last_insert_id()
        logger.info("Tautulli Newsletters :: Added new newsletter agent: %s (newsletter_id %s)."
                    % (agent['label'], newsletter_id))
        blacklist_logger()
        return newsletter_id
    except Exception as e:
        logger.warn("Tautulli Newsletters :: Unable to add newsletter agent: %s." % e)
        return False 
开发者ID:Tautulli,项目名称:Tautulli,代码行数:43,代码来源:newsletters.py

示例6: _try_to_lock_available_resource

# 需要导入模块: from future import builtins [as 别名]
# 或者: from future.builtins import next [as 别名]
def _try_to_lock_available_resource(self, username, groups,
                                        descriptor_dict):
        """Try to lock one of the given available resources.

        Args:
            descriptor_dict (dict): a descriptor dict of the wanted resource.
                Example:
                    {
                        "type": "resourceData",
                        "properties": {}
                    }
            username (str): the user who wants to lock the resource.
            groups (list): list of the resource groups that the resource
                should be taken from.

        Returns:
            ResourceData. the locked resource.

        Raises:
            BadRequest. If there are no available resources.
        """
        try:
            descriptor = ResourceDescriptor.decode(descriptor_dict)

        except ResourceTypeError as e:
            raise BadRequest(str(e))

        availables = self._get_available_resources(
            descriptor, username, groups)

        try:
            resource = next(availables)
            self._lock_resource(resource, username)
            return resource

        except StopIteration:
            raise BadRequest(UNAVAILABLE_RESOURCES.format(descriptor)) 
开发者ID:gregoil,项目名称:rotest,代码行数:39,代码来源:lock_resources.py

示例7: _run_case

# 需要导入模块: from future import builtins [as 别名]
# 或者: from future.builtins import next [as 别名]
def _run_case(test_class, config=default_config, debug=ENABLE_DEBUG, **kwargs):
    """Run a test of the given class, passing extra parameters as arguments.

    Args:
        test_class (type): class inheriting from AbstractTest.
        config (dict): run configuration dict.
        debug (bool): whether to run the test in debug mode or not.
        kwargs (dict): resources to use for the test.
    """
    class AlmightySuite(TestSuite):
        components = [test_class]

    suite_instance = _run_suite(AlmightySuite, config, debug, **kwargs)

    return next(iter(suite_instance)) 
开发者ID:gregoil,项目名称:rotest,代码行数:17,代码来源:shell.py

示例8: get_work_dir

# 需要导入模块: from future import builtins [as 别名]
# 或者: from future.builtins import next [as 别名]
def get_work_dir(base_dir, test_name, test_item):
    """Get the working directory for the given test.

    Creates a work directory for by joining the given base directory,
    the test name and the current date time string. If the work directory
    already exists the new one will get the copy number extension.

    Args:
        base_dir (str): base directory path.
        test_name (str): test name.
        test_item (object): test instance.

    Returns:
        str. path of the working directory.
    """
    if test_item is None:
        basic_work_dir = test_name

    else:
        test_index = get_test_index(test_item)
        if test_index is None:
            basic_work_dir = datetime.strftime(datetime.now(),
                                               DATE_TIME_FORMAT)

        else:
            basic_work_dir = "%d_%s" % (test_index, test_name)

    basic_work_dir = os.path.join(base_dir, basic_work_dir)
    work_dir = basic_work_dir

    copy_count = count()
    while os.path.exists(work_dir):
        work_dir = basic_work_dir + '(%s)' % next(copy_count)

    os.makedirs(work_dir)
    return work_dir 
开发者ID:gregoil,项目名称:rotest,代码行数:38,代码来源:utils.py

示例9: __init__

# 需要导入模块: from future import builtins [as 别名]
# 或者: from future.builtins import next [as 别名]
def __init__(self, methodName='test_method', indexer=count(), parent=None,
                 save_state=True, config=None, enable_debug=False,
                 resource_manager=None, skip_init=False):

        if enable_debug:
            for method_name in (methodName, self.SETUP_METHOD_NAME,
                                self.TEARDOWN_METHOD_NAME):

                debug(getattr(self, method_name),
                      ignore_exceptions=[KeyboardInterrupt,
                                         unittest.SkipTest,
                                         BdbQuit])

        super(AbstractTest, self).__init__(methodName)

        self.result = None
        self.is_main = True
        self.config = config
        self.parent = parent
        self.skip_init = skip_init
        self.save_state = save_state
        self.identifier = next(indexer)
        self.enable_debug = enable_debug
        self.parents_count = self._get_parents_count()

        self.all_resources = AttrDict()
        self.locked_resources = AttrDict()

        self._is_client_local = False
        self.resource_manager = resource_manager

        if parent is not None:
            parent.addTest(self) 
开发者ID:gregoil,项目名称:rotest,代码行数:35,代码来源:abstract_test.py

示例10: release_resources

# 需要导入模块: from future import builtins [as 别名]
# 或者: from future.builtins import next [as 别名]
def release_resources(self, resources=None, dirty=False,
                          force_release=True):
        """Release given resources using the client.

        Args:
            resources (list): resource names to release, leave None to release
                all locked resources.
            dirty (bool): True if the resource's integrity has been
                compromised, and it should be re-validated.
            force_release (bool): whether to always release to resources
                or enable saving them for next tests.
        """
        if resources is None:
            resources = list(self.locked_resources.keys())

        if len(resources) == 0:
            # No resources to release locked
            return

        resources_dict = {
            name: resource
            for name, resource in iteritems(self.locked_resources)
            if name in resources
        }

        not_releasing = [name for name in resources
                         if name not in resources_dict]

        if not_releasing:
            self.logger.warn("Not releasing (since they weren't locked by "
                             "the component): %r", not_releasing)

        self.resource_manager.release_resources(list(resources_dict.values()),
                                                dirty=dirty,
                                                force_release=force_release)

        # Remove the resources from the test's resource to avoid double release
        for resource in resources_dict:
            self.locked_resources.pop(resource, None) 
开发者ID:gregoil,项目名称:rotest,代码行数:41,代码来源:abstract_test.py

示例11: test_start_test

# 需要导入模块: from future import builtins [as 别名]
# 或者: from future.builtins import next [as 别名]
def test_start_test(self):
        """Test that the start_test method starts the test's data."""
        MockTestSuite.components = (SuccessCase,)

        run_data = RunData(run_name=None)
        main_test = MockTestSuite(run_data=run_data)
        test_case = next(iter(main_test))

        self.client.start_test_run(main_test)
        self._validate_has_times(test_case, start_time=False)

        self.client.start_test(test_case)
        self._validate_has_times(test_case, start_time=True) 
开发者ID:gregoil,项目名称:rotest,代码行数:15,代码来源:test_result_manager.py

示例12: test_update_resources

# 需要导入模块: from future import builtins [as 别名]
# 或者: from future.builtins import next [as 别名]
def test_update_resources(self):
        """Test that the update_resources method updates the test's data."""
        MockTestSuite.components = (SuccessCase,)

        run_data = RunData(run_name=None)
        main_test = MockTestSuite(run_data=run_data)
        test_case = next(iter(main_test))

        test_case.locked_resources = {'test_resource': DemoResource(
            data=DemoResourceData.objects.get(name='available_resource1'))}

        self.client.start_test_run(main_test)
        self.client.start_test(test_case)
        self.client.update_resources(test_case)

        test_data = CaseData.objects.get(name=test_case.data.name)

        self.assertEqual(test_data.resources.count(),
                         len(test_case.locked_resources),
                         "Wrong resources count, (expected resources %r, "
                         "actual resources %r)" %
                         (list(test_case.locked_resources.values()),
                          test_data.resources.all()))

        for resource in itervalues(test_case.locked_resources):
            self.assertEqual(
                     test_data.resources.filter(name=resource.name).count(), 1,
                     "Resource %r wasn't found in %r" %
                     (resource.name, test_data.resources.all())) 
开发者ID:gregoil,项目名称:rotest,代码行数:31,代码来源:test_result_manager.py

示例13: test_add_result

# 需要导入模块: from future import builtins [as 别名]
# 或者: from future.builtins import next [as 别名]
def test_add_result(self):
        """Test that the add_result method updates the test's data.

        This test simulates the workflow of running a test in server side:
        * Start a case and a case.
        * Assert that the result values are not yet set.
        * Stop the test and add a result.
        * Assert that the case's and case's results are as expected.
        """
        MockTestSuite.components = (SuccessCase,)

        run_data = RunData(run_name=None)
        main_test = MockTestSuite(run_data=run_data)
        test_case = next(iter(main_test))

        # Simulate starting the test.
        self.client.start_test_run(main_test)
        self.client.start_composite(main_test)
        self.client.start_test(test_case)

        # Check that the results are still None.
        self._validate_test_result(main_test, success=None)
        self._validate_test_result(test_case, success=None,
                                   error_tuple=(None, ''))

        # Simulate ending the test.
        self.client.stop_test(test_case)
        ERROR_STRING = 'test error'
        EXPECTED_STRING = 'ERROR: ' + ERROR_STRING
        self.client.add_result(test_case, TestOutcome.ERROR,
                               ERROR_STRING)
        self.client.stop_composite(main_test)

        # Check that the results are updated.
        self._validate_test_result(test_case, success=False,
                            error_tuple=(TestOutcome.ERROR, EXPECTED_STRING))
        self._validate_test_result(main_test, success=False) 
开发者ID:gregoil,项目名称:rotest,代码行数:39,代码来源:test_result_manager.py

示例14: _run_case

# 需要导入模块: from future import builtins [as 别名]
# 或者: from future.builtins import next [as 别名]
def _run_case(self, test_case):
        """Run given case and return it.

        Args:
            test_case (rotest.core.case.TestCase): case to run.

        Returns:
            rotest.core.case.TestCase. the case.
        """
        class InternalSuite(MockTestSuite):
            components = (test_case,)

        test_suite = InternalSuite()
        self.run_test(test_suite)
        return next(iter(test_suite)) 
开发者ID:gregoil,项目名称:rotest,代码行数:17,代码来源:test_monitor.py

示例15: header_encode_lines

# 需要导入模块: from future import builtins [as 别名]
# 或者: from future.builtins import next [as 别名]
def header_encode_lines(self, string, maxlengths):
        """Header-encode a string by converting it first to bytes.

        This is similar to `header_encode()` except that the string is fit
        into maximum line lengths as given by the argument.

        :param string: A unicode string for the header.  It must be possible
            to encode this string to bytes using the character set's
            output codec.
        :param maxlengths: Maximum line length iterator.  Each element
            returned from this iterator will provide the next maximum line
            length.  This parameter is used as an argument to built-in next()
            and should never be exhausted.  The maximum line lengths should
            not count the RFC 2047 chrome.  These line lengths are only a
            hint; the splitter does the best it can.
        :return: Lines of encoded strings, each with RFC 2047 chrome.
        """
        # See which encoding we should use.
        codec = self.output_codec or 'us-ascii'
        header_bytes = _encode(string, codec)
        encoder_module = self._get_encoder(header_bytes)
        encoder = partial(encoder_module.header_encode, charset=codec)
        # Calculate the number of characters that the RFC 2047 chrome will
        # contribute to each line.
        charset = self.get_output_charset()
        extra = len(charset) + RFC2047_CHROME_LEN
        # Now comes the hard part.  We must encode bytes but we can't split on
        # bytes because some character sets are variable length and each
        # encoded word must stand on its own.  So the problem is you have to
        # encode to bytes to figure out this word's length, but you must split
        # on characters.  This causes two problems: first, we don't know how
        # many octets a specific substring of unicode characters will get
        # encoded to, and second, we don't know how many ASCII characters
        # those octets will get encoded to.  Unless we try it.  Which seems
        # inefficient.  In the interest of being correct rather than fast (and
        # in the hope that there will be few encoded headers in any such
        # message), brute force it. :(
        lines = []
        current_line = []
        maxlen = next(maxlengths) - extra
        for character in string:
            current_line.append(character)
            this_line = EMPTYSTRING.join(current_line)
            length = encoder_module.header_length(_encode(this_line, charset))
            if length > maxlen:
                # This last character doesn't fit so pop it off.
                current_line.pop()
                # Does nothing fit on the first line?
                if not lines and not current_line:
                    lines.append(None)
                else:
                    separator = (' ' if lines else '')
                    joined_line = EMPTYSTRING.join(current_line)
                    header_bytes = _encode(joined_line, codec)
                    lines.append(encoder(header_bytes))
                current_line = [character]
                maxlen = next(maxlengths) - extra
        joined_line = EMPTYSTRING.join(current_line)
        header_bytes = _encode(joined_line, codec)
        lines.append(encoder(header_bytes))
        return lines 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:63,代码来源:charset.py


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