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


Python six.advance_iterator函数代码示例

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


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

示例1: scan_field_id

def scan_field_id(token, state, stream, lexdata):
    # When a candidate is found, do as follows:
    # - save the candidate
    # - eat any whitespace
    # - if next is colon, candidate is an identifier, emit both
    # identifier and colon
    candidate = token
    token = stream.peek()
    if token.type == "WS":
        token = stream.peek()
    if token.type == "COLON":
        # We do have a identifier, so replace WORD token by the
        # right keyword token
        candidate = _new_token(META_FIELDS_ID[candidate.value], candidate)

    try:
        field_type = FIELD_TYPE[candidate.type]
    except KeyError:
        data = lexdata.splitlines()
        msg = ["Error while tokenizing %r (missing colon ?)" %  candidate.value]
        msg += ["    Line %d -> %r" % (candidate.lineno, data[candidate.lineno-1])]
        raise SyntaxError("\n".join(msg))
    try:
        state = _FIELD_TYPE_TO_STATE[field_type]
    except KeyError:
        raise ValueError("Unknown state transition for type %s" % field_type)

    queue = [candidate]
    queue.append(six.advance_iterator(stream))
    nxt = six.advance_iterator(stream)
    return queue, nxt, state
开发者ID:jjehannet,项目名称:Bento,代码行数:31,代码来源:lexer.py

示例2: __delitem__

 def __delitem__(self, key):
     tmp = self._slice.duplicate()
     op = tmp._call_stack[-1][0]
     if op == _IndexedComponent_slice.get_item:
         # If the last attribute of the slice gets an item,
         # change it to delete the item
         tmp._call_stack[-1] = (
             _IndexedComponent_slice.del_item,
             tmp._call_stack[-1][1] )
     elif op == _IndexedComponent_slice.slice_info:
         assert len(tmp._call_stack) == 1
         _iter = self._get_iter(tmp, key)
         try:
             advance_iterator(_iter)
             del _iter._iter_stack[0].component[_iter.get_last_index()]
             return
         except StopIteration:
             raise KeyError("KeyError: %s" % (key,))
     elif op == _IndexedComponent_slice.get_attribute:
         # If the last attribute of the slice retrieves an attribute,
         # change it to delete the attribute
         tmp._call_stack[-1] = (
             _IndexedComponent_slice.del_attribute,
             tmp._call_stack[-1][1] )
     else:
         raise DeveloperError(
             "Unexpected slice _call_stack operation: %s" % op)
     try:
         advance_iterator(self._get_iter(tmp, key))
     except StopIteration:
         pass
开发者ID:Pyomo,项目名称:pyomo,代码行数:31,代码来源:reference.py

示例3: run_concurrent_tests

    def run_concurrent_tests(self, input_iter):
        """Run tests concurrently."""

        it = iter(input_iter)
        numtests = 0
        try:
            for proc in self.procs:
                self.task_queue.put(advance_iterator(it))
                numtests += 1
        except StopIteration:
            pass
        else:
            try:
                while numtests:
                    result = self.done_queue.get()
                    yield result
                    numtests -= 1
                    if self.stop and result.status == 'FAIL':
                        break
                    self.task_queue.put(advance_iterator(it))
                    numtests += 1
            except StopIteration:
                pass

        for proc in self.procs:
            self.task_queue.put('STOP')

        for i in range(numtests):
            yield self.done_queue.get()

        for proc in self.procs:
            proc.join()
开发者ID:swryan,项目名称:testflo,代码行数:32,代码来源:runner.py

示例4: _iter

 def _iter(self):
     rlist = []
     self._rdate.sort()
     self._genitem(rlist, iter(self._rdate))
     for gen in [iter(x) for x in self._rrule]:
         self._genitem(rlist, gen)
     rlist.sort()
     exlist = []
     self._exdate.sort()
     self._genitem(exlist, iter(self._exdate))
     for gen in [iter(x) for x in self._exrule]:
         self._genitem(exlist, gen)
     exlist.sort()
     lastdt = None
     total = 0
     while rlist:
         ritem = rlist[0]
         if not lastdt or lastdt != ritem.dt:
             while exlist and exlist[0] < ritem:
                 advance_iterator(exlist[0])
                 exlist.sort()
             if not exlist or ritem != exlist[0]:
                 total += 1
                 yield ritem.dt
             lastdt = ritem.dt
         advance_iterator(ritem)
         rlist.sort()
     self._len = total
