|
1 | | -# Copyright 2014 Google Inc. All rights reserved. |
| 1 | +# Copyright 2015 Google Inc. All rights reserved. |
2 | 2 | # |
3 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
4 | 4 | # you may not use this file except in compliance with the License. |
|
22 | 22 | those results into an iterable of the actual objects you want:: |
23 | 23 |
|
24 | 24 | class MyIterator(Iterator): |
25 | | - def get_items_from_response(self, response): |
26 | | - items = response.get('items', []) |
27 | | - for item in items: |
28 | | - my_item = MyItemClass(other_arg=True) |
29 | | - my_item._set_properties(item) |
30 | | - yield my_item |
| 25 | + def get_items_from_response(self, response): |
| 26 | + items = response.get('items', []) |
| 27 | + for item in items: |
| 28 | + my_item = MyItemClass(other_arg=True) |
| 29 | + my_item._set_properties(item) |
| 30 | + yield my_item |
31 | 31 |
|
32 | 32 | You then can use this to get **all** the results from a resource:: |
33 | 33 |
|
34 | | - >>> iterator = MyIterator(...) |
35 | | - >>> list(iterator) # Convert to a list (consumes all values). |
| 34 | + >>> iterator = MyIterator(...) |
| 35 | + >>> list(iterator) # Convert to a list (consumes all values). |
36 | 36 |
|
37 | 37 | Or you can walk your way through items and call off the search early if |
38 | 38 | you find what you're looking for (resulting in possibly fewer |
39 | 39 | requests):: |
40 | 40 |
|
41 | | - >>> for item in MyIterator(...): |
42 | | - >>> print item.name |
43 | | - >>> if not item.is_valid: |
44 | | - >>> break |
| 41 | + >>> for item in MyIterator(...): |
| 42 | + >>> print item.name |
| 43 | + >>> if not item.is_valid: |
| 44 | + >>> break |
45 | 45 | """ |
46 | 46 |
|
47 | 47 |
|
48 | 48 | class Iterator(object): |
49 | | - """A generic class for iterating through Cloud Storage list responses. |
| 49 | + """A generic class for iterating through Cloud JSON APIs list responses. |
50 | 50 |
|
51 | | - :type connection: :class:`gcloud.storage.connection.Connection` |
| 51 | + :type connection: :class:`gcloud.connection.Connection` |
52 | 52 | :param connection: The connection to use to make requests. |
53 | 53 |
|
54 | 54 | :type path: string |
|
0 commit comments