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
33 changes: 33 additions & 0 deletions tableauserverclient/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,24 @@
WorkbookItem,
)

from tableauserverclient.types import (
AddResponse,
FilePath,
FileObject,
FileObjectR,
FileObjectW,
HasIdpConfigurationID,
HyperAction,
HyperActionCondition,
HyperActionRow,
HyperActionTable,
IDPAttributes,
IDPProperty,
PathOrFile,
PathOrFileR,
PathOrFileW,
)

from tableauserverclient.server import (
CSVRequestOptions,
ExcelRequestOptions,
Expand All @@ -76,6 +94,7 @@
)

__all__ = [
"AddResponse",
"BackgroundJobItem",
"CollectionItem",
"ColumnItem",
Expand All @@ -96,13 +115,24 @@
"FailedSignInError",
"FavoriteItem",
"FileuploadItem",
"FilePath",
"FileObject",
"FileObjectR",
"FileObjectW",
"Filter",
"FlowItem",
"FlowRunItem",
"get_versions",
"GroupItem",
"GroupSetItem",
"HasIdpConfigurationID",
"HourlyInterval",
"HyperAction",
"HyperActionCondition",
"HyperActionRow",
"HyperActionTable",
"IDPAttributes",
"IDPProperty",
"ImageRequestOptions",
"IntervalItem",
"JobItem",
Expand All @@ -122,6 +152,9 @@
"Permission",
"PermissionsRule",
"PersonalAccessTokenAuth",
"PathOrFile",
"PathOrFileR",
"PathOrFileW",
"ProjectItem",
"RequestOptions",
"Resource",
Expand Down
8 changes: 2 additions & 6 deletions tableauserverclient/server/endpoint/custom_views_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,8 @@
update the name or owner of a custom view.
"""

FilePath = str | os.PathLike
FileObject = io.BufferedReader | io.BytesIO
FileObjectR = io.BufferedReader | io.BytesIO
FileObjectW = io.BufferedWriter | io.BytesIO
PathOrFileR = FilePath | FileObjectR
PathOrFileW = FilePath | FileObjectW
from tableauserverclient.types import FilePath, FileObject, FileObjectR, FileObjectW, PathOrFileR, PathOrFileW

io_types_r = (io.BufferedReader, io.BytesIO)
io_types_w = (io.BufferedWriter, io.BytesIO)

Expand Down
64 changes: 15 additions & 49 deletions tableauserverclient/server/endpoint/datasources_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,29 @@
import os

from pathlib import Path
from typing import Literal, TYPE_CHECKING, TypedDict, TypeVar, overload
from typing import Literal, TYPE_CHECKING, TypeVar, overload
from collections.abc import Iterable, Sequence

from tableauserverclient.models.dqw_item import DQWItem
from tableauserverclient.server.query import QuerySet
from tableauserverclient.types import (
FilePath,
FileObject,
FileObjectR,
FileObjectW,
PathOrFile,
PathOrFileR,
PathOrFileW,
HyperAction,
HyperActionCondition,
HyperActionRow,
HyperActionTable,
AddResponse,
)

if TYPE_CHECKING:
from tableauserverclient.server import Server
from tableauserverclient.models import PermissionsRule
from .schedules_endpoint import AddResponse

from tableauserverclient.server.endpoint.dqw_endpoint import _DataQualityWarningEndpoint
from tableauserverclient.server.endpoint.endpoint import DownloadableMixin, QuerysetEndpoint, api, parameter_added_in
Expand Down Expand Up @@ -44,53 +57,6 @@

io_types_r = (io.BytesIO, io.BufferedReader)

FilePath = str | os.PathLike
FileObject = io.BufferedReader | io.BytesIO
PathOrFile = FilePath | FileObject

FileObjectR = io.BufferedReader | io.BytesIO
FileObjectW = io.BufferedWriter | io.BytesIO
PathOrFileR = FilePath | FileObjectR
PathOrFileW = FilePath | FileObjectW


HyperActionCondition = TypedDict(
"HyperActionCondition",
{
"op": str,
"target-col": str,
"source-col": str,
},
)

HyperActionRow = TypedDict(
"HyperActionRow",
{
"action": Literal[
"update",
"upsert",
"delete",
],
"source-table": str,
"target-table": str,
"condition": HyperActionCondition,
},
)

HyperActionTable = TypedDict(
"HyperActionTable",
{
"action": Literal[
"insert",
"replace",
],
"source-table": str,
"target-table": str,
},
)

HyperAction = HyperActionTable | HyperActionRow


_UNSET = object()

Expand Down
10 changes: 2 additions & 8 deletions tableauserverclient/server/endpoint/flows_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,12 @@

from tableauserverclient.helpers.logging import logger

from tableauserverclient.types import FilePath, FileObjectR, FileObjectW, PathOrFileR, PathOrFileW, AddResponse

if TYPE_CHECKING:
from tableauserverclient.models import DQWItem
from tableauserverclient.models.permissions_item import PermissionsRule
from tableauserverclient.server.request_options import RequestOptions
from tableauserverclient.server.endpoint.schedules_endpoint import AddResponse


FilePath = str | os.PathLike
FileObjectR = io.BufferedReader | io.BytesIO
FileObjectW = io.BufferedWriter | io.BytesIO
PathOrFileR = FilePath | FileObjectR
PathOrFileW = FilePath | FileObjectW


class Flows(QuerysetEndpoint[FlowItem], TaggingMixin[FlowItem], DownloadableMixin):
Expand Down
15 changes: 2 additions & 13 deletions tableauserverclient/server/endpoint/oidc_endpoint.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,15 @@
from typing import Protocol, Union, TYPE_CHECKING
from typing import TYPE_CHECKING
from tableauserverclient.models.oidc_item import SiteOIDCConfiguration
from tableauserverclient.server.endpoint import Endpoint
from tableauserverclient.server.request_factory import RequestFactory
from tableauserverclient.server.endpoint.endpoint import api
from tableauserverclient.types import HasIdpConfigurationID

if TYPE_CHECKING:
from tableauserverclient.models.site_item import SiteAuthConfiguration
from tableauserverclient.server.server import Server


class IDPAttributes(Protocol):
idp_configuration_id: str


class IDPProperty(Protocol):
@property
def idp_configuration_id(self) -> str: ...


HasIdpConfigurationID = str | IDPAttributes


class OIDC(Endpoint):
def __init__(self, server: "Server") -> None:
self.parent_srv = server
Expand Down
3 changes: 1 addition & 2 deletions tableauserverclient/server/endpoint/schedules_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@
import copy
import logging
import warnings
from collections import namedtuple
from typing import TYPE_CHECKING, Any, Callable, Literal, overload

from .endpoint import Endpoint, api, parameter_added_in
from .exceptions import MissingRequiredFieldError
from tableauserverclient.server import RequestFactory
from tableauserverclient.models import PaginationItem, ScheduleItem, TaskItem, ExtractItem
from tableauserverclient.models.schedule_item import parse_batch_schedule_state
from tableauserverclient.types import AddResponse

from tableauserverclient.helpers.logging import logger

AddResponse = namedtuple("AddResponse", ("result", "error", "warnings", "task_created"))
OK = AddResponse(result=True, error=None, warnings=None, task_created=None)

if TYPE_CHECKING:
Expand Down
19 changes: 10 additions & 9 deletions tableauserverclient/server/endpoint/workbooks_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,20 @@
)
from collections.abc import Iterable, Sequence

from tableauserverclient.types import (
FilePath,
FileObject,
FileObjectR,
FileObjectW,
PathOrFileR,
PathOrFileW,
AddResponse,
)

if TYPE_CHECKING:
from tableauserverclient.server import Server
from tableauserverclient.server.request_options import RequestOptions, PDFRequestOptions, PPTXRequestOptions
from tableauserverclient.models import DatasourceItem
from tableauserverclient.server.endpoint.schedules_endpoint import AddResponse

io_types_r = (io.BytesIO, io.BufferedReader)

Expand All @@ -51,14 +60,6 @@

from tableauserverclient.helpers.logging import logger

FilePath = str | os.PathLike
FileObject = io.BufferedReader | io.BytesIO
FileObjectR = io.BufferedReader | io.BytesIO
FileObjectW = io.BufferedWriter | io.BytesIO
PathOrFileR = FilePath | FileObjectR
PathOrFileW = FilePath | FileObjectW


_UNSET = object()


Expand Down
71 changes: 71 additions & 0 deletions tableauserverclient/types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import io
import os
from collections import namedtuple
from typing import Literal, Protocol, TypedDict

# File path and object type aliases used across publish/download methods
FilePath = str | os.PathLike
FileObject = io.BufferedReader | io.BytesIO
FileObjectR = io.BufferedReader | io.BytesIO
FileObjectW = io.BufferedWriter | io.BytesIO
PathOrFile = FilePath | FileObject
PathOrFileR = FilePath | FileObjectR
PathOrFileW = FilePath | FileObjectW


# Hyper action types for Datasources.update_hyper_data()
HyperActionCondition = TypedDict(
"HyperActionCondition",
{
"op": str,
"target-col": str,
"source-col": str,
},
)

HyperActionRow = TypedDict(
"HyperActionRow",
{
"action": Literal["update", "upsert", "delete"],
"source-table": str,
"target-table": str,
"condition": HyperActionCondition,
},
)

HyperActionTable = TypedDict(
"HyperActionTable",
{
"action": Literal["insert", "replace"],
"source-table": str,
"target-table": str,
},
)

HyperAction = HyperActionTable | HyperActionRow


# Return type for Schedules.add_to_schedule()
AddResponse = namedtuple("AddResponse", ("result", "error", "warnings", "task_created"))


# IDP types for OIDC endpoint. Two Protocol variants are provided so callers
# can satisfy the interface with either style:
# - IDPAttributes: idp_configuration_id declared as a plain class attribute
# (invariant under mypy; matches simple dataclasses / attrs-style objects).
# - IDPProperty: idp_configuration_id declared as a read-only @property
# (matches classes that compute the value or want to prevent external writes).
#
# HasIdpConfigurationID unions both so downstream callers can implement either
# style without hitting mypy invariance errors. Callers accept
# `str | HasIdpConfigurationID` -- passing a raw id string or an object.
class IDPAttributes(Protocol):
idp_configuration_id: str


class IDPProperty(Protocol):
@property
def idp_configuration_id(self) -> str: ...


HasIdpConfigurationID = IDPAttributes | IDPProperty
Loading