开发者ID:klahnakoski,项目名称:pyLibrary,代码行数:28,代码来源:rrule.py

示例5: __setitem__

 def __setitem__(self, key, val):
     tmp = self._slice.duplicate()
     op = tmp._call_stack[-1][0]
     if op == _IndexedComponent_slice.get_item:
         tmp._call_stack[-1] = (
             _IndexedComponent_slice.set_item,
             tmp._call_stack[-1][1],
             val )
     elif op == _IndexedComponent_slice.slice_info:
         tmp._call_stack[-1] = (
             _IndexedComponent_slice.set_item,
             tmp._call_stack[-1][1],
             val )
     elif op == _IndexedComponent_slice.get_attribute:
         tmp._call_stack[-1] = (
             _IndexedComponent_slice.set_attribute,
             tmp._call_stack[-1][1],
             val )
     else:
         raise DeveloperError(
             "Unexpected slice _call_stack operation: %s" % op)
     try:
         advance_iterator(self._get_iter(tmp, key, get_if_not_present=True))
     except StopIteration:
         pass
开发者ID:Pyomo,项目名称:pyomo,代码行数:25,代码来源:reference.py

示例6: test_imap_unordered

 def test_imap_unordered(self):
     p = pool.Pool(1)
     it = p.imap_unordered(divide_by, [1, 0, 2])
     self.assertEqual(six.advance_iterator(it), 1.0)
     self.assertRaises(ZeroDivisionError, six.advance_iterator, it)
     self.assertEqual(six.advance_iterator(it), 0.5)
     self.assertRaises(StopIteration, six.advance_iterator, it)
开发者ID:ajbetteridge,项目名称:gevent,代码行数:7,代码来源:test__pool.py

示例7: test_iter_one_item

    def test_iter_one_item(self):
        self.r.request = Mock()
        self.r.request.return_value = Mock(), {'meta': {'key': 'foos', 'next_page_url': None}, 'foos': [{'sid': '123'}]}

        items = self.r.iter()
        advance_iterator(items)

        self.assertRaises(StopIteration, advance_iterator, items)
开发者ID:AgrAlert,项目名称:AgrAlert_Backend,代码行数:8,代码来源:test_base_resource.py

示例8: testIterOneItem

    def testIterOneItem(self):
        self.r.request = Mock()
        self.r.request.return_value = Mock(), {self.r.key: [{'sid': 'foo'}]}

        items = self.r.iter()
        advance_iterator(items)

        self.assertRaises(StopIteration, advance_iterator, items)
开发者ID:AgrAlert,项目名称:AgrAlert_Backend,代码行数:8,代码来源:test_base_resource.py

示例9: test_imap_unordered_gc

 def test_imap_unordered_gc(self):
     it = self.pool.imap_unordered(sqr, range(10))
     result = []
     for i in range(10):
         result.append(six.advance_iterator(it))
         gc.collect()
     self.assertRaises(StopIteration, lambda: six.advance_iterator(it))
     self.assertEqual(sorted(result), [x * x for x in range(10)])
开发者ID:BSlience,项目名称:gevent,代码行数:8,代码来源:test__threadpool.py

示例10: test_iterator

def test_iterator():
    class myiter(six.Iterator):
        def __next__(self):
            return 13
    assert six.advance_iterator(myiter()) == 13
    class myitersub(myiter):
        def __next__(self):
            return 14
    assert six.advance_iterator(myitersub()) == 14
开发者ID:A-Maze,项目名称:A-Pc,代码行数:9,代码来源:test_six.py

