Skip to content

Commit d9051f8

Browse files
committed
OData request/response serializer enhancements
1 parent e549e82 commit d9051f8

13 files changed

+58
-20
lines changed

office365/graph_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def __init__(self, acquire_token_callback):
4949
:param () -> dict acquire_token_callback: Acquire token function
5050
"""
5151
super(GraphClient, self).__init__()
52-
self._pending_request = ODataRequest(self, V4JsonFormat("minimal"))
52+
self._pending_request = ODataRequest(self, V4JsonFormat())
5353
self._pending_request.beforeExecute += self._build_specific_query
5454
self._resource = "https://graph.microsoft.com"
5555
self._authority_host_url = "https://login.microsoftonline.com"

office365/runtime/client_object.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,9 @@ def to_json(self, json_format=None):
205205
if isinstance(v, ClientObject) or isinstance(v, ClientValue):
206206
json[k] = v.to_json(json_format)
207207

208-
if json and self.entity_type_name is not None:
209-
if isinstance(json_format, JsonLightFormat) and json_format.is_verbose:
208+
if json and self.entity_type_name is not None and json_format.include_control_information():
209+
if isinstance(json_format, JsonLightFormat):
210210
json[json_format.metadata_type_tag_name] = {'type': self.entity_type_name}
211-
elif isinstance(json_format, ODataJsonFormat) and json_format.metadata_level == "minimal":
211+
elif isinstance(json_format, ODataJsonFormat):
212212
json[json_format.metadata_type_tag_name] = "#" + self.entity_type_name
213213
return json

office365/runtime/client_value.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def to_json(self, json_format=None):
3333
if isinstance(v, ClientValue):
3434
json[n] = v.to_json(json_format)
3535

36-
if isinstance(json_format, JsonLightFormat) and json_format.is_verbose and self.entity_type_name is not None:
36+
if isinstance(json_format, JsonLightFormat) and json_format.include_control_information() and self.entity_type_name is not None:
3737
json[json_format.metadata_type_tag_name] = {'type': self.entity_type_name}
3838

3939
return json

office365/runtime/client_value_collection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def to_json(self, json_format=None):
4141
for i, v in enumerate(json_items):
4242
if isinstance(v, ClientValue):
4343
json_items[i] = v.to_json(json_format)
44-
if isinstance(json_format, JsonLightFormat) and json_format.is_verbose:
44+
if isinstance(json_format, JsonLightFormat) and json_format.include_control_information():
4545
json = {json_format.collection_tag_name: json_items,
4646
json_format.metadata_type_tag_name: {'type': self.entity_type_name}}
4747

office365/runtime/odata/odata_json_format.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,11 @@ def __init__(self, metadata_level=None):
2121
@abstractmethod
2222
def get_media_type(self):
2323
pass
24+
25+
@abstractmethod
26+
def include_control_information(self):
27+
"""Determines whether control information that is represented as annotations should be included in payload
28+
29+
:rtype: bool
30+
"""
31+
pass
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
from office365.runtime.odata.odata_json_format import ODataJsonFormat
2-
from office365.runtime.odata.v3.metadata_level import ODataMetadataLevel
2+
from office365.runtime.odata.v3.metadata_level import ODataV3MetadataLevel
33

44

55
class JsonLightFormat(ODataJsonFormat):
66
"""JSON Light format for SharePoint Online/One Drive for Business"""
77

8-
def __init__(self, metadata_level=ODataMetadataLevel.Verbose):
8+
def __init__(self, metadata_level=ODataV3MetadataLevel.Verbose):
99
super(JsonLightFormat, self).__init__(metadata_level)
10-
if self.metadata_level == ODataMetadataLevel.Verbose:
10+
if self.metadata_level == ODataV3MetadataLevel.Verbose:
1111
self.security_tag_name = "d"
1212
self.collection_tag_name = "results"
1313
self.collection_next_tag_name = "__next"
@@ -19,6 +19,6 @@ def __init__(self, metadata_level=ODataMetadataLevel.Verbose):
1919
def get_media_type(self):
2020
return 'application/json;odata={0}'.format(self.metadata_level)
2121

22-
@property
23-
def is_verbose(self):
24-
return self.metadata_level == ODataMetadataLevel.Verbose
22+
def include_control_information(self):
23+
return self.metadata_level == ODataV3MetadataLevel.Verbose \
24+
or self.metadata_level == ODataV3MetadataLevel.MinimalMetadata
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
class ODataMetadataLevel:
1+
class ODataV3MetadataLevel:
22
"""The amount of metadata information to serialize in an OData response."""
33
def __init__(self):
44
pass
55

66
Verbose = "verbose"
7+
"""Indicates that the service MUST include all control information explicitly in the payload."""
8+
79
NoMetadata = "nometadata"
10+
"""Indicates that the service SHOULD omit control information other than odata.nextLink and odata.count"""
11+
812
MinimalMetadata = "minimalmetadata"
13+
"""Indicates that the service SHOULD remove computable control information from the payload wherever possible"""

office365/runtime/odata/v4/json_format.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
from office365.runtime.odata.odata_json_format import ODataJsonFormat
2+
from office365.runtime.odata.v4.metadata_level import ODataV4MetadataLevel
23

34

45
class V4JsonFormat(ODataJsonFormat):
56
"""V4 JSON format"""
67

7-
def __init__(self, metadata_level):
8+
def __init__(self, metadata_level=ODataV4MetadataLevel.Minimal):
89
super(V4JsonFormat, self).__init__(metadata_level)
910
"""The IEEE754Compatible format parameter indicates that the service MUST serialize Edm.Int64 and
1011
Edm.Decimal numbers as strings."""
@@ -17,3 +18,6 @@ def __init__(self, metadata_level):
1718
def get_media_type(self):
1819
return "application/json;odata.metadata={0};odata.streaming={1};IEEE754Compatible={2}" \
1920
.format(self.metadata_level, self.streaming, self.IEEE754Compatible)
21+
22+
def include_control_information(self):
23+
return self.metadata_level == ODataV4MetadataLevel.Minimal or self.metadata_level == ODataV4MetadataLevel.Full
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class ODataV4MetadataLevel:
2+
3+
Full = "full"
4+
"""Indicates that the service MUST include all control information explicitly in the payload."""
5+
6+
NoMetadata = "none"
7+
"""Indicates that the service SHOULD omit control information other than odata.nextLink and odata.count"""
8+
9+
Minimal = "minimal"
10+
"""Indicates that the service SHOULD remove computable control information from the payload wherever possible.
11+
This is the default value for the odata.metadata parameter and will be assumed if no other value is specified in
12+
the Accept header or $format query option"""
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from office365.runtime.client_value_collection import ClientValueCollection
2+
3+
4+
class StringCollection(ClientValueCollection):
5+
6+
def __init__(self, initial_values=None):
7+
super(StringCollection, self).__init__(str, initial_values)
8+
9+
@property
10+
def entity_type_name(self):
11+
return "Collection(Edm.String)"

office365/sharepoint/client_context.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from office365.runtime.http.request_options import RequestOptions
1111
from office365.runtime.odata.v3.json_light_format import JsonLightFormat
1212
from office365.runtime.odata.v3.batch_request import ODataBatchRequest
13-
from office365.runtime.odata.v3.metadata_level import ODataMetadataLevel
1413
from office365.runtime.odata.odata_request import ODataRequest
1514
from office365.runtime.queries.batch_query import BatchQuery
1615
from office365.runtime.queries.client_query import ClientQuery
@@ -146,7 +145,7 @@ def pending_request(self):
146145
:return: ODataRequest
147146
"""
148147
if self.__pending_request is None:
149-
self.__pending_request = ODataRequest(self, JsonLightFormat(ODataMetadataLevel.Verbose))
148+
self.__pending_request = ODataRequest(self, JsonLightFormat())
150149
self.__pending_request.beforeExecute += self._build_modification_query
151150
return self.__pending_request
152151

office365/sharepoint/portal/site_linking_manager.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@ def entity_type_name(self):
2424
class SiteLinkingManager(BaseEntity):
2525
""""""
2626

27-
def __init__(self, context):
28-
super(SiteLinkingManager, self).__init__(context,
29-
ResourcePath("Microsoft.SharePoint.Portal.SiteLinkingManager"))
27+
def __init__(self, context, resource_path=None):
28+
super(SiteLinkingManager, self).__init__(context, resource_path)
3029

3130
def get_site_links(self):
3231
""""""

office365/sharepoint/taxonomy/taxonomy_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def __init__(self, context):
1414
"""
1515
super(TaxonomyService, self).__init__()
1616
self._auth_context = context.authentication_context
17-
self._pendingRequest = ODataRequest(self, V4JsonFormat("minimal"))
17+
self._pendingRequest = ODataRequest(self, V4JsonFormat())
1818
self._service_root_url = "{0}/v2.1/".format(context.service_root_url())
1919

2020
def authenticate_request(self, request):

0 commit comments

Comments
 (0)