Skip to content

Commit fe19ef3

Browse files
committed
Preliminary removal of legacy/backcompat code
Signed-off-by: Paul Van Eck <[email protected]>
1 parent 9c2d9e5 commit fe19ef3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+4157
-1720
lines changed

eng/tox/run_pyright.py

+1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ def get_pyright_config_path(args):
8888

8989
paths = [
9090
os.path.join(args.target_package, "azure"),
91+
os.path.join(args.target_package, "generic"),
9192
os.path.join(args.target_package, "samples"),
9293
]
9394

sdk/core/azure-core/azure/core/configuration.py

+3
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ class Configuration(GenericConfiguration): # pylint: disable=too-many-instance-
7575
def __init__(self, **kwargs: Any) -> None:
7676
super().__init__(**kwargs)
7777

78+
# Http logger configuration
79+
self.http_logging_policy: Optional[AnyPolicy[HTTPRequestType, HTTPResponseType]] = None
80+
7881
# Custom hook configuration
7982
self.custom_hook_policy: Optional[AnyPolicy[HTTPRequestType, HTTPResponseType]] = None
8083

sdk/core/azure-core/dev_requirements.txt

-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,3 @@ opencensus-ext-threading
77
-e ../../../tools/azure-sdk-tools
88
-e ../../../tools/azure-devtools
99
-e tests/testserver_tests/coretestserver
10-
-e ../generic-core/

sdk/core/azure-core/setup.py

