Completed
Pull Request — master (#75)
by Cézar
01:32
created

BaseQuasiDictionaryIterator.__iter__()   A

Complexity

Conditions 1

Size

Total Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
dl 0
loc 2
rs 10
1
__author__ = "Jon Reid"
2
__copyright__ = "Copyright 2011 hamcrest.org"
3
__license__ = "BSD, see License.txt"
4
5
import six
6
7
8
class QuasiDictionary(object):
9
    def items(self):
10
        return QuasiDictionaryItemIterator()
11
12
    def keys(self):
13
        return QuasiDictionaryKeyIterator()
14
15
    def values(self):
16
        return QuasiDictionaryValueIterator()
17
18
19
class BaseQuasiDictionaryIterator(six.Iterator):
20
    def __init__(self):
21
        self.index = 1
22
23
    def __iter__(self):
24
        return self
25
26
    def __next__(self):
27
        if self.index >= 3:
28
            raise StopIteration
29
        result = self.indexToResult()
30
        self.index += 1
31
        return result
32
33
34
class QuasiDictionaryItemIterator(BaseQuasiDictionaryIterator):
35
    def indexToResult(self):
36
        return (self.index, str(self.index))
37
38
39
class QuasiDictionaryKeyIterator(BaseQuasiDictionaryIterator):
40
    def indexToResult(self):
41
        return self.index
42
43
44
class QuasiDictionaryValueIterator(BaseQuasiDictionaryIterator):
45
    def indexToResult(self):
46
        return str(self.index)
47