@@ -106,6 +106,9 @@ def __call__(self, *args, **kwargs):
106
106
"""
107
107
return self .get (* args , ** kwargs )
108
108
109
+ def __iter__ (self ):
110
+ return iter (self .repository )
111
+
109
112
110
113
class RepositoryEmpty (object ):
111
114
def __init__ (self , source = '' , encoding = DEFAULT_ENCODING ):
@@ -117,6 +120,9 @@ def __contains__(self, key):
117
120
def __getitem__ (self , key ):
118
121
return None
119
122
123
+ def __iter__ (self ):
124
+ return iter (())
125
+
120
126
121
127
class RepositoryIni (RepositoryEmpty ):
122
128
"""
@@ -139,6 +145,9 @@ def __getitem__(self, key):
139
145
except NoOptionError :
140
146
raise KeyError (key )
141
147
148
+ def __iter__ (self ):
149
+ return iter (self .parser [self .SECTION ])
150
+
142
151
143
152
class RepositoryEnv (RepositoryEmpty ):
144
153
"""
@@ -165,6 +174,9 @@ def __contains__(self, key):
165
174
def __getitem__ (self , key ):
166
175
return self .data [key ]
167
176
177
+ def __iter__ (self ):
178
+ return iter (self .data )
179
+
168
180
169
181
class RepositorySecret (RepositoryEmpty ):
170
182
"""
@@ -187,6 +199,9 @@ def __contains__(self, key):
187
199
def __getitem__ (self , key ):
188
200
return self .data [key ]
189
201
202
+ def __iter__ (self ):
203
+ return iter (self .data )
204
+
190
205
191
206
class AutoConfig (object ):
192
207
"""
@@ -225,7 +240,9 @@ def _find_file(self, path):
225
240
# reached root without finding any files.
226
241
return ''
227
242
228
- def _load (self , path ):
243
+ def _load (self , path = None ):
244
+ path = path or self .search_path or self ._caller_path ()
245
+
229
246
# Avoid unintended permission errors
230
247
try :
231
248
filename = self ._find_file (os .path .abspath (path ))
@@ -241,9 +258,15 @@ def _caller_path(self):
241
258
path = os .path .dirname (frame .f_back .f_back .f_code .co_filename )
242
259
return path
243
260
261
+ def __iter__ (self ):
262
+ if not self .config :
263
+ self ._load ()
264
+
265
+ return iter (self .config )
266
+
244
267
def __call__ (self , * args , ** kwargs ):
245
268
if not self .config :
246
- self ._load (self . search_path or self . _caller_path () )
269
+ self ._load ()
247
270
248
271
return self .config (* args , ** kwargs )
249
272
0 commit comments