示例11: popitem

 def popitem(self, last=True):
     if not self:
         raise KeyError('dictionary is empty')
     if last:
         key = six.advance_iterator(reversed(self))
     else:
         key = six.advance_iterator(iter(self))
     value = self.pop(key)
     return key, value
开发者ID:MattStockton,项目名称:flask-restful,代码行数:9,代码来源:ordereddict.py

示例12: sample

    def sample(self, cursor):
        """Extract records randomly from the database.
        Continue until the target proportion of the items have been
        extracted, or until `min_items` if this is larger.
        If `max_items` is non-negative, do not extract more than these.

        This function is a generator, yielding items incrementally.

        :param cursor: Cursor to sample
        :type cursor: pymongo.cursor.Cursor
        :return: yields each item
        :rtype: dict
        :raise: ValueError, if max_items is valid and less than `min_items`
                or if target collection is empty
        """
        count = cursor.count()

        # special case: empty collection
        if count == 0:
            self._empty = True
            raise ValueError("Empty collection")

        # special case: entire collection
        if self.p >= 1 and self.max_items <= 0:
            for item in cursor:
                yield item
            return

        # calculate target number of items to select
        if self.max_items <= 0:
            n_target = max(self.min_items, self.p * count)
        else:
            if self.p <= 0:
                n_target = max(self.min_items, self.max_items)
            else:
                n_target = max(self.min_items, min(self.max_items, self.p * count))
        if n_target == 0:
            raise ValueError("No items requested")

        # select first `n_target` items that pop up with
        # probability self.p
        # This is actually biased to items at the beginning
        # of the file if n_target is smaller than (p * count),
        n = 0
        while n < n_target:
            try:
                item = six.advance_iterator(cursor)
            except StopIteration:
                # need to keep looping through data until
                # we get all our items!
                cursor.rewind()
                item = six.advance_iterator(cursor)
            if self._keep():
                yield item
                n += 1
开发者ID:alayers2,项目名称:pymatgen-db,代码行数:55,代码来源:validate.py

示例13: _skip_ws

def _skip_ws(tok, stream, state, internal):
    while tok.type  in ["NEWLINE", "WS"]:
        if tok.type == "NEWLINE" and len(internal.words_stack) == 0:
            nxt = stream.peek()
            if not nxt.type == "INDENT":
                state = "SCANNING_FIELD_ID"
            else:
                tok = six.advance_iterator(stream)
            return tok, state
        tok = six.advance_iterator(stream)
    return tok, state
开发者ID:jjehannet,项目名称:Bento,代码行数:11,代码来源:lexer.py

示例14: test_imap

    def test_imap(self):
        it = self.pool.imap(sqr, range(10))
        self.assertEqual(list(it), list(map(squared, range(10))))

        it = self.pool.imap(sqr, range(10))
        for i in range(10):
            self.assertEqual(six.advance_iterator(it), i * i)
        self.assertRaises(StopIteration, lambda: six.advance_iterator(it))

        it = self.pool.imap(sqr, range(1000))
        for i in range(1000):
            self.assertEqual(six.advance_iterator(it), i * i)
        self.assertRaises(StopIteration, lambda: six.advance_iterator(it))
开发者ID:AlexSnet,项目名称:oneline,代码行数:13,代码来源:test__pool.py

示例15: checkIteratorParallel

 def checkIteratorParallel(self):
     self._dostore()
     self._dostore()
     iter1 = self._storage.iterator()
     iter2 = self._storage.iterator()
     txn_info1 = six.advance_iterator(iter1)
     txn_info2 = six.advance_iterator(iter2)
     self.assertEqual(txn_info1.tid, txn_info2.tid)
     txn_info1 = six.advance_iterator(iter1)
     txn_info2 = six.advance_iterator(iter2)
     self.assertEqual(txn_info1.tid, txn_info2.tid)
     self.assertRaises(StopIteration, next, iter1)
     self.assertRaises(StopIteration, next, iter2)
开发者ID:zopefoundation,项目名称:ZEO,代码行数:13,代码来源:IterationTests.py


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