7
7
# --------------------------------------------------------------------------
8
8
9
9
from copy import deepcopy
10
- from typing import TYPE_CHECKING
11
-
12
- from msrest import Deserializer , Serializer
10
+ from typing import Any , Optional , TYPE_CHECKING
11
+ from typing_extensions import Self
13
12
14
13
from azure .core import PipelineClient
14
+ from azure .core .pipeline import policies
15
+ from azure .core .rest import HttpRequest , HttpResponse
15
16
16
- from . import models
17
+ from . import models as _models
17
18
from ._configuration import AzureDigitalTwinsAPIConfiguration
18
- from .operations import DigitalTwinModelsOperations , DigitalTwinsOperations , EventRoutesOperations , QueryOperations
19
+ from ._utils .serialization import Deserializer , Serializer
20
+ from .operations import (
21
+ DeleteJobsOperations ,
22
+ DigitalTwinModelsOperations ,
23
+ DigitalTwinsOperations ,
24
+ EventRoutesOperations ,
25
+ ImportJobsOperations ,
26
+ QueryOperations ,
27
+ )
19
28
20
29
if TYPE_CHECKING :
21
- # pylint: disable=unused-import,ungrouped-imports
22
- from typing import Any
23
-
24
30
from azure .core .credentials import TokenCredential
25
- from azure .core .rest import HttpRequest , HttpResponse
26
31
27
- class AzureDigitalTwinsAPI (object ):
32
+
33
+ class AzureDigitalTwinsAPI :
28
34
"""A service for managing and querying digital twins and digital twin models.
29
35
30
36
:ivar digital_twin_models: DigitalTwinModelsOperations operations
@@ -35,41 +41,74 @@ class AzureDigitalTwinsAPI(object):
35
41
:vartype digital_twins: azure.digitaltwins.core.operations.DigitalTwinsOperations
36
42
:ivar event_routes: EventRoutesOperations operations
37
43
:vartype event_routes: azure.digitaltwins.core.operations.EventRoutesOperations
38
- :param credential: Credential needed for the client to connect to Azure.
44
+ :ivar import_jobs: ImportJobsOperations operations
45
+ :vartype import_jobs: azure.digitaltwins.core.operations.ImportJobsOperations
46
+ :ivar delete_jobs: DeleteJobsOperations operations
47
+ :vartype delete_jobs: azure.digitaltwins.core.operations.DeleteJobsOperations
48
+ :param credential: Credential needed for the client to connect to Azure. Required.
39
49
:type credential: ~azure.core.credentials.TokenCredential
50
+ :param operation_id: ID for the operation's status monitor. The ID is generated if header was
51
+ not passed by the client. Default value is None.
52
+ :type operation_id: str
53
+ :param timeout_in_minutes: Desired timeout for the delete job. Once the specified timeout is
54
+ reached, service will stop any delete operations triggered by the current delete job that are
55
+ in progress, and go to a failed state. Please note that this will leave your instance in an
56
+ unknown state as there won't be any rollback operation. Default value is None.
57
+ :type timeout_in_minutes: int
40
58
:param base_url: Service URL. Default value is "https://digitaltwins-hostname".
41
59
:type base_url: str
42
- :keyword api_version: Api Version. Default value is "2022-05 -31". Note that overriding
43
- this default value may result in unsupported behavior.
60
+ :keyword api_version: Api Version. Default value is "2023-10 -31". Note that overriding this
61
+ default value may result in unsupported behavior.
44
62
:paramtype api_version: str
63
+ :keyword int polling_interval: Default waiting time between two polls for LRO operations if no
64
+ Retry-After header is present.
45
65
"""
46
66
47
67
def __init__ (
48
68
self ,
49
- credential , # type: "TokenCredential"
50
- base_url = "https://digitaltwins-hostname" , # type: str
51
- ** kwargs # type: Any
52
- ):
53
- # type: (...) -> None
54
- self ._config = AzureDigitalTwinsAPIConfiguration (credential = credential , ** kwargs )
55
- self ._client = PipelineClient (base_url = base_url , config = self ._config , ** kwargs )
56
-
57
- client_models = {k : v for k , v in models .__dict__ .items () if isinstance (v , type )}
69
+ credential : "TokenCredential" ,
70
+ operation_id : Optional [str ] = None ,
71
+ timeout_in_minutes : Optional [int ] = None ,
72
+ base_url : str = "https://digitaltwins-hostname" ,
73
+ ** kwargs : Any
74
+ ) -> None :
75
+ self ._config = AzureDigitalTwinsAPIConfiguration (
76
+ credential = credential , operation_id = operation_id , timeout_in_minutes = timeout_in_minutes , ** kwargs
77
+ )
78
+
79
+ _policies = kwargs .pop ("policies" , None )
80
+ if _policies is None :
81
+ _policies = [
82
+ policies .RequestIdPolicy (** kwargs ),
83
+ self ._config .headers_policy ,
84
+ self ._config .user_agent_policy ,
85
+ self ._config .proxy_policy ,
86
+ policies .ContentDecodePolicy (** kwargs ),
87
+ self ._config .redirect_policy ,
88
+ self ._config .retry_policy ,
89
+ self ._config .authentication_policy ,
90
+ self ._config .custom_hook_policy ,
91
+ self ._config .logging_policy ,
92
+ policies .DistributedTracingPolicy (** kwargs ),
93
+ policies .SensitiveHeaderCleanupPolicy (** kwargs ) if self ._config .redirect_policy else None ,
94
+ self ._config .http_logging_policy ,
95
+ ]
96
+ self ._client : PipelineClient = PipelineClient (base_url = base_url , policies = _policies , ** kwargs )
97
+
98
+ client_models = {k : v for k , v in _models .__dict__ .items () if isinstance (v , type )}
58
99
self ._serialize = Serializer (client_models )
59
100
self ._deserialize = Deserializer (client_models )
60
101
self ._serialize .client_side_validation = False
61
- self .digital_twin_models = DigitalTwinModelsOperations (self ._client , self ._config , self ._serialize , self ._deserialize )
102
+ self .digital_twin_models = DigitalTwinModelsOperations (
103
+ self ._client , self ._config , self ._serialize , self ._deserialize
104
+ )
62
105
self .query = QueryOperations (self ._client , self ._config , self ._serialize , self ._deserialize )
63
106
self .digital_twins = DigitalTwinsOperations (self ._client , self ._config , self ._serialize , self ._deserialize )
64
107
self .event_routes = EventRoutesOperations (self ._client , self ._config , self ._serialize , self ._deserialize )
108
+ self .import_jobs = ImportJobsOperations (self ._client , self ._config , self ._serialize , self ._deserialize )
109
+ self .delete_jobs = DeleteJobsOperations (self ._client , self ._config , self ._serialize , self ._deserialize )
65
110
66
-
67
- def _send_request (
68
- self ,
69
- request , # type: HttpRequest
70
- ** kwargs # type: Any
71
- ):
72
- # type: (...) -> HttpResponse
111
+ def _send_request (self , request : HttpRequest , * , stream : bool = False , ** kwargs : Any ) -> HttpResponse :
73
112
"""Runs the network request through the client's chained policies.
74
113
75
114
>>> from azure.core.rest import HttpRequest
@@ -78,7 +117,7 @@ def _send_request(
78
117
>>> response = client._send_request(request)
79
118
<HttpResponse: 200 OK>
80
119
81
- For more information on this code flow, see https://aka.ms/azsdk/python/protocol/quickstart
120
+ For more information on this code flow, see https://aka.ms/azsdk/dpcodegen/ python/send_request
82
121
83
122
:param request: The network request you want to make. Required.
84
123
:type request: ~azure.core.rest.HttpRequest
@@ -89,17 +128,14 @@ def _send_request(
89
128
90
129
request_copy = deepcopy (request )
91
130
request_copy .url = self ._client .format_url (request_copy .url )
92
- return self ._client .send_request (request_copy , ** kwargs )
131
+ return self ._client .send_request (request_copy , stream = stream , ** kwargs ) # type: ignore
93
132
94
- def close (self ):
95
- # type: () -> None
133
+ def close (self ) -> None :
96
134
self ._client .close ()
97
135
98
- def __enter__ (self ):
99
- # type: () -> AzureDigitalTwinsAPI
136
+ def __enter__ (self ) -> Self :
100
137
self ._client .__enter__ ()
101
138
return self
102
139
103
- def __exit__ (self , * exc_details ):
104
- # type: (Any) -> None
140
+ def __exit__ (self , * exc_details : Any ) -> None :
105
141
self ._client .__exit__ (* exc_details )
0 commit comments