+3
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@
7272
"requests>=2.18.4",
7373
"six>=1.11.0",
7474
"typing-extensions>=4.6.0",
75+
76+
# Generic core package. Github URL is temporary until we release the package.
77+
"generic-core @ git+https://github.com/Azure/azure-sdk-for-python.git@feature/generic-core#subdirectory=sdk/core/generic-core"
7578
],
7679
extras_require={
7780
"aio": [

sdk/core/generic-core/dev_requirements.txt

+2
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ requests
22
aiohttp>=3.0
33
-e ../../../tools/azure-sdk-tools
44
-e ../../../tools/azure-devtools
5+
-e tests/testserver_tests/coretestserver
6+
../../core/azure-core

sdk/core/generic-core/generic/core/_pipeline_client.py

-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
from .pipeline.policies import (
3535
ContentDecodePolicy,
3636
DistributedTracingPolicy,
37-
HttpLoggingPolicy,
3837
RequestIdPolicy,
3938
RetryPolicy,
4039
SensitiveHeaderCleanupPolicy,
@@ -140,7 +139,6 @@ def _build_pipeline(
140139
config.logging_policy,
141140
DistributedTracingPolicy(**kwargs),
142141
SensitiveHeaderCleanupPolicy(**kwargs) if config.redirect_policy else None,
143-
config.http_logging_policy or HttpLoggingPolicy(**kwargs),
144142
]
145143
)
146144
else:

sdk/core/generic-core/generic/core/_pipeline_client_async.py

-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
from .pipeline.policies import (
4545
ContentDecodePolicy,
4646
DistributedTracingPolicy,
47-
HttpLoggingPolicy,
4847
RequestIdPolicy,
4948
AsyncRetryPolicy,
5049
SensitiveHeaderCleanupPolicy,
@@ -223,7 +222,6 @@ def _build_pipeline(
223222
config.logging_policy,
224223
DistributedTracingPolicy(**kwargs),
225224
SensitiveHeaderCleanupPolicy(**kwargs) if config.redirect_policy else None,
226-
config.http_logging_policy or HttpLoggingPolicy(**kwargs),
227225
]
228226
)
229227
else:

sdk/core/generic-core/generic/core/configuration.py

-4
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ class Configuration(Generic[HTTPRequestType, HTTPResponseType]): # pylint: disa
5353
:ivar redirect_policy: Provides configuration parameters for redirects.
5454
:ivar retry_policy: Provides configuration parameters for retries in the pipeline.
5555
:ivar logging_policy: Provides configuration parameters for logging.
56-
:ivar http_logging_policy: Provides configuration parameters for HTTP specific logging.
5756
:ivar user_agent_policy: Provides configuration parameters to append custom values to the
5857
User-Agent header.
5958
:ivar authentication_policy: Provides configuration parameters for adding a bearer token Authorization
@@ -86,9 +85,6 @@ def __init__(self, **kwargs: Any) -> None:
8685
# Logger configuration
8786
self.logging_policy: Optional[AnyPolicy[HTTPRequestType, HTTPResponseType]] = None
8887

89-
# Http logger configuration
90-
self.http_logging_policy: Optional[AnyPolicy[HTTPRequestType, HTTPResponseType]] = None
91-
9288
# User Agent configuration
9389
self.user_agent_policy: Optional[AnyPolicy[HTTPRequestType, HTTPResponseType]] = None
9490

sdk/core/generic-core/generic/core/exceptions.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -199,15 +199,14 @@ class HttpResponseError(ServiceError):
199199
200200
:param object message: The message object stringified as 'message' attribute
201201
:param response: The response that triggered the exception.
202-
:type response: ~generic.core.pipeline.transport.HttpResponse or ~generic.core.pipeline.transport.AsyncHttpResponse
202+
:type response: ~generic.core.rest.HttpResponse or ~generic.core.rest.AsyncHttpResponse
203203
204204
:ivar reason: The HTTP response reason
205205
:vartype reason: str
206206
:ivar status_code: HttpResponse's status code
207207
:vartype status_code: int
208208
:ivar response: The response that triggered the exception.
209-
:vartype response: ~generic.core.pipeline.transport.HttpResponse or
210-
~generic.core.pipeline.transport.AsyncHttpResponse
209+
:vartype response: ~generic.core.rest.HttpResponse or ~generic.core.rest.AsyncHttpResponse
211210
"""
212211

213212
def __init__(

sdk/core/generic-core/generic/core/pipeline/__init__.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ class PipelineRequest(Generic[HTTPRequestType]):
141141
Universal for all transports, both synchronous and asynchronous.
142142
143143
:param http_request: The request object.
144-
:type http_request: ~generic.core.pipeline.transport.HttpRequest
144+
:type http_request: ~generic.core.rest.HttpRequest
145145
:param context: Contains the context - data persisted between pipeline requests.
146146
:type context: ~generic.core.pipeline.PipelineContext
147147
"""
@@ -162,9 +162,9 @@ class PipelineResponse(Generic[HTTPRequestType, HTTPResponseType]):
162162
However, nothing prevents a policy to actually sub-class this class a return it instead of the initial instance.
163163
164164
:param http_request: The request object.
165-
:type http_request: ~generic.core.pipeline.transport.HttpRequest
165+
:type http_request: ~generic.core.rest.HttpRequest
166166
:param http_response: The response object.
167-
:type http_response: ~generic.core.pipeline.transport.HttpResponse
167+
:type http_response: ~generic.core.rest.HttpResponse
168168
:param context: Contains the context - data persisted between pipeline requests.
169169
:type context: ~generic.core.pipeline.PipelineContext
170170
"""

sdk/core/generic-core/generic/core/pipeline/_base.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ def prepare_requests(req):
191191

192192
def _prepare_multipart(self, request: HTTPRequestType) -> None:
193193
# This code is fine as long as HTTPRequestType is actually
194-
# generic.core.pipeline.transport.HTTPRequest, bu we don't check it in here
194+
# generic.core.rest.HttpRequest, bu we don't check it in here
195195
# since we didn't see (yet) pipeline usage where it's not this actual instance
196196
# class used
197197
self._prepare_multipart_mixed_request(request)
@@ -201,7 +201,7 @@ def run(self, request: HTTPRequestType, **kwargs: Any) -> PipelineResponse[HTTPR
201201
"""Runs the HTTP Request through the chained policies.
202202
203203
:param request: The HTTP request object.
204-
:type request: ~generic.core.pipeline.transport.HttpRequest
204+
:type request: ~generic.core.rest.HttpRequest
205205
:return: The PipelineResponse object
206206
:rtype: ~generic.core.pipeline.PipelineResponse
207207
"""

sdk/core/generic-core/generic/core/pipeline/_base_async.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ async def prepare_requests(req):
198198

199199
async def _prepare_multipart(self, request: HTTPRequestType) -> None:
200200
# This code is fine as long as HTTPRequestType is actually
201-
# generic.core.pipeline.transport.HTTPRequest, but we don't check it in here
201+
# generic.core.rest.HttpRequest, but we don't check it in here
202202
# since we didn't see (yet) pipeline usage where it's not this actual instance
203203
# class used
204204
await self._prepare_multipart_mixed_request(request)
@@ -210,7 +210,7 @@ async def run(
210210
"""Runs the HTTP Request through the chained policies.
211211
212212
:param request: The HTTP request object.
213-
:type request: ~generic.core.pipeline.transport.HttpRequest
213+
:type request: ~generic.core.rest.HttpRequest
214214
:return: The PipelineResponse object.
215215
:rtype: ~generic.core.pipeline.PipelineResponse
216216
"""

sdk/core/generic-core/generic/core/pipeline/_tools.py

+3-19
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@
2424
#
2525
# --------------------------------------------------------------------------
2626
from __future__ import annotations
27-
from typing import TYPE_CHECKING, Union, Callable, TypeVar, Dict
28-
from typing_extensions import TypeGuard, ParamSpec
27+
from typing import TYPE_CHECKING, Callable, TypeVar, Dict
28+
from typing_extensions import ParamSpec
2929

3030
if TYPE_CHECKING:
31-
from ..rest import HttpResponse, HttpRequest, AsyncHttpResponse
31+
from ..rest import HttpResponse
3232

3333

3434
P = ParamSpec("P")
@@ -52,22 +52,6 @@ def await_result(func: Callable[P, T], *args: P.args, **kwargs: P.kwargs) -> T:
5252
return result
5353

5454

55-
def is_rest(obj: object) -> TypeGuard[Union[HttpRequest, HttpResponse, AsyncHttpResponse]]:
56-
"""Return whether a request or a response is a rest request / response.
57-
58-
Checking whether the response has the object content can sometimes result
59-
in a ResponseNotRead error if you're checking the value on a response
60-
that has not been read in yet. To get around this, we also have added
61-
a check for is_stream_consumed, which is an exclusive property on our new responses.
62-
63-
:param obj: The object to check.
64-
:type obj: any
65-
:rtype: bool
66-
:return: Whether the object is a rest request / response.
67-
"""
68-
return hasattr(obj, "is_stream_consumed") or hasattr(obj, "content")
69-
70-
7155
def handle_non_stream_rest_response(response: HttpResponse) -> None:
7256
"""Handle reading and closing of non stream rest responses.
7357
For our new rest responses, we have to call .read() and .close() for our non-stream

sdk/core/generic-core/generic/core/pipeline/policies/__init__.py

-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
NetworkTraceLoggingPolicy,
3939
ContentDecodePolicy,
4040
ProxyPolicy,
41-
HttpLoggingPolicy,
4241
RequestIdPolicy,
4342
)
4443
from ._base_async import AsyncHTTPPolicy
@@ -62,7 +61,6 @@
6261
"ProxyPolicy",
6362
"DistributedTracingPolicy",
6463
"RequestHistory",
65-
"HttpLoggingPolicy",
6664
"RequestIdPolicy",
6765
"AsyncHTTPPolicy",
6866
"AsyncBearerTokenCredentialPolicy",

sdk/core/generic-core/generic/core/pipeline/policies/_authentication.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
# -------------------------------------------------------------------------
66
import time
77
from typing import TYPE_CHECKING, Optional, TypeVar, MutableMapping, Any
8+
89
from .. import PipelineRequest, PipelineResponse
9-
from ..transport import HttpResponse as LegacyHttpResponse, HttpRequest as LegacyHttpRequest
1010
from ...rest import HttpResponse, HttpRequest
1111
from . import HTTPPolicy, SansIOHTTPPolicy
1212
from ...exceptions import ServiceRequestError
@@ -19,8 +19,8 @@
1919
ServiceKeyCredential,
2020
)
2121

