Skip to content

Commit 0087ef7

Browse files
Remove ContentRange class and use plain strings for content range
Co-authored-by: changjian-wang <15209050+changjian-wang@users.noreply.github.com>
1 parent 16895d1 commit 0087ef7

11 files changed

Lines changed: 222 additions & 836 deletions

File tree

sdk/contentunderstanding/azure-ai-contentunderstanding/azure/ai/contentunderstanding/_patch.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ def begin_analyze_binary(
236236
analyzer_id: str,
237237
binary_input: bytes,
238238
*,
239-
content_range: Optional[Union[str, _models.ContentRange]] = None,
239+
content_range: Optional[str] = None,
240240
content_type: str = "application/octet-stream",
241241
processing_location: Optional[Union[str, _models.ProcessingLocation]] = None,
242242
**kwargs: Any,
@@ -247,11 +247,10 @@ def begin_analyze_binary(
247247
:type analyzer_id: str
248248
:param binary_input: The binary content of the document to analyze. Required.
249249
:type binary_input: bytes
250-
:keyword content_range: Range of the input to analyze. Accepts a
251-
:class:`~azure.ai.contentunderstanding.models.ContentRange` or a raw string
250+
:keyword content_range: Range of the input to analyze. Accepts a raw string
252251
(ex. ``"1-3,5,9-"``). Document content uses 1-based page numbers,
253252
while audio visual content uses integer milliseconds. Default value is None.
254-
:paramtype content_range: str or ~azure.ai.contentunderstanding.models.ContentRange
253+
:paramtype content_range: str
255254
:keyword content_type: Body Parameter content-type. Content type parameter for binary body.
256255
Default value is "application/octet-stream".
257256
:paramtype content_type: str
@@ -268,16 +267,13 @@ def begin_analyze_binary(
268267
matches Python's native string indexing behavior (len() and str[i] use code points).
269268
This ensures ContentSpan offsets work correctly with Python string slicing.
270269
"""
271-
# Convert ContentRange to string if needed
272-
content_range_str = str(content_range) if content_range is not None else None
273-
274270
# Call parent implementation with string_encoding set to "codePoint"
275271
# (matches Python's string indexing)
276272
poller = super().begin_analyze_binary(
277273
analyzer_id=analyzer_id,
278274
binary_input=binary_input,
279275
string_encoding="codePoint",
280-
content_range=content_range_str,
276+
content_range=content_range,
281277
content_type=content_type,
282278
processing_location=processing_location,
283279
**kwargs,

sdk/contentunderstanding/azure-ai-contentunderstanding/azure/ai/contentunderstanding/aio/_patch.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ async def begin_analyze_binary(
237237
analyzer_id: str,
238238
binary_input: bytes,
239239
*,
240-
content_range: Optional[Union[str, _models.ContentRange]] = None,
240+
content_range: Optional[str] = None,
241241
content_type: str = "application/octet-stream",
242242
processing_location: Optional[Union[str, _models.ProcessingLocation]] = None,
243243
**kwargs: Any,
@@ -248,11 +248,10 @@ async def begin_analyze_binary(
248248
:type analyzer_id: str
249249
:param binary_input: The binary content of the document to analyze. Required.
250250
:type binary_input: bytes
251-
:keyword content_range: Range of the input to analyze. Accepts a
252-
:class:`~azure.ai.contentunderstanding.models.ContentRange` or a raw string
251+
:keyword content_range: Range of the input to analyze. Accepts a raw string
253252
(ex. ``"1-3,5,9-"``). Document content uses 1-based page numbers,
254253
while audio visual content uses integer milliseconds. Default value is None.
255-
:paramtype content_range: str or ~azure.ai.contentunderstanding.models.ContentRange
254+
:paramtype content_range: str
256255
:keyword content_type: Body Parameter content-type. Content type parameter for binary body.
257256
Default value is "application/octet-stream".
258257
:paramtype content_type: str
@@ -269,16 +268,13 @@ async def begin_analyze_binary(
269268
matches Python's native string indexing behavior (len() and str[i] use code points).
270269
This ensures ContentSpan offsets work correctly with Python string slicing.
271270
"""
272-
# Convert ContentRange to string if needed
273-
content_range_str = str(content_range) if content_range is not None else None
274-
275271
# Call parent implementation with string_encoding set to "codePoint"
276272
# (matches Python's string indexing)
277273
poller = await super().begin_analyze_binary(
278274
analyzer_id=analyzer_id,
279275
binary_input=binary_input,
280276
string_encoding="codePoint",
281-
content_range=content_range_str,
277+
content_range=content_range,
282278
content_type=content_type,
283279
processing_location=processing_location,
284280
**kwargs,

sdk/contentunderstanding/azure-ai-contentunderstanding/azure/ai/contentunderstanding/models/_content_range.py

Lines changed: 0 additions & 196 deletions
This file was deleted.

sdk/contentunderstanding/azure-ai-contentunderstanding/azure/ai/contentunderstanding/models/_patch.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
from typing import TYPE_CHECKING, Any, Dict, List, Optional, TypeVar
1515
from azure.core import CaseInsensitiveEnumMeta
1616
from azure.core.polling import LROPoller, PollingMethod
17-
from ._content_range import ContentRange
1817
from ._models import (
1918
StringField,
2019
IntegerField,
@@ -77,7 +76,6 @@ def value(self) -> Optional[Any]: ...
7776
PollingReturnType_co = TypeVar("PollingReturnType_co", covariant=True)
7877

7978
__all__ = [
80-
"ContentRange",
8179
"RecordMergePatchUpdate",
8280
"AnalyzeLROPoller",
8381
"ProcessingLocation",

sdk/contentunderstanding/azure-ai-contentunderstanding/samples/async_samples/sample_analyze_binary_async.py

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
from azure.ai.contentunderstanding.aio import ContentUnderstandingClient
5959
from azure.ai.contentunderstanding.models import (
6060
AnalysisResult,
61-
ContentRange,
6261
DocumentContent,
6362
)
6463
from azure.core.credentials import AzureKeyCredential
@@ -91,55 +90,50 @@ async def main() -> None:
9190
# [END analyze_document_from_binary]
9291

9392
# [START analyze_binary_with_content_range]
94-
# Use a multi-page document for ContentRange demonstrations.
93+
# Use a multi-page document for content range demonstrations.
9594
multi_page_path = "sample_files/mixed_financial_invoices.pdf"
9695
with open(multi_page_path, "rb") as f:
9796
multi_page_bytes = f.read()
9897

9998
# Analyze only pages 3 onward.
100-
print("\nAnalyzing pages 3 onward with ContentRange...")
99+
print("\nAnalyzing pages 3 onward with content range '3-'...")
101100
range_poller = await client.begin_analyze_binary(
102101
analyzer_id="prebuilt-documentSearch",
103102
binary_input=multi_page_bytes,
104-
content_range=ContentRange.pages_from(3),
103+
content_range="3-",
105104
)
106105
range_result: AnalysisResult = await range_poller.result()
107106

108107
if isinstance(range_result.contents[0], DocumentContent):
109108
range_doc = range_result.contents[0]
110109
print(
111-
f"ContentRange analysis returned pages"
110+
f"Content range analysis returned pages"
112111
f" {range_doc.start_page_number} - {range_doc.end_page_number}"
113112
)
114113
# [END analyze_binary_with_content_range]
115114

116115
# [START analyze_binary_with_combined_content_range]
117116
# Analyze pages 1-3, page 5, and pages 9 onward.
118-
print("\nAnalyzing combined pages (1-3, 5, 9-) with ContentRange...")
117+
print("\nAnalyzing combined pages (1-3, 5, 9-) with content range '1-3,5,9-'...")
119118
combine_range_poller = await client.begin_analyze_binary(
120119
analyzer_id="prebuilt-documentSearch",
121120
binary_input=multi_page_bytes,
122-
content_range=ContentRange.combine(
123-
ContentRange.pages(1, 3),
124-
ContentRange.page(5),
125-
ContentRange.pages_from(9),
126-
),
121+
content_range="1-3,5,9-",
127122
)
128123
combine_range_result: AnalysisResult = await combine_range_poller.result()
129124

130125
if isinstance(combine_range_result.contents[0], DocumentContent):
131126
combine_doc = combine_range_result.contents[0]
132127
print(
133-
f"Combined ContentRange analysis returned pages"
128+
f"Combined content range analysis returned pages"
134129
f" {combine_doc.start_page_number} - {combine_doc.end_page_number}"
135130
)
136131
# [END analyze_binary_with_combined_content_range]
137132

138133
# [START analyze_binary_with_raw_content_range]
139-
# You can also pass content range as a plain string directly, without using
140-
# ContentRange factory methods. The wire format is the same as what the factory methods produce.
134+
# Content range is passed as a plain string. Document ranges use 1-based page numbers.
141135

142-
# "1-3" — pages 1 through 3 (equivalent to ContentRange.pages(1, 3))
136+
# "1-3" — pages 1 through 3
143137
print("\nAnalyzing pages 1-3 with raw string '1-3'...")
144138
raw_pages_poller = await client.begin_analyze_binary(
145139
analyzer_id="prebuilt-documentSearch",
@@ -155,7 +149,7 @@ async def main() -> None:
155149
f" {raw_pages_doc.start_page_number} - {raw_pages_doc.end_page_number}"
156150
)
157151

158-
# "9-" — pages 9 onward (equivalent to ContentRange.pages_from(9))
152+
# "9-" — pages 9 onward
159153
print("\nAnalyzing pages 9 onward with raw string '9-'...")
160154
raw_from_poller = await client.begin_analyze_binary(
161155
analyzer_id="prebuilt-documentSearch",
@@ -171,7 +165,7 @@ async def main() -> None:
171165
f" {raw_from_doc.start_page_number} - {raw_from_doc.end_page_number}"
172166
)
173167

174-
# "1-3,5,9-" — combined ranges (equivalent to ContentRange.combine(pages(1,3), page(5), pages_from(9)))
168+
# "1-3,5,9-" — combined ranges
175169
print("\nAnalyzing combined pages (1-3, 5, 9-) with raw string '1-3,5,9-'...")
176170
raw_combine_poller = await client.begin_analyze_binary(
177171
analyzer_id="prebuilt-documentSearch",

0 commit comments

Comments
 (0)