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

Python six.advance_iterator函数代码示例

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

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



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


示例16: skip_until_eol

def skip_until_eol(stream, t):
    try:
        prev = stream.previous()
    except ValueError:
        prev = None
    while t.type != "NEWLINE":
        t = six.advance_iterator(stream)
    # FIXME: ideally, we would like to remove EOL for comments which span the
    # full line, but we need access to the token before the comment delimiter
    # to do so, as we don't want to remove EOL for inline commeng (e.g. 'foo #
    # comment')
    if prev and t.type == "NEWLINE" and prev.type in ('NEWLINE', 'INDENT'):
        t = six.advance_iterator(stream)
    return t
开发者ID:jjehannet,项目名称:Bento,代码行数:14,代码来源:lexer.py


示例17: checkIteratorGCStorageTPCAborting

    def checkIteratorGCStorageTPCAborting(self):
        # The odd little jig we do below arises from the fact that the
        # CS iterator may not be constructed right away if the CS is wrapped.
        # We need to actually do some iteration to get the iterator created.
        # We do a store to make sure the iterator isn't exhausted right away.
        self._dostore()
        six.advance_iterator(self._storage.iterator())

        iid = list(self._storage._iterator_ids)[0]

        t = transaction.Transaction()
        self._storage.tpc_begin(t)
        self._storage.tpc_abort(t)
        self.assertEquals(0, len(self._storage._iterator_ids))
        self.assertRaises(KeyError, self._storage._server.iterator_next, iid)
开发者ID:Krilivye,项目名称:ZEO,代码行数:15,代码来源:IterationTests.py


示例18: __contains__

 def __contains__(self, key):
     try:
         advance_iterator(self._get_iter(self._slice, key))
         return True
     except (StopIteration, KeyError):
         return False
     except SliceEllipsisLookupError:
         if type(key) is tuple and len(key) == 1:
             key = key[0]
         # Brute force (linear time) lookup
         _iter = iter(self._slice)
         for item in _iter:
             if _iter.get_last_index_wildcards() == key:
                 return True
         return False
开发者ID:Pyomo,项目名称:pyomo,代码行数:15,代码来源:reference.py


示例19: test_PushbackAdapter

def test_PushbackAdapter():
    it = PushbackAdapter(iter([1, 2, 3, 4]))
    assert it.has_more()
    assert six.advance_iterator(it) == 1
    it.push_back(0)
    assert six.advance_iterator(it) == 0
    assert six.advance_iterator(it) == 2
    assert it.peek() == 3
    it.push_back(10)
    assert it.peek() == 10
    it.push_back(20)
    assert it.peek() == 20
    assert it.has_more()
    assert list(it) == [20, 10, 3, 4]
    assert not it.has_more()
开发者ID:gyenney,项目名称:Tools,代码行数:15,代码来源:util.py


示例20: checkIteratorExhaustionStorage

    def checkIteratorExhaustionStorage(self):
        # Test the storage's garbage collection mechanism.
        self._dostore()
        iterator = self._storage.iterator()

        # At this point, a wrapping iterator might not have called the CS
        # iterator yet. We'll consume one item to make sure this happens.
        six.advance_iterator(iterator)
        self.assertEqual(1, len(self._storage._iterator_ids))
        iid = list(self._storage._iterator_ids)[0]
        self.assertEqual([], list(iterator))
        self.assertEqual(0, len(self._storage._iterator_ids))

        # The iterator has run through, so the server has already disposed it.
        self.assertRaises(KeyError, self._storage._call, 'iterator_next', iid)
开发者ID:zopefoundation,项目名称:ZEO,代码行数:15,代码来源:IterationTests.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python six.assertCountEqual函数代码示例发布时间:2022-05-27
下一篇:
Python six.add_move函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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