22-
HTTPResponseType = TypeVar("HTTPResponseType", HttpResponse, LegacyHttpResponse)
23-
HTTPRequestType = TypeVar("HTTPRequestType", HttpRequest, LegacyHttpRequest)
22+
HTTPResponseType = TypeVar("HTTPResponseType", bound=HttpResponse)
23+
HTTPRequestType = TypeVar("HTTPRequestType", bound=HttpRequest)
2424

2525

2626
# pylint:disable=too-few-public-methods

sdk/core/generic-core/generic/core/pipeline/policies/_authentication_async.py

+3-7
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,15 @@
1010
from ...credentials import AccessToken
1111
from .. import PipelineRequest, PipelineResponse
1212
from .._base_async import AsyncHTTPPolicy
13-
from ._authentication import (
14-
_BearerTokenCredentialPolicyBase,
15-
)
16-
from ..transport import AsyncHttpResponse as LegacyAsyncHttpResponse, HttpRequest as LegacyHttpRequest
13+
from ._authentication import _BearerTokenCredentialPolicyBase
1714
from ...rest import AsyncHttpResponse, HttpRequest
18-
1915
from .._tools_async import await_result
2016

2117
if TYPE_CHECKING:
2218
from ...credentials_async import AsyncTokenCredential
2319

24-
AsyncHTTPResponseType = TypeVar("AsyncHTTPResponseType", AsyncHttpResponse, LegacyAsyncHttpResponse)
25-
HTTPRequestType = TypeVar("HTTPRequestType", HttpRequest, LegacyHttpRequest)
20+
AsyncHTTPResponseType = TypeVar("AsyncHTTPResponseType", bound=AsyncHttpResponse)
21+
HTTPRequestType = TypeVar("HTTPRequestType", bound=HttpRequest)
2622

