Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/uipath-platform/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "uipath-platform"
version = "0.3.12"
version = "0.3.13"
description = "HTTP client library for programmatic access to UiPath Platform"
readme = { file = "README.md", content-type = "text/markdown" }
requires-python = ">=3.11"
Expand Down
4 changes: 3 additions & 1 deletion packages/uipath-platform/src/uipath/platform/_uipath.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ def documents(self) -> DocumentsService:

@property
def documents_v2(self) -> DocumentsServiceV2:
return DocumentsServiceV2(self._config, self._execution_context)
return DocumentsServiceV2(
self._config, self._execution_context, folders_service=self.folders
)

@property
def queues(self) -> QueuesService:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
FieldType,
FieldValueProjection,
FileContent,
ModelExtractionResponse,
ProjectType,
Reference,
StartExtractionResponse,
StartExtractionValidationResponse,
StartModelExtractionResponse,
StartOperationResponse,
ValidateClassificationAction,
ValidateExtractionAction,
Expand Down Expand Up @@ -49,4 +51,6 @@
"StartExtractionResponse",
"StartOperationResponse",
"StartExtractionValidationResponse",
"StartModelExtractionResponse",
"ModelExtractionResponse",
]
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,18 @@
import time
from contextlib import nullcontext
from pathlib import Path
from typing import Any, Awaitable, Callable, Dict, List, Optional, Set, Tuple, Union
from typing import (
Any,
Awaitable,
Callable,
Dict,
List,
Optional,
Set,
Tuple,
TypeVar,
Union,
)
from urllib.parse import quote
from uuid import UUID

Expand Down Expand Up @@ -33,6 +44,8 @@
POLLING_INTERVAL = 2 # seconds
POLLING_TIMEOUT = 300 # seconds

T = TypeVar("T")

# Response values returned as-is: Document Processing contract payloads are
# PascalCase in every API version, and the digitization DOM is large and unused.
_UNNORMALIZED_KEYS = frozenset(
Expand All @@ -46,15 +59,33 @@
)


def _framework_url(*segments: Any) -> Endpoint:
def _url_path(segments: Tuple[Any, ...]) -> str:
parts = [str(segment) for segment in segments]
for part in parts:
# Percent-encoding leaves these unchanged, and URL normalization would
# resolve them, moving the request to another route.
if part in ("", ".", ".."):
raise ValueError(f"Invalid URL path segment: {part!r}")
path = "/".join(quote(part, safe="") for part in parts)
return Endpoint(f"/du_/api/framework/projects/{path}")
return "/".join(quote(part, safe="") for part in parts)


def _framework_url(*segments: Any) -> Endpoint:
return Endpoint(f"/du_/api/framework/projects/{_url_path(segments)}")


def _status_result(
outcome: Tuple[Any, Optional[Any], Optional[Any]],
wait_statuses: List[str],
success_status: str,
) -> Any:
"""Read one `(status, error, result)` check for `_wait_until_complete`."""
status, error, result = outcome
if status in wait_statuses:
# Only signals the poller to try again; it never reaches the caller.
raise OperationNotCompleteException(operation_id="", status=status)
if status != success_status:
raise RuntimeError(f"Operation failed with status: {status}, error: {error}")
return result


def _operation_result(
Expand Down Expand Up @@ -801,31 +832,47 @@ async def _start_extraction_async(
api_version=self._api_version,
)

def _wait_until_complete(self, retrieve: Callable[[], T]) -> T:
"""Call `retrieve` until it stops raising `OperationNotCompleteException`.

This is the one polling loop of the documents services: blocking
methods wait through it, on the same single-check `retrieve` that
non-blocking callers use.

Raises:
TimeoutError: If the operation is still not complete after `polling_timeout`.
"""
start_time = time.monotonic()
while True:
try:
return retrieve()
except OperationNotCompleteException:
if time.monotonic() - start_time >= self.polling_timeout:
raise TimeoutError("Operation timed out.") from None
time.sleep(self.polling_interval)

async def _wait_until_complete_async(
self, retrieve: Callable[[], Awaitable[T]]
) -> T:
"""Asynchronous version of `_wait_until_complete`."""
start_time = time.monotonic()
while True:
try:
return await retrieve()
except OperationNotCompleteException:
if time.monotonic() - start_time >= self.polling_timeout:
raise TimeoutError("Operation timed out.") from None
await asyncio.sleep(self.polling_interval)

def _wait_for_operation(
self,
result_getter: Callable[[], Tuple[Any, Optional[Any], Optional[Any]]],
wait_statuses: List[str],
success_status: str,
) -> Any:
start_time = time.monotonic()
status = wait_statuses[0]
result = None

while (
status in wait_statuses
and (time.monotonic() - start_time) < self.polling_timeout
):
status, error, result = result_getter()
time.sleep(self.polling_interval)

if status != success_status:
if time.monotonic() - start_time >= self.polling_timeout:
raise TimeoutError("Operation timed out.")
raise RuntimeError(
f"Operation failed with status: {status}, error: {error}"
)

return result
return self._wait_until_complete(
lambda: _status_result(result_getter(), wait_statuses, success_status)
)

async def _wait_for_operation_async(
self,
Expand All @@ -835,25 +882,10 @@ async def _wait_for_operation_async(
wait_statuses: List[str],
success_status: str,
) -> Any:
start_time = time.monotonic()
status = wait_statuses[0]
result = None

while (
status in wait_statuses
and (time.monotonic() - start_time) < self.polling_timeout
):
status, error, result = await result_getter()
await asyncio.sleep(self.polling_interval)

if status != success_status:
if time.monotonic() - start_time >= self.polling_timeout:
raise TimeoutError("Operation timed out.")
raise RuntimeError(
f"Operation failed with status: {status}, error: {error}"
)
async def retrieve() -> Any:
return _status_result(await result_getter(), wait_statuses, success_status)

return result
return await self._wait_until_complete_async(retrieve)

def _wait_for_extraction(
self,
Expand Down
Loading
Loading