Python six.Iterator() Examples

The following are 10 code examples of six.Iterator(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module six , or try the search function .
Example #1
Source File: TransactionService.py    From client-python with Apache License 2.0 6 votes vote down vote up
def __next__(self):
        if self._done:
            raise GraknError('Iterator was already iterated.')

        try:
            response = next(self._response_iterator)
        except StopIteration:
            raise GraknError('Internal client/protocol error,'
                             ' did not receive an expected "done" or "iteratorId" message.'
                             '\n\n Please ensure client version is supported by server version.')

        iter_res = response.iter_res
        res_type = iter_res.WhichOneof('res')
        if res_type == 'done':
            self._done = True
            raise StopIteration
        elif res_type == 'iteratorId':
            self._request_next_batch(iter_res.iteratorId)
            return next(self)
        else:
            return self._resp_converter(iter_res) 
Example #2
Source File: utils.py    From yaql with Apache License 2.0 5 votes vote down vote up
def is_iterator(obj):
    return isinstance(obj, collections.Iterator) 
Example #3
Source File: utils.py    From yaql with Apache License 2.0 5 votes vote down vote up
def memorize(collection, engine):
    if not is_iterator(collection):
        return collection

    yielded = []

    class RememberingIterator(six.Iterator):
        def __init__(self):
            self.seq = iter(collection)
            self.index = 0

        def __iter__(self):
            return RememberingIterator()

        def __next__(self):
            if self.index < len(yielded):
                self.index += 1
                return yielded[self.index - 1]
            else:
                val = next(self.seq)
                yielded.append(val)
                limit_memory_usage(engine, (1, yielded))
                self.index += 1
                return val

    return RememberingIterator() 
Example #4
Source File: TransactionService.py    From client-python with Apache License 2.0 5 votes vote down vote up
def query(self, query, infer, explain, batch_size):
        return Iterator(self._communicator,
                        RequestBuilder.start_iterating_query(query, infer, explain, batch_size),
                        ResponseReader.ResponseReader.get_query_results(self)) 
Example #5
Source File: TransactionService.py    From client-python with Apache License 2.0 5 votes vote down vote up
def get_attributes_by_value(self, attribute_value, value_type):
        request = RequestBuilder.start_iterating_get_attributes_by_value(attribute_value, value_type)
        return Iterator(self._communicator, request, ResponseReader.ResponseReader.get_attributes_by_value(self)) 
Example #6
Source File: TransactionService.py    From client-python with Apache License 2.0 5 votes vote down vote up
def run_concept_iter_method(self, concept_id, grpc_concept_iter_method_req):
        return Iterator(self._communicator,
                        RequestBuilder.start_iterating_concept_method(concept_id, grpc_concept_iter_method_req),
                        lambda res: res.conceptMethod_iter_res.response) 
Example #7
Source File: test_six.py    From six with MIT License 5 votes vote down vote up
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 
Example #8
Source File: test_six.py    From c4ddev with MIT License 5 votes vote down vote up
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 
Example #9
Source File: test_six.py    From data with GNU General Public License v3.0 5 votes vote down vote up
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 
Example #10
Source File: test_six.py    From data with GNU General Public License v3.0 5 votes vote down vote up
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