2723

2824
class AsyncBearerTokenCredentialPolicy(AsyncHTTPPolicy[HTTPRequestType, AsyncHTTPResponseType]):

sdk/core/generic-core/generic/core/pipeline/policies/_base.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,9 @@ class RequestHistory(Generic[HTTPRequestType, HTTPResponseType]):
128128
This is used to document requests/responses that resulted in redirected/retried requests.
129129
130130
:param http_request: The request.
131-
:type http_request: ~generic.core.pipeline.transport.HttpRequest
131+
:type http_request: ~generic.core.rest.HttpRequest
132132
:param http_response: The HTTP response.
133-
:type http_response: ~generic.core.pipeline.transport.HttpResponse
133+
:type http_response: ~generic.core.rest.HttpResponse
134134
:param Exception error: An error encountered during the request, or None if the response was received successfully.
135135
:param dict context: The pipeline context.
136136
"""

sdk/core/generic-core/generic/core/pipeline/policies/_distributed_tracing.py

+8-9
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232

3333
from .. import PipelineRequest, PipelineResponse
3434
from ..policies import SansIOHTTPPolicy
35-
from ..transport import HttpResponse as LegacyHttpResponse, HttpRequest as LegacyHttpRequest
3635
from ...rest import HttpResponse, HttpRequest
3736
from ...settings import settings
3837
from ...tracing import SpanKind
@@ -42,8 +41,8 @@
4241
AbstractSpan,
4342
)
4443

45-
HTTPResponseType = TypeVar("HTTPResponseType", HttpResponse, LegacyHttpResponse)
46-
HTTPRequestType = TypeVar("HTTPRequestType", HttpRequest, LegacyHttpRequest)
44+
HTTPResponseType = TypeVar("HTTPResponseType", bound=HttpResponse)
45+
HTTPRequestType = TypeVar("HTTPRequestType", bound=HttpRequest)
4746
ExcInfo = Tuple[Type[BaseException], BaseException, TracebackType]
4847
OptExcInfo = Union[ExcInfo, Tuple[None, None, None]]
4948

@@ -54,7 +53,7 @@ def _default_network_span_namer(http_request: HTTPRequestType) -> str:
5453
"""Extract the path to be used as network span name.
5554
5655
:param http_request: The HTTP request
57-
:type http_request: ~generic.core.pipeline.transport.HttpRequest
56+
:type http_request: ~generic.core.rest.HttpRequest
5857
:returns: The string to use as network span name
5958
:rtype: str
6059
"""
@@ -68,14 +67,14 @@ class DistributedTracingPolicy(SansIOHTTPPolicy[HTTPRequestType, HTTPResponseTyp
6867
"""The policy to create spans for service calls.
6968
7069
:keyword network_span_namer: A callable to customize the span name
71-
:type network_span_namer: callable[[~generic.core.pipeline.transport.HttpRequest], str]
70+
:type network_span_namer: callable[[~generic.core.rest.HttpRequest], str]
7271
:keyword tracing_attributes: Attributes to set on all created spans
7372
:type tracing_attributes: dict[str, str]
7473
"""
7574

7675
TRACING_CONTEXT = "TRACING_CONTEXT"
77-
_REQUEST_ID = "x-ms-client-request-id"
78-
_RESPONSE_ID = "x-ms-request-id"
76+
_REQUEST_ID = "x-client-request-id"
77+
_RESPONSE_ID = "x-request-id"
7978

8079
def __init__(self, **kwargs: Any):
8180
self._network_span_namer = kwargs.get("network_span_namer", _default_network_span_namer)
@@ -114,15 +113,15 @@ def end_span(
114113
:param request: The PipelineRequest object
115114
:type request: ~generic.core.pipeline.PipelineRequest
116115
:param response: The HttpResponse object
117-
:type response: ~generic.core.rest.HTTPResponse or ~generic.core.pipeline.transport.HttpResponse
116+
:type response: ~generic.core.rest.HTTPResponse or ~generic.core.rest.HttpResponse
118117
:param exc_info: The exception information
119118
:type exc_info: tuple
120119
"""
121120
if self.TRACING_CONTEXT not in request.context:
122121
return
123122

