ContentDecodePolicy Class

Policy for decoding unstreamed response content.

Inheritance
azure.core.pipeline.policies._base.SansIOHTTPPolicy
ContentDecodePolicy

Constructor

ContentDecodePolicy(response_encoding: Optional[str] = None, **kwargs: Any)

Parameters

response_encoding
str
default value: None

The encoding to use if known for this service (will disable auto-detection)

Methods

deserialize_from_http_generics

Deserialize from HTTP response.

Headers will tested for "content-type"

deserialize_from_text

Decode response data according to content-type.

Accept a stream of data as well, but will be load at once in memory for now. If no content-type, will return the string version (not bytes, not stream)

on_request

Is executed before sending the request from next policy.

on_response

Extract data from the body of a REST response object. This will load the entire payload in memory. Will follow Content-Type to parse. We assume everything is UTF8 (BOM acceptable).

deserialize_from_http_generics

Deserialize from HTTP response.

Headers will tested for "content-type"

deserialize_from_http_generics(response, encoding=None)

Parameters

response
Required

The HTTP response

encoding
Required

The encoding to use if known for this service (will disable auto-detection)

encoding
default value: None

Returns

A dict or XML tree, depending of the mime-type

Exceptions

If deserialization fails

deserialize_from_text

Decode response data according to content-type.

Accept a stream of data as well, but will be load at once in memory for now. If no content-type, will return the string version (not bytes, not stream)

deserialize_from_text(data, mime_type=None, response=None)

Parameters

response
HttpResponse
Required

The HTTP response.

mime_type
str
Required

The mime type. As mime type, charset is not expected.

response
default value: None

If passed, exception will be annotated with that response

response
default value: None

Returns

A dict or XML tree, depending of the mime_type

Exceptions

If deserialization fails

on_request

Is executed before sending the request from next policy.

on_request(request: azure.core.pipeline.PipelineRequest) -> None

Parameters

request
PipelineRequest
Required

Request to be modified before sent from next policy.

Exceptions

If deserialization fails

on_response

Extract data from the body of a REST response object. This will load the entire payload in memory. Will follow Content-Type to parse. We assume everything is UTF8 (BOM acceptable).

on_response(request: PipelineRequest[HTTPRequestType], response: PipelineResponse[HTTPRequestType, Union[HttpResponse, AsyncHttpResponse]]) -> None

Parameters

request
PipelineRequest
Required

The PipelineRequest object.

response
PipelineResponse
Required

The PipelineResponse object.

raw_data
Required

Data to be processed.

content_type
Required

How to parse if raw_data is a string/bytes.

Exceptions

JSONDecodeError

If JSON is requested and parsing is impossible.

If bytes is not UTF8

If bytes is not valid XML

If deserialization fails

Attributes

CONTEXT_NAME

CONTEXT_NAME = 'deserialized_data'

JSON_REGEXP

JSON_REGEXP = re.compile('^(application|text)/([0-9a-z+.-]+\\+)?json$')