Repository navigation
Expand file tree
/
Copy pathcollection_base.py
More file actions
68 lines (48 loc) · 1.88 KB
/
Copy pathcollection_base.py
File metadata and controls
68 lines (48 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
"""
Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
"""
from __future__ import unicode_literals
from .request_base import RequestBase
class CollectionRequestBase(RequestBase):
def __init__(self, request_url, client, options):
super(CollectionRequestBase, self).__init__(request_url, client, options)
def _init_next_page_request(self, next_page_link, client, options):
# implemented in each collection request
pass
def _page_from_response(self, response):
"""Get the collection page from within the response
Args:
response (:class:`CollectionResponseBase`):
The response to get the collection page from
Returns:
The collection page from within the response
"""
if response:
if "@odata.nextLink" in response._prop_dict:
next_page_link = response._prop_dict["@odata.nextLink"]
response.collection_page._init_next_page_request(next_page_link, self._client, None)
return response.collection_page
return None
class CollectionResponseBase(object):
def __init__(self, prop_dict={}):
self._prop_dict = prop_dict
self._collection_page = None
@property
def collection_page(self):
pass
class CollectionBase(object):
def __init__(self, prop_list = []):
self._prop_list = prop_list
def __len__(self):
return len(self._prop_list)
class CollectionPageBase(CollectionBase):
@property
def next_page_request(self):
"""Gets a request for the next page of a collection, if one exists
Returns:
The request object to send
"""
try:
return self._next_page_request
except:
return None