Skip to content

Commit b5962dd

Browse files
author
Vadim Grem
committed
refactor: use return_raw_content flag instead of hardcoded name check
Replace _is_content_download name matching with a explicit return_raw_content flag on FunctionQuery. Callers set the flag at construction time — cleaner and extensible.
1 parent c657c29 commit b5962dd

4 files changed

Lines changed: 12 additions & 6 deletions

File tree

office365/onedrive/driveitems/driveItem.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ def get_content(self, format_name: str | None = None) -> ClientResult[AnyStr]:
427427
action_name = "content"
428428
if format_name is not None:
429429
action_name = action_name + rf"?format={format_name}"
430-
qry = FunctionQuery(self, action_name, None, return_type)
430+
qry = FunctionQuery(self, action_name, None, return_type, return_raw_content=True)
431431
self.context.add_query(qry)
432432
return return_type
433433

office365/runtime/odata/request.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,7 @@ def process_response(self, response: Response, query: ClientQuery) -> None:
9292
@staticmethod
9393
def _is_content_download(query: ClientQuery) -> bool:
9494
"""Check if the query is a raw content download (file content, not OData metadata)."""
95-
if isinstance(query, FunctionQuery):
96-
name = query.name
97-
return name in ("content", "$value")
98-
return False
95+
return bool(getattr(query, "return_raw_content", False))
9996

10097
def map_json(
10198
self,

office365/runtime/queries/function.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ def __init__(
1515
method_name: str | None = None,
1616
method_params: list | dict | ClientValue | None = None,
1717
return_type: ReturnT | None = None,
18+
return_raw_content: bool = False,
1819
) -> None:
1920
"""Initialize a function query.
2021
@@ -23,9 +24,17 @@ def __init__(
2324
method_name: The name of the method to call
2425
method_params: Parameters for the method call
2526
return_type: The expected return type
27+
return_raw_content: When True, the response body is treated as raw content
28+
(e.g. file download) rather than parsed as OData JSON.
2629
"""
2730
super().__init__(binding_type.context, binding_type, None, None, return_type)
2831
self._path = ServiceOperationPath(method_name or "", method_params, binding_type.resource_path)
32+
self._return_raw_content = return_raw_content
33+
34+
@property
35+
def return_raw_content(self) -> bool:
36+
"""Whether the response should be treated as raw content, not OData JSON."""
37+
return self._return_raw_content
2938

3039
def __repr__(self) -> str:
3140
return f"FunctionQuery(name={self.path.name})"

office365/sharepoint/files/file.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def _file_loaded():
140140
def get_content(self) -> ClientResult[bytes]:
141141
"""Downloads a file content"""
142142
return_type = ClientResult(self.context, bytes())
143-
qry = FunctionQuery(self, "$value", return_type=return_type)
143+
qry = FunctionQuery(self, "$value", return_type=return_type, return_raw_content=True)
144144
self.context.add_query(qry)
145145
return return_type
146146

0 commit comments

Comments
 (0)