124123
span: "AbstractSpan" = request.context[self.TRACING_CONTEXT]
125-
http_request: Union[HttpRequest, LegacyHttpRequest] = request.http_request
124+
http_request: HttpRequest = request.http_request
126125
if span is not None:
127126
span.set_http_attributes(http_request, response=response)
128127
request_id = http_request.headers.get(self._REQUEST_ID)

sdk/core/generic-core/generic/core/pipeline/policies/_redirect.py

+3-10
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,13 @@
3333

3434
from ...exceptions import TooManyRedirectsError
3535
from .. import PipelineResponse, PipelineRequest
36-
from ..transport import (
37-
HttpResponse as LegacyHttpResponse,
38-
HttpRequest as LegacyHttpRequest,
39-
AsyncHttpResponse as LegacyAsyncHttpResponse,
40-
)
4136
from ...rest import HttpResponse, HttpRequest, AsyncHttpResponse
4237
from ._base import HTTPPolicy, RequestHistory
4338
from ._utils import get_domain
4439

45-
HTTPResponseType = TypeVar("HTTPResponseType", HttpResponse, LegacyHttpResponse)
46-
AllHttpResponseType = TypeVar(
47-
"AllHttpResponseType", HttpResponse, LegacyHttpResponse, AsyncHttpResponse, LegacyAsyncHttpResponse
48-
)
49-
HTTPRequestType = TypeVar("HTTPRequestType", HttpRequest, LegacyHttpRequest)
40+
HTTPResponseType = TypeVar("HTTPResponseType", bound=HttpResponse)
41+
AllHttpResponseType = TypeVar("AllHttpResponseType", HttpResponse, AsyncHttpResponse)
42+
HTTPRequestType = TypeVar("HTTPRequestType", bound=HttpRequest)
5043
ClsRedirectPolicy = TypeVar("ClsRedirectPolicy", bound="RedirectPolicyBase")
5144

5245
_LOGGER = logging.getLogger(__name__)

sdk/core/generic-core/generic/core/pipeline/policies/_redirect_async.py

+6-9
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,16 @@
2424
#
2525
# --------------------------------------------------------------------------
2626
from typing import TypeVar
27-
from generic.core.exceptions import TooManyRedirectsError
28-
from generic.core.pipeline import PipelineResponse, PipelineRequest
29-
from generic.core.pipeline.transport import (
30-
AsyncHttpResponse as LegacyAsyncHttpResponse,
31-
HttpRequest as LegacyHttpRequest,
32-
)
33-
from generic.core.rest import AsyncHttpResponse, HttpRequest
27+
3428
from . import AsyncHTTPPolicy
3529
from ._redirect import RedirectPolicyBase, domain_changed
3630
from ._utils import get_domain
31+
from .. import PipelineResponse, PipelineRequest
32+
from ...exceptions import TooManyRedirectsError
33+
from ...rest import AsyncHttpResponse, HttpRequest
3734

38-
AsyncHTTPResponseType = TypeVar("AsyncHTTPResponseType", AsyncHttpResponse, LegacyAsyncHttpResponse)
39-
HTTPRequestType = TypeVar("HTTPRequestType", HttpRequest, LegacyHttpRequest)
35+
AsyncHTTPResponseType = TypeVar("AsyncHTTPResponseType", bound=AsyncHttpResponse)
36+
HTTPRequestType = TypeVar("HTTPRequestType", bound=HttpRequest)
4037

4138

4239
class AsyncRedirectPolicy(RedirectPolicyBase, AsyncHTTPPolicy[HTTPRequestType, AsyncHTTPResponseType]):

0 commit comments

Comments
 (0)