Show More
@@ -2554,6 +2554,9 b' class _generatorset(object):' | |||
|
2554 | 2554 | internally |
|
2555 | 2555 | """ |
|
2556 | 2556 | def __init__(self, gen): |
|
2557 | """ | |
|
2558 | gen: a generator producing the values for the generatorset. | |
|
2559 | """ | |
|
2557 | 2560 | self._gen = gen |
|
2558 | 2561 | self._iter = iter(gen) |
|
2559 | 2562 | self._cache = {} |
@@ -2565,6 +2568,7 b' class _generatorset(object):' | |||
|
2565 | 2568 | if x in self._cache: |
|
2566 | 2569 | return self._cache[x] |
|
2567 | 2570 | |
|
2571 | # Use __iter__ which caches values and stores them into self._genlist | |
|
2568 | 2572 | for l in self: |
|
2569 | 2573 | if l == x: |
|
2570 | 2574 | return True |
@@ -2575,9 +2579,12 b' class _generatorset(object):' | |||
|
2575 | 2579 | |
|
2576 | 2580 | def __iter__(self): |
|
2577 | 2581 | if self._iterated: |
|
2582 | # At least a part of the list should be cached if iteration has | |
|
2583 | # started over the generatorset. | |
|
2578 | 2584 | for l in self._genlist: |
|
2579 | 2585 | yield l |
|
2580 | 2586 | else: |
|
2587 | # Starting iteration over the generatorset. | |
|
2581 | 2588 | self._iterated = True |
|
2582 | 2589 | |
|
2583 | 2590 | for item in self._gen: |
@@ -2585,13 +2592,14 b' class _generatorset(object):' | |||
|
2585 | 2592 | self._genlist.append(item) |
|
2586 | 2593 | yield item |
|
2587 | 2594 | |
|
2595 | # Iteration over the generator has finished. Whole value list should be | |
|
2596 | # cached in self._genlist | |
|
2588 | 2597 | self._finished = True |
|
2589 | 2598 | |
|
2590 | 2599 | def set(self): |
|
2591 | 2600 | return self |
|
2592 | 2601 | |
|
2593 | 2602 | def sort(self, reverse=False): |
|
2594 | # Basic implementation to be changed in future patches | |
|
2595 | 2603 | if not self._finished: |
|
2596 | 2604 | for i in self: |
|
2597 | 2605 | continue |
General Comments 0
You need to be logged in to leave comments.
Login now